2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
22 * @copyright 1999 onwards Martin Dougiamas http://dougiamas.com
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30 global $DB, $CFG, $OUTPUT;
32 if (CLI_MAINTENANCE
) {
33 echo "CLI maintenance mode active, cron execution suspended.\n";
37 if (moodle_needs_upgrading()) {
38 echo "Moodle upgrade pending, cron execution suspended.\n";
42 require_once($CFG->libdir
.'/adminlib.php');
43 require_once($CFG->libdir
.'/gradelib.php');
45 if (!empty($CFG->showcronsql
)) {
48 if (!empty($CFG->showcrondebugging
)) {
49 $CFG->debug
= DEBUG_DEVELOPER
;
50 $CFG->debugdisplay
= true;
54 $starttime = microtime();
56 // Increase memory limit
57 raise_memory_limit(MEMORY_EXTRA
);
59 // Emulate normal session - we use admin accoutn by default
64 mtrace("Server Time: ".date('r', $timenow)."\n\n");
67 // Run cleanup core cron jobs, but not every time since they aren't too important.
68 // These don't have a timer to reduce load, so we'll use a random number
69 // to randomly choose the percentage of times we should run these jobs.
70 srand ((double) microtime() * 10000000);
71 $random100 = rand(0,100);
72 if ($random100 < 20) { // Approximately 20% of the time.
73 mtrace("Running clean-up tasks...");
74 cron_trace_time_and_memory();
76 // Delete users who haven't confirmed within required period
77 if (!empty($CFG->deleteunconfirmed
)) {
78 $cuttime = $timenow - ($CFG->deleteunconfirmed
* 3600);
79 $rs = $DB->get_recordset_sql ("SELECT *
81 WHERE confirmed = 0 AND firstaccess > 0
82 AND firstaccess < ?", array($cuttime));
83 foreach ($rs as $user) {
84 delete_user($user); // we MUST delete user properly first
85 $DB->delete_records('user', array('id'=>$user->id
)); // this is a bloody hack, but it might work
86 mtrace(" Deleted unconfirmed user for ".fullname($user, true)." ($user->id)");
92 // Delete users who haven't completed profile within required period
93 if (!empty($CFG->deleteincompleteusers
)) {
94 $cuttime = $timenow - ($CFG->deleteincompleteusers
* 3600);
95 $rs = $DB->get_recordset_sql ("SELECT *
97 WHERE confirmed = 1 AND lastaccess > 0
98 AND lastaccess < ? AND deleted = 0
99 AND (lastname = '' OR firstname = '' OR email = '')",
101 foreach ($rs as $user) {
103 mtrace(" Deleted not fully setup user $user->username ($user->id)");
109 // Delete old logs to save space (this might need a timer to slow it down...)
110 if (!empty($CFG->loglifetime
)) { // value in days
111 $loglifetime = $timenow - ($CFG->loglifetime
* 3600 * 24);
112 $DB->delete_records_select("log", "time < ?", array($loglifetime));
113 mtrace(" Deleted old log records");
117 // Delete old backup_controllers and logs.
118 $loglifetime = get_config('backup', 'loglifetime');
119 if (!empty($loglifetime)) { // Value in days.
120 $loglifetime = $timenow - ($loglifetime * 3600 * 24);
121 // Delete child records from backup_logs.
122 $DB->execute("DELETE FROM {backup_logs}
125 FROM {backup_controllers} bc
126 WHERE bc.backupid = {backup_logs}.backupid
127 AND bc.timecreated < ?)", array($loglifetime));
128 // Delete records from backup_controllers.
129 $DB->execute("DELETE FROM {backup_controllers}
130 WHERE timecreated < ?", array($loglifetime));
131 mtrace(" Deleted old backup records");
135 // Delete old cached texts
136 if (!empty($CFG->cachetext
)) { // Defined in config.php
137 $cachelifetime = time() - $CFG->cachetext
- 60; // Add an extra minute to allow for really heavy sites
138 $DB->delete_records_select('cache_text', "timemodified < ?", array($cachelifetime));
139 mtrace(" Deleted old cache_text records");
143 if (!empty($CFG->usetags
)) {
144 require_once($CFG->dirroot
.'/tag/lib.php');
146 mtrace(' Executed tag cron');
150 // Context maintenance stuff
151 context_helper
::cleanup_instances();
152 mtrace(' Cleaned up context instances');
153 context_helper
::build_all_paths(false);
154 // If you suspect that the context paths are somehow corrupt
155 // replace the line below with: context_helper::build_all_paths(true);
156 mtrace(' Built context paths');
159 // Remove expired cache flags
161 mtrace(' Cleaned cache flags');
165 if (!empty($CFG->messagingdeletereadnotificationsdelay
)) {
166 $notificationdeletetime = time() - $CFG->messagingdeletereadnotificationsdelay
;
167 $DB->delete_records_select('message_read', 'notification=1 AND timeread<:notificationdeletetime', array('notificationdeletetime'=>$notificationdeletetime));
168 mtrace(' Cleaned up read notifications');
171 mtrace("...finished clean-up tasks");
173 } // End of occasional clean-up tasks
176 // Send login failures notification - brute force protection in moodle is weak,
177 // we should at least send notices early in each cron execution
178 if (notify_login_failures()) {
179 mtrace(' Notified login failures');
183 // Make sure all context instances are properly created - they may be required in auth, enrol, etc.
184 context_helper
::create_instances();
185 mtrace(' Created missing context instances');
190 mtrace("Cleaned up stale user sessions");
193 // Run the auth cron, if any before enrolments
194 // because it might add users that will be needed in enrol plugins
195 $auths = get_enabled_auth_plugins();
196 mtrace("Running auth crons if required...");
197 cron_trace_time_and_memory();
198 foreach ($auths as $auth) {
199 $authplugin = get_auth_plugin($auth);
200 if (method_exists($authplugin, 'cron')) {
201 mtrace("Running cron for auth/$auth...");
203 if (!empty($authplugin->log
)) {
204 mtrace($authplugin->log
);
209 // Generate new password emails for users - ppl expect these generated asap
210 if ($DB->count_records('user_preferences', array('name'=>'create_password', 'value'=>'1'))) {
211 mtrace('Creating passwords for new users...');
212 $newusers = $DB->get_recordset_sql("SELECT u.id as id, u.email, u.firstname,
213 u.lastname, u.username, u.lang,
216 JOIN {user_preferences} p ON u.id=p.userid
217 WHERE p.name='create_password' AND p.value='1' AND u.email !='' AND u.suspended = 0 AND u.auth != 'nologin' AND u.deleted = 0");
219 // note: we can not send emails to suspended accounts
220 foreach ($newusers as $newuser) {
221 // Use a low cost factor when generating bcrypt hash otherwise
222 // hashing would be slow when emailing lots of users. Hashes
223 // will be automatically updated to a higher cost factor the first
224 // time the user logs in.
225 if (setnew_password_and_mail($newuser, true)) {
226 unset_user_preference('create_password', $newuser);
227 set_user_preference('auth_forcepasswordchange', 1, $newuser);
229 trigger_error("Could not create and mail new user password!");
236 // It is very important to run enrol early
237 // because other plugins depend on correct enrolment info.
238 mtrace("Running enrol crons if required...");
239 $enrols = enrol_get_plugins(true);
240 foreach($enrols as $ename=>$enrol) {
241 // do this for all plugins, disabled plugins might want to cleanup stuff such as roles
242 if (!$enrol->is_cron_required()) {
245 mtrace("Running cron for enrol_$ename...");
246 cron_trace_time_and_memory();
248 $enrol->set_config('lastcron', time());
252 // Run all cron jobs for each module
253 mtrace("Starting activity modules");
254 get_mailer('buffer');
255 if ($mods = $DB->get_records_select("modules", "cron > 0 AND ((? - lastcron) > cron) AND visible = 1", array($timenow))) {
256 foreach ($mods as $mod) {
257 $libfile = "$CFG->dirroot/mod/$mod->name/lib.php";
258 if (file_exists($libfile)) {
259 include_once($libfile);
260 $cron_function = $mod->name
."_cron";
261 if (function_exists($cron_function)) {
262 mtrace("Processing module function $cron_function ...", '');
263 cron_trace_time_and_memory();
264 $pre_dbqueries = null;
265 $pre_dbqueries = $DB->perf_get_queries();
266 $pre_time = microtime(1);
267 if ($cron_function()) {
268 $DB->set_field("modules", "lastcron", $timenow, array("id"=>$mod->id
));
270 if (isset($pre_dbqueries)) {
271 mtrace("... used " . ($DB->perf_get_queries() - $pre_dbqueries) . " dbqueries");
272 mtrace("... used " . (microtime(1) - $pre_time) . " seconds");
274 // Reset possible changes by modules to time_limit. MDL-11597
282 mtrace("Finished activity modules");
285 mtrace("Starting blocks");
286 if ($blocks = $DB->get_records_select("block", "cron > 0 AND ((? - lastcron) > cron) AND visible = 1", array($timenow))) {
287 // We will need the base class.
288 require_once($CFG->dirroot
.'/blocks/moodleblock.class.php');
289 foreach ($blocks as $block) {
290 $blockfile = $CFG->dirroot
.'/blocks/'.$block->name
.'/block_'.$block->name
.'.php';
291 if (file_exists($blockfile)) {
292 require_once($blockfile);
293 $classname = 'block_'.$block->name
;
294 $blockobj = new $classname;
295 if (method_exists($blockobj,'cron')) {
296 mtrace("Processing cron function for ".$block->name
.'....','');
297 cron_trace_time_and_memory();
298 if ($blockobj->cron()) {
299 $DB->set_field('block', 'lastcron', $timenow, array('id'=>$block->id
));
301 // Reset possible changes by blocks to time_limit. MDL-11597
309 mtrace('Finished blocks');
312 mtrace('Starting admin reports');
313 cron_execute_plugin_type('report');
314 mtrace('Finished admin reports');
317 mtrace('Starting main gradebook job...');
318 cron_trace_time_and_memory();
323 mtrace('Starting processing the event queue...');
324 cron_trace_time_and_memory();
329 if ($CFG->enablecompletion
) {
331 mtrace('Starting the completion cron...');
332 cron_trace_time_and_memory();
333 require_once($CFG->dirroot
.'/completion/cron.php');
339 if ($CFG->enableportfolios
) {
341 mtrace('Starting the portfolio cron...');
342 cron_trace_time_and_memory();
343 require_once($CFG->libdir
. '/portfoliolib.php');
349 //now do plagiarism checks
350 require_once($CFG->libdir
.'/plagiarismlib.php');
354 mtrace('Starting course reports');
355 cron_execute_plugin_type('coursereport');
356 mtrace('Finished course reports');
359 // run gradebook import/export/report cron
360 mtrace('Starting gradebook plugins');
361 cron_execute_plugin_type('gradeimport');
362 cron_execute_plugin_type('gradeexport');
363 cron_execute_plugin_type('gradereport');
364 mtrace('Finished gradebook plugins');
367 require_once "{$CFG->dirroot}/calendar/lib.php";
370 // Run external blog cron if needed
371 if (!empty($CFG->enableblogs
) && $CFG->useexternalblogs
) {
372 require_once($CFG->dirroot
. '/blog/lib.php');
373 mtrace("Fetching external blog entries...", '');
374 cron_trace_time_and_memory();
375 $sql = "timefetched < ? OR timefetched = 0";
376 $externalblogs = $DB->get_records_select('blog_external', $sql, array(time() - $CFG->externalblogcrontime
));
378 foreach ($externalblogs as $eb) {
379 blog_sync_external_entries($eb);
383 // Run blog associations cleanup
384 if (!empty($CFG->enableblogs
) && $CFG->useblogassociations
) {
385 require_once($CFG->dirroot
. '/blog/lib.php');
386 // delete entries whose contextids no longer exists
387 mtrace("Deleting blog associations linked to non-existent contexts...", '');
388 cron_trace_time_and_memory();
389 $DB->delete_records_select('blog_association', 'contextid NOT IN (SELECT id FROM {context})');
394 // Run question bank clean-up.
395 mtrace("Starting the question bank cron...", '');
396 cron_trace_time_and_memory();
397 require_once($CFG->libdir
. '/questionlib.php');
398 question_bank
::cron();
402 //Run registration updated cron
403 mtrace(get_string('siteupdatesstart', 'hub'));
404 cron_trace_time_and_memory();
405 require_once($CFG->dirroot
. '/' . $CFG->admin
. '/registration/lib.php');
406 $registrationmanager = new registration_manager();
407 $registrationmanager->cron();
408 mtrace(get_string('siteupdatesend', 'hub'));
410 // If enabled, fetch information about available updates and eventually notify site admins
411 if (empty($CFG->disableupdatenotifications
)) {
412 require_once($CFG->libdir
.'/pluginlib.php');
413 $updateschecker = available_update_checker
::instance();
414 $updateschecker->cron();
417 //cleanup old session linked tokens
418 //deletes the session linked tokens that are over a day old.
419 mtrace("Deleting session linked tokens more than one day old...", '');
420 cron_trace_time_and_memory();
421 $DB->delete_records_select('external_tokens', 'lastaccess < :onedayago AND tokentype = :tokentype',
422 array('onedayago' => time() - DAYSECS
, 'tokentype' => EXTERNAL_TOKEN_EMBEDDED
));
427 cron_execute_plugin_type('message', 'message plugins');
428 cron_execute_plugin_type('filter', 'filters');
429 cron_execute_plugin_type('editor', 'editors');
430 cron_execute_plugin_type('format', 'course formats');
431 cron_execute_plugin_type('profilefield', 'profile fields');
432 cron_execute_plugin_type('webservice', 'webservices');
433 cron_execute_plugin_type('repository', 'repository plugins');
434 cron_execute_plugin_type('qbehaviour', 'question behaviours');
435 cron_execute_plugin_type('qformat', 'question import/export formats');
436 cron_execute_plugin_type('qtype', 'question types');
437 cron_execute_plugin_type('plagiarism', 'plagiarism plugins');
438 cron_execute_plugin_type('theme', 'themes');
439 cron_execute_plugin_type('tool', 'admin tools');
442 // and finally run any local cronjobs, if any
443 if ($locals = get_plugin_list('local')) {
444 mtrace('Processing customized cron scripts ...', '');
445 // new cron functions in lib.php first
446 cron_execute_plugin_type('local');
447 // legacy cron files are executed directly
448 foreach ($locals as $local => $localdir) {
449 if (file_exists("$localdir/cron.php")) {
450 include("$localdir/cron.php");
457 // Run automated backups if required - these may take a long time to execute
458 require_once($CFG->dirroot
.'/backup/util/includes/backup_includes.php');
459 require_once($CFG->dirroot
.'/backup/util/helper/backup_cron_helper.class.php');
460 backup_cron_automated_helper
::run_automated_backup();
463 // Run stats as at the end because they are known to take very long time on large sites
464 if (!empty($CFG->enablestats
) and empty($CFG->disablestatsprocessing
)) {
465 require_once($CFG->dirroot
.'/lib/statslib.php');
466 // check we're not before our runtime
467 $timetocheck = stats_get_base_daily() +
$CFG->statsruntimestarthour
*60*60 +
$CFG->statsruntimestartminute
*60;
469 if (time() > $timetocheck) {
470 // process configured number of days as max (defaulting to 31)
471 $maxdays = empty($CFG->statsruntimedays
) ?
31 : abs($CFG->statsruntimedays
);
472 if (stats_cron_daily($maxdays)) {
473 if (stats_cron_weekly()) {
474 if (stats_cron_monthly()) {
481 mtrace('Next stats run after:'. userdate($timetocheck));
486 // cleanup file trash - not very important
487 $fs = get_file_storage();
490 mtrace("Cron script completed correctly");
493 mtrace('Cron completed at ' . date('H:i:s') . '. Memory used ' . display_size(memory_get_usage()) . '.');
494 $difftime = microtime_diff($starttime, microtime());
495 mtrace("Execution took ".$difftime." seconds");
499 * Executes cron functions for a specific type of plugin.
501 * @param string $plugintype Plugin type (e.g. 'report')
502 * @param string $description If specified, will display 'Starting (whatever)'
503 * and 'Finished (whatever)' lines, otherwise does not display
505 function cron_execute_plugin_type($plugintype, $description = null) {
508 // Get list from plugin => function for all plugins
509 $plugins = get_plugin_list_with_function($plugintype, 'cron');
511 // Modify list for backward compatibility (different files/names)
512 $plugins = cron_bc_hack_plugin_functions($plugintype, $plugins);
514 // Return if no plugins with cron function to process
520 mtrace('Starting '.$description);
523 foreach ($plugins as $component=>$cronfunction) {
524 $dir = get_component_directory($component);
526 // Get cron period if specified in version.php, otherwise assume every cron
528 if (file_exists("$dir/version.php")) {
529 $plugin = new stdClass();
530 include("$dir/version.php");
531 if (isset($plugin->cron
)) {
532 $cronperiod = $plugin->cron
;
536 // Using last cron and cron period, don't run if it already ran recently
537 $lastcron = get_config($component, 'lastcron');
538 if ($cronperiod && $lastcron) {
539 if ($lastcron +
$cronperiod > time()) {
540 // do not execute cron yet
545 mtrace('Processing cron function for ' . $component . '...');
546 cron_trace_time_and_memory();
547 $pre_dbqueries = $DB->perf_get_queries();
548 $pre_time = microtime(true);
552 mtrace("done. (" . ($DB->perf_get_queries() - $pre_dbqueries) . " dbqueries, " .
553 round(microtime(true) - $pre_time, 2) . " seconds)");
555 set_config('lastcron', time(), $component);
560 mtrace('Finished ' . $description);
565 * Used to add in old-style cron functions within plugins that have not been converted to the
566 * new standard API. (The standard API is frankenstyle_name_cron() in lib.php; some types used
567 * cron.php and some used a different name.)
569 * @param string $plugintype Plugin type e.g. 'report'
570 * @param array $plugins Array from plugin name (e.g. 'report_frog') to function name (e.g.
571 * 'report_frog_cron') for plugin cron functions that were already found using the new API
572 * @return array Revised version of $plugins that adds in any extra plugin functions found by
573 * looking in the older location
575 function cron_bc_hack_plugin_functions($plugintype, $plugins) {
576 global $CFG; // mandatory in case it is referenced by include()d PHP script
578 if ($plugintype === 'report') {
579 // Admin reports only - not course report because course report was
580 // never implemented before, so doesn't need BC
581 foreach (get_plugin_list($plugintype) as $pluginname=>$dir) {
582 $component = $plugintype . '_' . $pluginname;
583 if (isset($plugins[$component])) {
584 // We already have detected the function using the new API
587 if (!file_exists("$dir/cron.php")) {
588 // No old style cron file present
591 include_once("$dir/cron.php");
592 $cronfunction = $component . '_cron';
593 if (function_exists($cronfunction)) {
594 $plugins[$component] = $cronfunction;
596 debugging("Invalid legacy cron.php detected in $component, " .
597 "please use lib.php instead");
600 } else if (strpos($plugintype, 'grade') === 0) {
601 // Detect old style cron function names
602 // Plugin gradeexport_frog used to use grade_export_frog_cron() instead of
603 // new standard API gradeexport_frog_cron(). Also applies to gradeimport, gradereport
604 foreach(get_plugin_list($plugintype) as $pluginname=>$dir) {
605 $component = $plugintype.'_'.$pluginname;
606 if (isset($plugins[$component])) {
607 // We already have detected the function using the new API
610 if (!file_exists("$dir/lib.php")) {
613 include_once("$dir/lib.php");
614 $cronfunction = str_replace('grade', 'grade_', $plugintype) . '_' .
615 $pluginname . '_cron';
616 if (function_exists($cronfunction)) {
617 $plugins[$component] = $cronfunction;
626 * Output some standard information during cron runs. Specifically current time
627 * and memory usage. This method also does gc_collect_cycles() (before displaying
628 * memory usage) to try to help PHP manage memory better.
630 function cron_trace_time_and_memory() {
632 mtrace('... started ' . date('H:i:s') . '. Current memory use ' . display_size(memory_get_usage()) . '.');
636 * Notify admin users or admin user of any failed logins (since last notification).
638 * Note that this function must be only executed from the cron script
639 * It uses the cache_flags system to store temporary records, deleting them
640 * by name before finishing
642 * @return bool True if executed, false if not
644 function notify_login_failures() {
645 global $CFG, $DB, $OUTPUT;
647 if (empty($CFG->notifyloginfailures
)) {
651 $recip = get_users_from_config($CFG->notifyloginfailures
, 'moodle/site:config');
653 if (empty($CFG->lastnotifyfailure
)) {
654 $CFG->lastnotifyfailure
=0;
657 // If it has been less than an hour, or if there are no recipients, don't execute.
658 if (((time() - HOURSECS
) < $CFG->lastnotifyfailure
) ||
!is_array($recip) ||
count($recip) <= 0) {
662 // we need to deal with the threshold stuff first.
663 if (empty($CFG->notifyloginthreshold
)) {
664 $CFG->notifyloginthreshold
= 10; // default to something sensible.
667 // Get all the IPs with more than notifyloginthreshold failures since lastnotifyfailure
668 // and insert them into the cache_flags temp table
669 $sql = "SELECT ip, COUNT(*)
671 WHERE module = 'login' AND action = 'error'
674 HAVING COUNT(*) >= ?";
675 $params = array($CFG->lastnotifyfailure
, $CFG->notifyloginthreshold
);
676 $rs = $DB->get_recordset_sql($sql, $params);
677 foreach ($rs as $iprec) {
678 if (!empty($iprec->ip
)) {
679 set_cache_flag('login_failure_by_ip', $iprec->ip
, '1', 0);
684 // Get all the INFOs with more than notifyloginthreshold failures since lastnotifyfailure
685 // and insert them into the cache_flags temp table
686 $sql = "SELECT info, count(*)
688 WHERE module = 'login' AND action = 'error'
691 HAVING count(*) >= ?";
692 $params = array($CFG->lastnotifyfailure
, $CFG->notifyloginthreshold
);
693 $rs = $DB->get_recordset_sql($sql, $params);
694 foreach ($rs as $inforec) {
695 if (!empty($inforec->info
)) {
696 set_cache_flag('login_failure_by_info', $inforec->info
, '1', 0);
701 // Now, select all the login error logged records belonging to the ips and infos
702 // since lastnotifyfailure, that we have stored in the cache_flags table
703 $sql = "SELECT * FROM (
704 SELECT l.*, u.firstname, u.lastname
706 JOIN {cache_flags} cf ON l.ip = cf.name
707 LEFT JOIN {user} u ON l.userid = u.id
708 WHERE l.module = 'login' AND l.action = 'error'
710 AND cf.flagtype = 'login_failure_by_ip'
712 SELECT l.*, u.firstname, u.lastname
714 JOIN {cache_flags} cf ON l.info = cf.name
715 LEFT JOIN {user} u ON l.userid = u.id
716 WHERE l.module = 'login' AND l.action = 'error'
718 AND cf.flagtype = 'login_failure_by_info') t
719 ORDER BY t.time DESC";
720 $params = array($CFG->lastnotifyfailure
, $CFG->lastnotifyfailure
);
722 // Init some variables
725 // Iterate over the logs recordset
726 $rs = $DB->get_recordset_sql($sql, $params);
727 foreach ($rs as $log) {
728 $log->time
= userdate($log->time
);
729 $messages .= get_string('notifyloginfailuresmessage','',$log)."\n";
734 // If we have something useful to report.
737 $subject = get_string('notifyloginfailuressubject', '', format_string($site->fullname
));
738 // Calculate the complete body of notification (start + messages + end)
739 $body = get_string('notifyloginfailuresmessagestart', '', $CFG->wwwroot
) .
740 (($CFG->lastnotifyfailure
!= 0) ?
'('.userdate($CFG->lastnotifyfailure
).')' : '')."\n\n" .
742 "\n\n".get_string('notifyloginfailuresmessageend','',$CFG->wwwroot
)."\n\n";
744 // For each destination, send mail
745 mtrace('Emailing admins about '. $count .' failed login attempts');
746 foreach ($recip as $admin) {
747 //emailing the admins directly rather than putting these through the messaging system
748 email_to_user($admin, generate_email_supportuser(), $subject, $body);
752 // Update lastnotifyfailure with current time
753 set_config('lastnotifyfailure', time());
755 // Finally, delete all the temp records we have created in cache_flags
756 $DB->delete_records_select('cache_flags', "flagtype IN ('login_failure_by_ip', 'login_failure_by_info')");