From 07a06264dc88d74493ce6d56883012c016ece049 Mon Sep 17 00:00:00 2001 From: Ankit Agarwal Date: Fri, 26 Dec 2014 08:40:40 +0530 Subject: [PATCH] MDL-37584 tasks: Use a senisible maximum time window for the task --- .../task/send_failed_login_notifications_task.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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.