. /** * Task executor for adhoc tasks. * * @package core * @subpackage cli * @copyright 2018 Andrew Nicols * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ define('CLI_SCRIPT', true); require(__DIR__ . '/../../config.php'); require_once("{$CFG->libdir}/clilib.php"); list($options, $unrecognized) = cli_get_params( [ 'help' => false, 'showsql' => false, 'showdebugging' => false, 'execute' => false, 'keep-alive' => 0, 'ignorelimits' => false, 'force' => false, 'id' => null, 'classname' => null, 'taskslimit' => null, 'failed' => false, ], [ 'h' => 'help', 'e' => 'execute', 'k' => 'keep-alive', 'i' => 'ignorelimits', 'f' => 'force', 'c' => 'classname', 'l' => 'taskslimit', ] ); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } $help = <<set_debug(true); } if (!empty($CFG->showcronsql)) { $DB->set_debug(true); } if (!empty($CFG->showcrondebugging)) { set_debugging(DEBUG_DEVELOPER, true); } // Process params. core_php_time_limit::raise(); // Increase memory limit. raise_memory_limit(MEMORY_EXTRA); // Emulate normal session - we use admin account by default. \core\cron::setup_user(); \core\local\cli\shutdown::script_supports_graceful_exit(); $humantimenow = date('r', time()); mtrace("Server Time: {$humantimenow}\n"); $classname = $options['classname']; // Run a single adhoc task only, if requested. if (!empty($options['id'])) { $taskid = (int) $options['id']; \core\cron::run_adhoc_task($taskid); exit(0); } // Run all failed tasks. if (!empty($options['failed'])) { \core\cron::run_failed_adhoc_tasks($classname); exit(0); } // Examine params and determine if we should run. $execute = (bool) $options['execute']; $keepalive = empty($options['keep-alive']) ? 0 : (int) $options['keep-alive']; $taskslimit = empty($options['taskslimit']) ? null : (int) $options['taskslimit']; $checklimits = empty($options['ignorelimits']); if ($classname || $keepalive || $taskslimit) { $execute = true; } // Output the help text if no criteria for running the adhoc tasks are given. if (!$execute) { echo $help; exit(0); } \core\cron::run_adhoc_tasks(time(), $keepalive, $checklimits, null, $taskslimit, $classname);