MDL-77186 core: Move all uses of cronlib to new class

This commit is contained in:
Andrew Nicols
2023-03-13 21:21:13 +08:00
parent 99a67b615f
commit 9ec46c232d
36 changed files with 73 additions and 92 deletions
+2 -3
View File
@@ -27,7 +27,6 @@ define('CLI_SCRIPT', true);
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 @@ core_php_time_limit::raise();
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 @@ $keepalive = (int)$options['keep-alive'];
\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);
+4 -5
View File
@@ -30,7 +30,6 @@ define('CLI_SCRIPT', true);
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 @@ if (!empty($CFG->showcrondebugging)) {
$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 @@ backup_cron_automated_helper::run_automated_backup(backup_cron_automated_helper:
mtrace("Automated cron backups completed correctly");
$difftime = microtime_diff($starttime, microtime());
mtrace("Execution took ".$difftime." seconds");
mtrace("Execution took ".$difftime." seconds");
+1 -2
View File
@@ -31,7 +31,6 @@ define('CLI_SCRIPT', true);
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 @@ if (!get_config('core', 'cron_enabled') && !$options['force']) {
$keepalive = $options['keep-alive'];
cron_run($keepalive);
\core\cron::run_main_process($keepalive);
-1
View File
@@ -28,7 +28,6 @@ define('CLI_SCRIPT', true);
require(__DIR__ . '/../../config.php');
require_once($CFG->libdir . '/clilib.php');
require_once($CFG->libdir . '/cronlib.php');
list($options, $unrecognized) = cli_get_params(
[
+2 -3
View File
@@ -27,7 +27,6 @@ define('CLI_SCRIPT', true);
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 @@ if ($execute = $options['execute']) {
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 @@ if ($execute = $options['execute']) {
$task->set_cron_lock($cronlock);
}
cron_run_inner_scheduled_task($task);
\core\cron::run_inner_scheduled_task($task);
}
+1 -2
View File
@@ -50,7 +50,6 @@ define('NO_OUTPUT_BUFFERING', true);
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 @@ if (!empty($CFG->cronremotepassword)) {
@ini_set('html_errors', 'off');
// Execute the cron, disabling keepalive.
cron_run(0);
\core\cron::run_main_process(0);
+1 -1
View File
@@ -348,7 +348,7 @@ if ($hassiteconfig) {
);
// Set an upper limit of 15 minutes.
$setting->set_max_duration(15 * MINSEC);
$setting->set_max_duration(15 * MINSECS);
$temp->add($setting);
+1 -1
View File
@@ -101,7 +101,7 @@ if (!file_exists($source)) {
}
// Emulate normal session - we use admin account by default.
cron_setup_user();
\core\cron::setup_user();
// Get the file list.
$files = [];
@@ -366,7 +366,7 @@ class manager {
}
// 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 @@ class manager {
// 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 @@ class manager {
// 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 @@ class manager {
// 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 @@ class manager {
// 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 @@ class manager {
// 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());
-2
View File
@@ -26,8 +26,6 @@ define('NO_OUTPUT_BUFFERING', true);
require('../../../config.php');
require_once($CFG->libdir.'/cronlib.php');
// Basic security checks.
require_admin();
$context = context_system::instance();
-2
View File
@@ -28,8 +28,6 @@ define('NO_OUTPUT_BUFFERING', true);
require('../../../config.php');
require_once($CFG->libdir.'/cronlib.php');
/**
* Function used to handle mtrace by outputting the text to normal browser window.
*
+1 -1
View File
@@ -184,7 +184,7 @@ if ($options['restorefile'] && !file_exists($options['restorefile'])) {
$processoroptions['restorefile'] = $options['restorefile'];
// Emulate normal session.
cron_setup_user();
\core\cron::setup_user();
// Let's get started!
$content = file_get_contents($options['file']);
+1 -1
View File
@@ -36,7 +36,7 @@ core_php_time_limit::raise();
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();