|
15 | 15 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
16 | 16 |
|
17 | 17 | /**
|
18 |
| - * @package cleaner |
| 18 | + * Library functions for data cleaner. |
| 19 | + * |
| 20 | + * @package local_datacleaner |
19 | 21 | * @copyright 2015 Catalyst IT
|
20 | 22 | * @author Nigel Cunningham <nigelc@catalyst-au.net>
|
21 | 23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
22 | 24 | */
|
23 | 25 |
|
| 26 | +<<<<<<< HEAD |
24 | 27 | defined('MOODLE_INTERNAL') || die();
|
| 28 | +======= |
| 29 | +use local_datacleaner\clean; |
| 30 | +>>>>>>> ce6bb45 (issue 195: coding style fixes) |
25 | 31 |
|
26 | 32 | /**
|
27 | 33 | * Print a message to the terminal.
|
@@ -89,43 +95,33 @@ function safety_checks($dryrun) {
|
89 | 95 | $minutes = $timetoshowusers / 60;
|
90 | 96 | $now = time();
|
91 | 97 | $timefrom = $now - $timetoshowusers; // Unlike original code, don't care about caches for this.
|
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"; |
| 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++; |
122 | 117 | }
|
| 118 | + $message .= "\n"; |
| 119 | + } |
123 | 120 |
|
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 |
| - } |
| 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; |
129 | 125 | }
|
130 | 126 |
|
131 | 127 | // 3. Has cron run recently?
|
|
0 commit comments