@@ -92,43 +92,33 @@ function safety_checks($dryrun) {
92
92
$ minutes = $ timetoshowusers / 60 ;
93
93
$ now = time ();
94
94
$ timefrom = $ now - $ timetoshowusers ; // Unlike original code, don't care about caches for this.
95
- $ params = array ('now ' => $ now , 'timefrom ' => $ timefrom );
96
-
97
- $ csql = "SELECT COUNT(u.id)
98
- FROM {user} u
99
- WHERE u.lastaccess > :timefrom
100
- AND u.lastaccess <= :now
101
- AND u.deleted = 0 " ;
102
-
103
- if ($ DB ->count_records_sql ($ csql , $ params )) {
104
- $ namefields = "u. " . implode (', u. ' , \core_user \fields::get_name_fields ());
105
-
106
- $ sql = "SELECT u.id, u.username, {$ namefields }
107
- FROM {user} u
108
- WHERE u.lastaccess > :timefrom
109
- AND u.lastaccess <= :now
110
- AND u.deleted = 0
111
- GROUP BY u.id
112
- ORDER BY lastaccess DESC " ;
113
- $ users = $ DB ->get_records_sql ($ sql , $ params );
114
-
115
- $ message = "The following users have logged in within the last {$ minutes } minutes: \n" ;
116
- $ nonadmins = 0 ;
117
- foreach ($ users as $ user ) {
118
- $ message .= ' - ' . fullname ($ user ) . ' ( ' . $ user ->username . ') ' ;
119
- if (is_siteadmin ($ user )) {
120
- $ message .= ' (siteadmin) ' ;
121
- } else {
122
- $ nonadmins ++;
123
- }
124
- $ message .= "\n" ;
95
+ $ params = array ('timefrom ' => $ timefrom );
96
+
97
+ $ namefields = "u. " . implode (', u. ' , \core_user \fields::get_name_fields ());
98
+
99
+ $ sql = "SELECT u.id, u.username, {$ namefields }
100
+ FROM {user} u
101
+ WHERE u.lastaccess > :timefrom
102
+ AND u.deleted = 0
103
+ ORDER BY lastaccess DESC " ;
104
+ $ users = $ DB ->get_records_sql ($ sql , $ params );
105
+
106
+ $ message = "The following users have logged in within the last {$ minutes } minutes: \n" ;
107
+ $ nonadmins = 0 ;
108
+ foreach ($ users as $ user ) {
109
+ $ message .= ' - ' . fullname ($ user ) . ' ( ' . $ user ->username . ') ' ;
110
+ if (is_siteadmin ($ user )) {
111
+ $ message .= ' (siteadmin) ' ;
112
+ } else {
113
+ $ nonadmins ++;
125
114
}
115
+ $ message .= "\n" ;
116
+ }
126
117
127
- if ($ nonadmins ) {
128
- abort_message ($ abort , $ message );
129
- abort_message ("There are non site-administrators in the list of recent users. " , true );
130
- $ willdie = true ;
131
- }
118
+ if ($ nonadmins ) {
119
+ abort_message ($ abort , $ message );
120
+ abort_message ($ abort , "There are non site-administrators in the list of recent users. " , true );
121
+ $ willdie = true ;
132
122
}
133
123
134
124
// 3. Has cron run recently?
0 commit comments