diff --git a/lib/classes/task/send_failed_login_notifications_task.php b/lib/classes/task/send_failed_login_notifications_task.php index 7791fcf8fc5..3fbe3b99f1d 100644 --- a/lib/classes/task/send_failed_login_notifications_task.php +++ b/lib/classes/task/send_failed_login_notifications_task.php @@ -28,6 +28,9 @@ namespace core\task; */ class send_failed_login_notifications_task extends scheduled_task { + /** The maximum time period to look back (30 days = 30 * 24 * 3600) */ + const NOTIFY_MAXIMUM_TIME = 2592000; + /** * Get a descriptive name for this task (shown to admins). * @@ -50,8 +53,10 @@ class send_failed_login_notifications_task extends scheduled_task { $recip = get_users_from_config($CFG->notifyloginfailures, 'moodle/site:config'); - if (empty($CFG->lastnotifyfailure)) { - $CFG->lastnotifyfailure = 0; + // Do not look back more than 1 month to avoid crashes due to huge number of records. + $maximumlastnotifytime = time() - self::NOTIFY_MAXIMUM_TIME; + if (empty($CFG->lastnotifyfailure) || ($CFG->lastnotifyfailure < $maximumlastnotifytime)) { + $CFG->lastnotifyfailure = $maximumlastnotifytime; } // If it has been less than an hour, or if there are no recipients, don't execute.