|
15 | 15 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. |
16 | 16 |
|
17 | 17 | /** |
18 | | - * Library functions for data cleaner. |
19 | | - * |
20 | | - * @package local_datacleaner |
| 18 | + * @package cleaner |
21 | 19 | * @copyright 2015 Catalyst IT |
22 | 20 | * @author Nigel Cunningham <[email protected]> |
23 | 21 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
24 | 22 | */ |
25 | 23 |
|
26 | | -<<<<<<< HEAD |
27 | 24 | defined('MOODLE_INTERNAL') || die(); |
28 | | -======= |
29 | | -use local_datacleaner\clean; |
30 | | ->>>>>>> ce6bb45 (issue 195: coding style fixes) |
31 | 25 |
|
32 | 26 | /** |
33 | 27 | * Print a message to the terminal. |
@@ -95,33 +89,43 @@ function safety_checks($dryrun) { |
95 | 89 | $minutes = $timetoshowusers / 60; |
96 | 90 | $now = time(); |
97 | 91 | $timefrom = $now - $timetoshowusers; // Unlike original code, don't care about caches for this. |
98 | | - $params = ['timefrom' => $timefrom]; |
99 | | - |
100 | | - $namefields = "u." . implode(', u.', \core_user\fields::get_name_fields()); |
101 | | - |
102 | | - $sql = "SELECT u.id, u.username, {$namefields} |
103 | | - FROM {user} u |
104 | | - WHERE u.lastaccess > :timefrom |
105 | | - AND u.deleted = 0 |
106 | | - ORDER BY lastaccess DESC "; |
107 | | - $users = $DB->get_records_sql($sql, $params); |
108 | | - |
109 | | - $message = "The following users have logged in within the last {$minutes} minutes:\n"; |
110 | | - $nonadmins = 0; |
111 | | - foreach ($users as $user) { |
112 | | - $message .= ' - ' . fullname($user) . ' (' . $user->username . ')'; |
113 | | - if (is_siteadmin($user)) { |
114 | | - $message .= ' (siteadmin)'; |
115 | | - } else { |
116 | | - $nonadmins++; |
| 92 | + $params = array('now' => $now, 'timefrom' => $timefrom); |
| 93 | + |
| 94 | + $csql = "SELECT COUNT(u.id) |
| 95 | + FROM {user} u |
| 96 | + WHERE u.lastaccess > :timefrom |
| 97 | + AND u.lastaccess <= :now |
| 98 | + AND u.deleted = 0"; |
| 99 | + |
| 100 | + if ($DB->count_records_sql($csql, $params)) { |
| 101 | + $namefields = "u." . implode(', u.', get_all_user_name_fields()); |
| 102 | + |
| 103 | + $sql = "SELECT u.id, u.username, {$namefields} |
| 104 | + FROM {user} u |
| 105 | + WHERE u.lastaccess > :timefrom |
| 106 | + AND u.lastaccess <= :now |
| 107 | + AND u.deleted = 0 |
| 108 | + GROUP BY u.id |
| 109 | + ORDER BY lastaccess DESC "; |
| 110 | + $users = $DB->get_records_sql($sql, $params); |
| 111 | + |
| 112 | + $message = "The following users have logged in within the last {$minutes} minutes:\n"; |
| 113 | + $nonadmins = 0; |
| 114 | + foreach ($users as $user) { |
| 115 | + $message .= ' - ' . fullname($user) . ' (' . $user->username . ')'; |
| 116 | + if (is_siteadmin($user)) { |
| 117 | + $message .= ' (siteadmin)'; |
| 118 | + } else { |
| 119 | + $nonadmins++; |
| 120 | + } |
| 121 | + $message .= "\n"; |
117 | 122 | } |
118 | | - $message .= "\n"; |
119 | | - } |
120 | 123 |
|
121 | | - if ($nonadmins) { |
122 | | - abort_message($abort, $message); |
123 | | - abort_message($abort, "There are non site-administrators in the list of recent users.", true); |
124 | | - $willdie = true; |
| 124 | + if ($nonadmins) { |
| 125 | + abort_message($abort, $message); |
| 126 | + abort_message("There are non site-administrators in the list of recent users.", true); |
| 127 | + $willdie = true; |
| 128 | + } |
125 | 129 | } |
126 | 130 |
|
127 | 131 | // 3. Has cron run recently? |
|
0 commit comments