diff --git a/lib/classes/task/manager.php b/lib/classes/task/manager.php index e2ec497a3fb..d4e09f9ac47 100644 --- a/lib/classes/task/manager.php +++ b/lib/classes/task/manager.php @@ -456,6 +456,8 @@ class manager { $params = array('timestart1' => $timestart, 'timestart2' => $timestart); $records = $DB->get_records_select('task_scheduled', $where, $params); + $pluginmanager = \core_plugin_manager::instance(); + foreach ($records as $record) { if ($lock = $cronlockfactory->get_lock(($record->classname), 10)) { @@ -463,6 +465,17 @@ class manager { $task = self::scheduled_task_from_record($record); $task->set_lock($lock); + + // See if the component is disabled. + $plugininfo = $pluginmanager->get_plugin_info($task->get_component()); + + if ($plugininfo) { + if (!$task->get_run_if_component_disabled() && !$plugininfo->is_enabled()) { + $lock->release(); + continue; + } + } + if (!$task->is_blocking()) { $cronlock->release(); } else { diff --git a/lib/classes/task/scheduled_task.php b/lib/classes/task/scheduled_task.php index 47e93c7bdc0..ed2fc03144c 100644 --- a/lib/classes/task/scheduled_task.php +++ b/lib/classes/task/scheduled_task.php @@ -183,6 +183,15 @@ abstract class scheduled_task extends task_base { return $this->disabled; } + /** + * Override this function if you want this scheduled task to run, even if the component is disabled. + * + * @return bool + */ + public function get_run_if_component_disabled() { + return false; + } + /** * Take a cron field definition and return an array of valid numbers with the range min-max. *