require_once "{$CFG->libdir}/clilib.php"; require_once "{$CFG->libdir}/cronlib.php"; list($options, $unrecognized) = cli_get_params(array('help' => false, 'list' => false, 'execute' => false), array('h' => 'help')); if ($unrecognized) { $unrecognized = implode("\n ", $unrecognized); cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); } if ($options['help'] or !$options['list'] and !$options['execute']) { $help = "Scheduled cron tasks.\n\nOptions:\n--execute=\\\\some\\\\task Execute scheduled task manually\n--list List all scheduled tasks\n-h, --help Print out this help\n\nExample:\n\$sudo -u www-data /usr/bin/php admin/tool/task/cli/scheduled_task.php --execute=\\\\core\\\\task\\\\session_cleanup_task\n\n"; echo $help; die; } if ($options['list']) { cli_heading("List of scheduled tasks ({$CFG->wwwroot})"); $shorttime = get_string('strftimedatetimeshort'); $tasks = \core\task\manager::get_all_scheduled_tasks(); foreach ($tasks as $task) { $class = '\\' . get_class($task); $schedule = $task->get_minute() . ' ' . $task->get_hour() . ' ' . $task->get_day() . ' ' . $task->get_day_of_week() . ' ' . $task->get_month() . ' ' . $task->get_day_of_week(); $nextrun = $task->get_next_run_time(); $plugininfo = core_plugin_manager::instance()->get_plugin_info($task->get_component()); $plugindisabled = $plugininfo && $plugininfo->is_enabled() === false && !$task->get_run_if_component_disabled(); if ($plugindisabled) { $nextrun = get_string('plugindisabled', 'tool_task'); } else { if ($task->get_disabled()) { $nextrun = get_string('taskdisabled', 'tool_task'); } else { if ($nextrun > time()) { $nextrun = userdate($nextrun); } else {