diff --git a/admin/cli/adhoc_task.php b/admin/cli/adhoc_task.php index dd1cc14b478b4..e6ccff48bca66 100644 --- a/admin/cli/adhoc_task.php +++ b/admin/cli/adhoc_task.php @@ -27,7 +27,6 @@ require(__DIR__ . '/../../config.php'); require_once("{$CFG->libdir}/clilib.php"); -require_once("{$CFG->libdir}/cronlib.php"); list($options, $unrecognized) = cli_get_params( [ @@ -120,7 +119,7 @@ raise_memory_limit(MEMORY_EXTRA); // Emulate normal session - we use admin account by default. -cron_setup_user(); +\core\cron::setup_user(); $humantimenow = date('r', time()); $keepalive = (int)$options['keep-alive']; @@ -128,4 +127,4 @@ \core\local\cli\shutdown::script_supports_graceful_exit(); mtrace("Server Time: {$humantimenow}\n"); -cron_run_adhoc_tasks(time(), $keepalive, $checklimits); +\core\cron::run_adhoc_tasks(time(), $keepalive, $checklimits); diff --git a/admin/cli/automated_backups.php b/admin/cli/automated_backups.php index 0b03282fbcf65..bb5c560b071ad 100644 --- a/admin/cli/automated_backups.php +++ b/admin/cli/automated_backups.php @@ -30,7 +30,6 @@ require(__DIR__.'/../../config.php'); require_once($CFG->libdir.'/clilib.php'); // cli only functions -require_once($CFG->libdir.'/cronlib.php'); // now get cli options list($options, $unrecognized) = cli_get_params(array('help'=>false), @@ -80,10 +79,10 @@ $starttime = microtime(); -/// emulate normal session -cron_setup_user(); +// Emulate normal session. +\core\cron::setup_user(); -/// Start output log +// Start output log. $timenow = time(); mtrace("Server Time: ".date('r',$timenow)."\n\n"); @@ -96,4 +95,4 @@ mtrace("Automated cron backups completed correctly"); $difftime = microtime_diff($starttime, microtime()); -mtrace("Execution took ".$difftime." seconds"); \ No newline at end of file +mtrace("Execution took ".$difftime." seconds"); diff --git a/admin/cli/cron.php b/admin/cli/cron.php index 1b7760c447c0f..5a6bb85375c95 100644 --- a/admin/cli/cron.php +++ b/admin/cli/cron.php @@ -31,7 +31,6 @@ require(__DIR__ . '/../../config.php'); require_once($CFG->libdir . '/clilib.php'); -require_once($CFG->libdir . '/cronlib.php'); // Now get cli option. [$options, $unrecognized] = cli_get_params( @@ -184,4 +183,4 @@ $keepalive = $options['keep-alive']; -cron_run($keepalive); +\core\cron::run_main_process($keepalive); diff --git a/admin/cli/delete_course.php b/admin/cli/delete_course.php index 2dfe9d8dbe454..92f4ae788537d 100644 --- a/admin/cli/delete_course.php +++ b/admin/cli/delete_course.php @@ -28,7 +28,6 @@ require(__DIR__ . '/../../config.php'); require_once($CFG->libdir . '/clilib.php'); -require_once($CFG->libdir . '/cronlib.php'); list($options, $unrecognized) = cli_get_params( [ diff --git a/admin/cli/scheduled_task.php b/admin/cli/scheduled_task.php index 367cda28e85ab..cf6e3accd80c3 100644 --- a/admin/cli/scheduled_task.php +++ b/admin/cli/scheduled_task.php @@ -27,7 +27,6 @@ require(__DIR__ . '/../../config.php'); require_once("$CFG->libdir/clilib.php"); -require_once("$CFG->libdir/cronlib.php"); list($options, $unrecognized) = cli_get_params( [ @@ -142,7 +141,7 @@ raise_memory_limit(MEMORY_EXTRA); // Emulate normal session - we use admin account by default. - cron_setup_user(); + \core\cron::setup_user(); // Execute the task. \core\local\cli\shutdown::script_supports_graceful_exit(); @@ -164,5 +163,5 @@ $task->set_cron_lock($cronlock); } - cron_run_inner_scheduled_task($task); + \core\cron::run_inner_scheduled_task($task); } diff --git a/admin/cron.php b/admin/cron.php index 1b4fd29f17ee8..5356eb7506ba4 100644 --- a/admin/cron.php +++ b/admin/cron.php @@ -50,7 +50,6 @@ require('../config.php'); require_once($CFG->libdir . '/clilib.php'); -require_once($CFG->libdir . '/cronlib.php'); // extra safety \core\session\manager::write_close(); @@ -78,4 +77,4 @@ @ini_set('html_errors', 'off'); // Execute the cron, disabling keepalive. -cron_run(0); +\core\cron::run_main_process(0); diff --git a/admin/settings/server.php b/admin/settings/server.php index 68976834265ef..8700ac4e69283 100644 --- a/admin/settings/server.php +++ b/admin/settings/server.php @@ -348,7 +348,7 @@ ); // Set an upper limit of 15 minutes. - $setting->set_max_duration(15 * MINSEC); + $setting->set_max_duration(15 * MINSECS); $temp->add($setting); diff --git a/admin/tool/customlang/cli/import.php b/admin/tool/customlang/cli/import.php index 492e466b7ae9c..b0ce921113067 100644 --- a/admin/tool/customlang/cli/import.php +++ b/admin/tool/customlang/cli/import.php @@ -101,7 +101,7 @@ } // Emulate normal session - we use admin account by default. -cron_setup_user(); +\core\cron::setup_user(); // Get the file list. $files = []; diff --git a/admin/tool/messageinbound/classes/manager.php b/admin/tool/messageinbound/classes/manager.php index 4864bef802996..61152721af700 100644 --- a/admin/tool/messageinbound/classes/manager.php +++ b/admin/tool/messageinbound/classes/manager.php @@ -366,7 +366,7 @@ public function process_message( } // Record the user that this script is currently being run as. This is important when re-processing existing - // messages, as cron_setup_user is called multiple times. + // messages, as \core\cron::setup_user is called multiple times. $originaluser = $USER; $envelope = $message->getEnvelope(); @@ -433,7 +433,7 @@ public function process_message( // Process the message as the user. $user = $this->addressmanager->get_data()->user; mtrace("-- Processing the message as user {$user->id} ({$user->username})."); - cron_setup_user($user); + \core\cron::setup_user($user); // Process and retrieve the message data for this message. // This includes fetching the full content, as well as all headers, and attachments. @@ -459,7 +459,7 @@ public function process_message( // Returning to normal cron user. mtrace("-- Returning to the original user."); - cron_setup_user($originaluser); + \core\cron::setup_user($originaluser); return; } @@ -478,7 +478,7 @@ public function process_message( // Returning to normal cron user. mtrace("-- Returning to the original user."); - cron_setup_user($originaluser); + \core\cron::setup_user($originaluser); return; } catch (\Exception $e) { // An unknown error occurred. The user is not informed, but the administrator is. @@ -487,7 +487,7 @@ public function process_message( // Returning to normal cron user. mtrace("-- Returning to the original user."); - cron_setup_user($originaluser); + \core\cron::setup_user($originaluser); return; } @@ -501,7 +501,7 @@ public function process_message( // Returning to normal cron user. mtrace("-- Returning to the original user."); - cron_setup_user($originaluser); + \core\cron::setup_user($originaluser); mtrace("-- Finished processing " . $message->getUid()); diff --git a/admin/tool/task/clear_fail_delay.php b/admin/tool/task/clear_fail_delay.php index 032be004634fc..682e566450b1e 100644 --- a/admin/tool/task/clear_fail_delay.php +++ b/admin/tool/task/clear_fail_delay.php @@ -26,8 +26,6 @@ require('../../../config.php'); -require_once($CFG->libdir.'/cronlib.php'); - // Basic security checks. require_admin(); $context = context_system::instance(); diff --git a/admin/tool/task/schedule_task.php b/admin/tool/task/schedule_task.php index aabd3de70eae2..d2cd31d93e157 100644 --- a/admin/tool/task/schedule_task.php +++ b/admin/tool/task/schedule_task.php @@ -28,8 +28,6 @@ require('../../../config.php'); -require_once($CFG->libdir.'/cronlib.php'); - /** * Function used to handle mtrace by outputting the text to normal browser window. * diff --git a/admin/tool/uploadcourse/cli/uploadcourse.php b/admin/tool/uploadcourse/cli/uploadcourse.php index 5068670d8b2c9..800987026a3fb 100644 --- a/admin/tool/uploadcourse/cli/uploadcourse.php +++ b/admin/tool/uploadcourse/cli/uploadcourse.php @@ -184,7 +184,7 @@ $processoroptions['restorefile'] = $options['restorefile']; // Emulate normal session. -cron_setup_user(); +\core\cron::setup_user(); // Let's get started! $content = file_get_contents($options['file']); diff --git a/admin/tool/uploaduser/cli/uploaduser.php b/admin/tool/uploaduser/cli/uploaduser.php index 5db9e0261b364..667d893f31119 100644 --- a/admin/tool/uploaduser/cli/uploaduser.php +++ b/admin/tool/uploaduser/cli/uploaduser.php @@ -36,7 +36,7 @@ raise_memory_limit(MEMORY_EXTRA); // Emulate normal session - we use admin account by default, set language to the site language. -cron_setup_user(); +\core\cron::setup_user(); $USER->lang = $CFG->lang; $clihelper = new \tool_uploaduser\cli_helper(); diff --git a/backup/tests/automated_backup_test.php b/backup/tests/automated_backup_test.php index c7bc863b418cc..26831d2ab43f0 100644 --- a/backup/tests/automated_backup_test.php +++ b/backup/tests/automated_backup_test.php @@ -30,7 +30,6 @@ global $CFG; require_once($CFG->dirroot . '/backup/util/helper/backup_cron_helper.class.php'); -require_once($CFG->libdir.'/cronlib.php'); require_once($CFG->libdir . '/completionlib.php'); /** diff --git a/backup/util/helper/backup_cron_helper.class.php b/backup/util/helper/backup_cron_helper.class.php index ff7610398b99f..9d25262ec7b23 100644 --- a/backup/util/helper/backup_cron_helper.class.php +++ b/backup/util/helper/backup_cron_helper.class.php @@ -123,7 +123,7 @@ public static function run_automated_backup($rundirective = self::RUN_ON_SCHEDUL mtrace("Skipping deleted courses", '...'); mtrace(sprintf("%d courses", self::remove_deleted_courses_from_schedule())); mtrace('Running required automated backups...'); - cron_trace_time_and_memory(); + \core\cron::trace_time_and_memory(); mtrace("Getting admin info"); $admin = get_admin(); diff --git a/course/classes/task/content_notification_task.php b/course/classes/task/content_notification_task.php index d731fc884604c..d7deffd2c4ec8 100644 --- a/course/classes/task/content_notification_task.php +++ b/course/classes/task/content_notification_task.php @@ -68,7 +68,7 @@ public function execute() { from user with id {$userfrom->id}."); foreach ($users as $user) { - cron_setup_user($user, $course); + \core\cron::setup_user($user, $course); $cm = get_fast_modinfo($course)->cms[$cm->id]; diff --git a/course/classes/task/course_delete_modules.php b/course/classes/task/course_delete_modules.php index 77ef3d9e517f7..ad796ee349f7d 100644 --- a/course/classes/task/course_delete_modules.php +++ b/course/classes/task/course_delete_modules.php @@ -53,11 +53,11 @@ public function execute() { // Set the proper user. if ($this->get_custom_data()->userid !== $this->get_custom_data()->realuserid) { $realuser = \core_user::get_user($this->get_custom_data()->realuserid, '*', MUST_EXIST); - cron_setup_user($realuser); + \core\cron::setup_user($realuser); \core\session\manager::loginas($this->get_custom_data()->userid, \context_system::instance(), false); } else { $user = \core_user::get_user($this->get_custom_data()->userid, '*', MUST_EXIST); - cron_setup_user($user); + \core\cron::setup_user($user); } $cms = $this->get_custom_data()->cms; diff --git a/lib/classes/task/plagiarism_cron_task.php b/lib/classes/task/plagiarism_cron_task.php index 9d600ff944a54..0f69b980d6168 100644 --- a/lib/classes/task/plagiarism_cron_task.php +++ b/lib/classes/task/plagiarism_cron_task.php @@ -53,7 +53,7 @@ public function execute() { $plagiarismplugin = new $plagiarismclass; if (method_exists($plagiarismplugin, 'cron')) { mtrace('Processing cron function for plagiarism_plugin_' . $plugin . '...', ''); - cron_trace_time_and_memory(); + \core\cron::trace_time_and_memory(); mtrace('It has been detected the class ' . $plagiarismclass . ' has a legacy cron method implemented. Plagiarism plugins should implement their own schedule tasks.', ''); $plagiarismplugin->cron(); diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 82ae689b1d2ff..3719e50d48662 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -2838,7 +2838,7 @@ function cron_execute_plugin_type($plugintype, $description = null) { mtrace('Processing cron function for ' . $component . '...'); debugging("Use of legacy cron is deprecated ($cronfunction). Please use scheduled tasks.", DEBUG_DEVELOPER); - cron_trace_time_and_memory(); + \core\cron::trace_time_and_memory(); $pre_dbqueries = $DB->perf_get_queries(); $pre_time = microtime(true); diff --git a/lib/filestorage/file_storage.php b/lib/filestorage/file_storage.php index e3a852271ffcd..9c6e3c33937ca 100644 --- a/lib/filestorage/file_storage.php +++ b/lib/filestorage/file_storage.php @@ -2250,12 +2250,11 @@ public static function mimetype_from_file($fullpath) { */ public function cron() { global $CFG, $DB; - require_once($CFG->libdir.'/cronlib.php'); // find out all stale draft areas (older than 4 days) and purge them // those are identified by time stamp of the /. root dir mtrace('Deleting old draft files... ', ''); - cron_trace_time_and_memory(); + \core\cron::trace_time_and_memory(); $old = time() - 60*60*24*4; $sql = "SELECT * FROM {files} @@ -2272,7 +2271,7 @@ public function cron() { // * preview files in the core preview filearea without the existing original file. // * document converted files in core documentconversion filearea without the existing original file. mtrace('Deleting orphaned preview, and document conversion files... ', ''); - cron_trace_time_and_memory(); + \core\cron::trace_time_and_memory(); $sql = "SELECT p.* FROM {files} p LEFT JOIN {files} o ON (p.filename = o.contenthash) @@ -2299,7 +2298,7 @@ public function cron() { require_once($CFG->libdir.'/filelib.php'); // Delete files that are associated with a context that no longer exists. mtrace('Cleaning up files from deleted contexts... ', ''); - cron_trace_time_and_memory(); + \core\cron::trace_time_and_memory(); $sql = "SELECT DISTINCT f.contextid FROM {files} f LEFT OUTER JOIN {context} c ON f.contextid = c.id @@ -2315,7 +2314,7 @@ public function cron() { mtrace('done.'); mtrace('Call filesystem cron tasks.', ''); - cron_trace_time_and_memory(); + \core\cron::trace_time_and_memory(); $this->filesystem->cron(); mtrace('done.'); } diff --git a/lib/phpunit/classes/advanced_testcase.php b/lib/phpunit/classes/advanced_testcase.php index 991e63796acf8..146ff3bf71a7e 100644 --- a/lib/phpunit/classes/advanced_testcase.php +++ b/lib/phpunit/classes/advanced_testcase.php @@ -689,8 +689,7 @@ public function waitForSecond() { * @param int $matchuserid The userid to match. */ protected function runAdhocTasks($matchclass = '', $matchuserid = null) { - global $CFG, $DB; - require_once($CFG->libdir.'/cronlib.php'); + global $DB; $params = []; if (!empty($matchclass)) { @@ -729,7 +728,7 @@ protected function runAdhocTasks($matchclass = '', $matchuserid = null) { $task->set_cron_lock($cronlock); } - cron_prepare_core_renderer(); + \core\cron::prepare_core_renderer(); $this->setUser($user); $task->execute(); diff --git a/lib/statslib.php b/lib/statslib.php index 04c5744bf857b..b8421b586f66b 100644 --- a/lib/statslib.php +++ b/lib/statslib.php @@ -164,7 +164,7 @@ function stats_cron_daily($maxdays=1) { $defaultfproleid = (int)$CFG->defaultfrontpageroleid; mtrace("Running daily statistics gathering, starting at $timestart:"); - cron_trace_time_and_memory(); + \core\cron::trace_time_and_memory(); $days = 0; $total = 0; @@ -664,7 +664,7 @@ function stats_cron_weekly() { $DB->delete_records_select('stats_user_weekly', "timeend > $timestart"); mtrace("Running weekly statistics gathering, starting at $timestart:"); - cron_trace_time_and_memory(); + \core\cron::trace_time_and_memory(); $weeks = 0; while ($now > $nextstartweek) { @@ -807,7 +807,7 @@ function stats_cron_monthly() { mtrace("Running monthly statistics gathering, starting at $timestart:"); - cron_trace_time_and_memory(); + \core\cron::trace_time_and_memory(); $months = 0; while ($now > $nextstartmonth) { @@ -1068,7 +1068,7 @@ function stats_get_next_month_start($time) { function stats_clean_old() { global $DB; mtrace("Running stats cleanup tasks..."); - cron_trace_time_and_memory(); + \core\cron::trace_time_and_memory(); $deletebefore = stats_get_base_monthly(); // delete dailies older than 3 months (to be safe) diff --git a/lib/tests/behat/behat_general.php b/lib/tests/behat/behat_general.php index 29953ce53835d..b19ca32fc77d3 100644 --- a/lib/tests/behat/behat_general.php +++ b/lib/tests/behat/behat_general.php @@ -1108,9 +1108,6 @@ public function i_trigger_cron() { * @param string $taskname Name of task e.g. 'mod_whatever\task\do_something' */ public function i_run_the_scheduled_task($taskname) { - global $CFG; - require_once("{$CFG->libdir}/cronlib.php"); - $task = \core\task\manager::get_scheduled_task($taskname); if (!$task) { throw new DriverException('The "' . $taskname . '" scheduled task does not exist'); @@ -1118,7 +1115,7 @@ public function i_run_the_scheduled_task($taskname) { // Do setup for cron task. raise_memory_limit(MEMORY_EXTRA); - cron_setup_user(); + \core\cron::setup_user(); // Get lock. $cronlockfactory = \core\lock\lock_config::get_lock_factory('cron'); @@ -1138,7 +1135,7 @@ public function i_run_the_scheduled_task($taskname) { try { // Prepare the renderer. - cron_prepare_core_renderer(); + \core\cron::prepare_core_renderer(); // Discard task output as not appropriate for Behat output! ob_start(); @@ -1146,13 +1143,13 @@ public function i_run_the_scheduled_task($taskname) { ob_end_clean(); // Restore the previous renderer. - cron_prepare_core_renderer(true); + \core\cron::prepare_core_renderer(true); // Mark task complete. \core\task\manager::scheduled_task_complete($task); } catch (Exception $e) { // Restore the previous renderer. - cron_prepare_core_renderer(true); + \core\cron::prepare_core_renderer(true); // Mark task failed and throw exception. \core\task\manager::scheduled_task_failed($task); @@ -1175,11 +1172,10 @@ public function i_run_the_scheduled_task($taskname) { * @throws DriverException */ public function i_run_all_adhoc_tasks() { - global $CFG, $DB; - require_once("{$CFG->libdir}/cronlib.php"); + global $DB; // Do setup for cron task. - cron_setup_user(); + \core\cron::setup_user(); // Discard task output as not appropriate for Behat output! ob_start(); @@ -1193,7 +1189,7 @@ public function i_run_all_adhoc_tasks() { ob_clean(); // Run the task. - cron_run_inner_adhoc_task($task); + \core\cron::run_inner_adhoc_task($task); // Check whether the task record still exists. // If a task was successful it will be removed. diff --git a/lib/tests/statslib_test.php b/lib/tests/statslib_test.php index c3551156f12be..c46ceabfc127e 100644 --- a/lib/tests/statslib_test.php +++ b/lib/tests/statslib_test.php @@ -21,7 +21,6 @@ global $CFG; require_once($CFG->libdir . '/adminlib.php'); require_once($CFG->libdir . '/statslib.php'); -require_once($CFG->libdir . '/cronlib.php'); require_once(__DIR__ . '/fixtures/stats_events.php'); /** diff --git a/message/output/email/classes/task/send_email_task.php b/message/output/email/classes/task/send_email_task.php index 11bbcfbf99433..9696dfb141a66 100644 --- a/message/output/email/classes/task/send_email_task.php +++ b/message/output/email/classes/task/send_email_task.php @@ -73,7 +73,7 @@ public function execute() { // Keep track of which emails failed to send. $users = $this->get_unique_users(); foreach ($users as $user) { - cron_setup_user($user); + \core\cron::setup_user($user); $hascontent = false; $renderable = new \message_email\output\email_digest($user); @@ -99,7 +99,7 @@ public function execute() { } } } - cron_setup_user(); + \core\cron::setup_user(); $users->close(); } diff --git a/mod/assign/feedback/editpdf/tests/feedback_test.php b/mod/assign/feedback/editpdf/tests/feedback_test.php index a777955e95ba5..e18a4b994a23e 100644 --- a/mod/assign/feedback/editpdf/tests/feedback_test.php +++ b/mod/assign/feedback/editpdf/tests/feedback_test.php @@ -344,7 +344,7 @@ public function test_document_services() { public function test_conversion_task() { $this->require_ghostscript(); $this->resetAfterTest(); - cron_setup_user(); + \core\cron::setup_user(); $course = $this->getDataGenerator()->create_course(); $student = $this->getDataGenerator()->create_and_enrol($course, 'student'); diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 8496e16e8b67b..9817b2d621fc6 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -2744,7 +2744,7 @@ public static function cron() { // Override the language and timezone of the "current" user, so that // mail is customised for the receiver. - cron_setup_user($user, $course); + \core\cron::setup_user($user, $course); // Context lookups are already cached. $coursecontext = context_course::instance($course->id); @@ -2824,7 +2824,7 @@ public static function cron() { } mtrace('Done processing ' . count($submissions) . ' assignment submissions'); - cron_setup_user(); + \core\cron::setup_user(); // Free up memory just to be sure. unset($courses); diff --git a/mod/assign/tests/locallib_test.php b/mod/assign/tests/locallib_test.php index b91f2f444ea2d..7beb742b699c1 100644 --- a/mod/assign/tests/locallib_test.php +++ b/mod/assign/tests/locallib_test.php @@ -1562,7 +1562,7 @@ public function test_cron() { $this->resetAfterTest(); // First run cron so there are no messages waiting to be sent (from other tests). - cron_setup_user(); + \core\cron::setup_user(); \assign::cron(); $course = $this->getDataGenerator()->create_course(); @@ -1580,7 +1580,7 @@ public function test_cron() { $this->mark_submission($teacher, $assign, $student, 50.0); $this->expectOutputRegex('/Done processing 1 assignment submissions/'); - cron_setup_user(); + \core\cron::setup_user(); $sink = $this->redirectMessages(); \assign::cron(); $messages = $sink->get_messages(); @@ -1604,7 +1604,7 @@ public function test_cron_without_notifications() { $this->resetAfterTest(); // First run cron so there are no messages waiting to be sent (from other tests). - cron_setup_user(); + \core\cron::setup_user(); \assign::cron(); $course = $this->getDataGenerator()->create_course(); @@ -1623,7 +1623,7 @@ public function test_cron_without_notifications() { 'sendstudentnotifications' => 0, ]); - cron_setup_user(); + \core\cron::setup_user(); $sink = $this->redirectMessages(); \assign::cron(); $messages = $sink->get_messages(); @@ -1635,7 +1635,7 @@ public function test_cron_regraded() { $this->resetAfterTest(); // First run cron so there are no messages waiting to be sent (from other tests). - cron_setup_user(); + \core\cron::setup_user(); \assign::cron(); $course = $this->getDataGenerator()->create_course(); @@ -1653,14 +1653,14 @@ public function test_cron_regraded() { $this->mark_submission($teacher, $assign, $student, 50.0); $this->expectOutputRegex('/Done processing 1 assignment submissions/'); - cron_setup_user(); + \core\cron::setup_user(); \assign::cron(); // Regrade. $this->mark_submission($teacher, $assign, $student, 50.0); $this->expectOutputRegex('/Done processing 1 assignment submissions/'); - cron_setup_user(); + \core\cron::setup_user(); $sink = $this->redirectMessages(); \assign::cron(); $messages = $sink->get_messages(); @@ -1677,7 +1677,7 @@ public function test_markingworkflow_cron() { $this->resetAfterTest(); // First run cron so there are no messages waiting to be sent (from other tests). - cron_setup_user(); + \core\cron::setup_user(); \assign::cron(); $course = $this->getDataGenerator()->create_course(); @@ -1700,7 +1700,7 @@ public function test_markingworkflow_cron() { 'workflowstate' => ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE, ]); - cron_setup_user(); + \core\cron::setup_user(); $sink = $this->redirectMessages(); \assign::cron(); $messages = $sink->get_messages(); @@ -1714,7 +1714,7 @@ public function test_markingworkflow_cron() { $assign->testable_apply_grade_to_user($submission, $student->id, 0); // Now run cron and see that one message was sent. - cron_setup_user(); + \core\cron::setup_user(); $sink = $this->redirectMessages(); $this->expectOutputRegex('/Done processing 1 assignment submissions/'); \assign::cron(); @@ -1729,7 +1729,7 @@ public function test_cron_message_includes_courseid() { $this->resetAfterTest(); // First run cron so there are no messages waiting to be sent (from other tests). - cron_setup_user(); + \core\cron::setup_user(); \assign::cron(); $course = $this->getDataGenerator()->create_course(); @@ -1750,7 +1750,7 @@ public function test_cron_message_includes_courseid() { \phpunit_util::stop_message_redirection(); // Now run cron and see that one message was sent. - cron_setup_user(); + \core\cron::setup_user(); $this->preventResetByRollback(); $sink = $this->redirectEvents(); $this->expectOutputRegex('/Done processing 1 assignment submissions/'); diff --git a/mod/bigbluebuttonbn/classes/task/send_notification.php b/mod/bigbluebuttonbn/classes/task/send_notification.php index c2110b1b90ca3..51f100237e66c 100644 --- a/mod/bigbluebuttonbn/classes/task/send_notification.php +++ b/mod/bigbluebuttonbn/classes/task/send_notification.php @@ -183,7 +183,7 @@ protected function send_all_notifications(): void { foreach ($this->get_recipients() as $recipient) { try { \core_user::require_active_user($recipient, true, true); - cron_setup_user($recipient); + \core\cron::setup_user($recipient); } catch (moodle_exception $e) { // Skip sending. continue; @@ -192,7 +192,7 @@ protected function send_all_notifications(): void { $this->send_notification_to_current_user(); } - cron_setup_user(); + \core\cron::setup_user(); } /** diff --git a/mod/forum/classes/task/cron_task.php b/mod/forum/classes/task/cron_task.php index ade297fd42f50..258ea02efd1ad 100644 --- a/mod/forum/classes/task/cron_task.php +++ b/mod/forum/classes/task/cron_task.php @@ -329,7 +329,7 @@ protected function queue_user_tasks() { $send = false; // Setup this user so that the capabilities are cached, and environment matches receiving user. - cron_setup_user($user); + \core\cron::setup_user($user); list($individualpostdata, $digestpostdata) = $this->fetch_posts_for_user($user); diff --git a/mod/forum/tests/cron_trait.php b/mod/forum/tests/cron_trait.php index e2d154ba3ce49..f3f31af5632cb 100644 --- a/mod/forum/tests/cron_trait.php +++ b/mod/forum/tests/cron_trait.php @@ -36,7 +36,7 @@ protected function queue_tasks_and_assert($expectations = []) { // Note, we cannot use expectOutputRegex because it only allows for a single RegExp. ob_start(); - cron_setup_user(); + \core\cron::setup_user(); $cron = new \mod_forum\task\cron_task(); $cron->execute(); $output = ob_get_contents(); diff --git a/mod/workshop/allocation/scheduled/tests/scheduled_allocator_test.php b/mod/workshop/allocation/scheduled/tests/scheduled_allocator_test.php index cd031a34b944d..d227143fab1bb 100644 --- a/mod/workshop/allocation/scheduled/tests/scheduled_allocator_test.php +++ b/mod/workshop/allocation/scheduled/tests/scheduled_allocator_test.php @@ -54,7 +54,7 @@ public function test_that_allocator_in_executed_on_submission_end_when_phaseswit $workshopgenerator = $this->getDataGenerator()->get_plugin_generator('mod_workshop'); - cron_setup_user(); + \core\cron::setup_user(); // Let the students add submissions. $this->workshop->switch_phase(\workshop::PHASE_SUBMISSION); @@ -94,7 +94,7 @@ public function test_that_allocator_is_not_executed_when_its_not_active(): void $workshopgenerator = $this->getDataGenerator()->get_plugin_generator('mod_workshop'); - cron_setup_user(); + \core\cron::setup_user(); // Let the students add submissions. $this->workshop->switch_phase(\workshop::PHASE_SUBMISSION); diff --git a/mod/workshop/tests/event/events_test.php b/mod/workshop/tests/event/events_test.php index 2f98599b04438..b8c1ae77ce087 100644 --- a/mod/workshop/tests/event/events_test.php +++ b/mod/workshop/tests/event/events_test.php @@ -32,7 +32,6 @@ global $CFG; require_once($CFG->dirroot . '/mod/workshop/lib.php'); // Include the code to test. require_once($CFG->dirroot . '/mod/workshop/locallib.php'); // Include the code to test. -require_once($CFG->dirroot . '/lib/cronlib.php'); // Include the code to test. require_once(__DIR__ . '/../fixtures/testable.php'); diff --git a/mod/workshop/tests/task/cron_task_test.php b/mod/workshop/tests/task/cron_task_test.php index 2de236b8e87f4..68f8cae17d953 100644 --- a/mod/workshop/tests/task/cron_task_test.php +++ b/mod/workshop/tests/task/cron_task_test.php @@ -60,7 +60,7 @@ public function test_phase_switching() { // Execute the cron. ob_start(); - cron_setup_user(); + \core\cron::setup_user(); $cron = new \mod_workshop\task\cron_task(); $cron->execute(); $output = ob_get_contents(); @@ -96,7 +96,7 @@ public function test_that_phase_automatically_switched_event_is_triggerd_when_ph // Execute the cron. $eventsink = $this->redirectEvents(); ob_start(); - cron_setup_user(); + \core\cron::setup_user(); $cron = new \mod_workshop\task\cron_task(); $cron->execute(); ob_end_clean(); diff --git a/reportbuilder/classes/task/send_schedule.php b/reportbuilder/classes/task/send_schedule.php index b978961977c17..e9aa09600f707 100644 --- a/reportbuilder/classes/task/send_schedule.php +++ b/reportbuilder/classes/task/send_schedule.php @@ -75,10 +75,10 @@ public function execute(): void { // Handle schedule configuration as to who the report should be viewed as. if ($scheduleuserviewas === schedule::REPORT_VIEWAS_CREATOR) { - cron_setup_user(core_user::get_user($schedule->get('usercreated'))); + \core\cron::setup_user(core_user::get_user($schedule->get('usercreated'))); $scheduleattachment = helper::get_schedule_report_file($schedule); } else if ($scheduleuserviewas !== schedule::REPORT_VIEWAS_RECIPIENT) { - cron_setup_user(core_user::get_user($scheduleuserviewas)); + \core\cron::setup_user(core_user::get_user($scheduleuserviewas)); $scheduleattachment = helper::get_schedule_report_file($schedule); } @@ -98,7 +98,7 @@ public function execute(): void { if ($scheduleattachment !== null) { helper::send_schedule_message($schedule, $user, $scheduleattachment); } else { - cron_setup_user($user); + \core\cron::setup_user($user); if ($schedulereportempty === schedule::REPORT_EMPTY_DONT_SEND && helper::get_schedule_report_count($schedule) === 0) { @@ -123,6 +123,6 @@ public function execute(): void { $this->log_finish('Sending schedule complete'); // Restore cron user to original state. - cron_setup_user($originaluser); + \core\cron::setup_user($originaluser); } } diff --git a/search/classes/engine.php b/search/classes/engine.php index 788c27a4f08f3..a0814836d2e6e 100644 --- a/search/classes/engine.php +++ b/search/classes/engine.php @@ -306,7 +306,7 @@ public function add_documents($iterator, $searcharea, $options) { $now = manager::get_current_time(); if ($now - $lastprogress >= manager::DISPLAY_INDEXING_PROGRESS_EVERY) { $lastprogress = $now; - // The first date format is the same used in cron_trace_time_and_memory(). + // The first date format is the same used in \core\cron::trace_time_and_memory(). $options['progress']->output(date('H:i:s', (int)$now) . ': Done to ' . userdate( $lastindexeddoc, get_string('strftimedatetimeshort', 'langconfig')), 1); }