MDL-63580 core_task: Deprecation cron_run_single_task and run_from_cli

Also we have move the functions in \tool_task\run_from_cli to \core\task\manager
and we have deprecated that class.
This commit is contained in:
cescobedo
2020-05-11 10:53:23 +02:00
parent 079736ccb3
commit db15746c2d
7 changed files with 90 additions and 112 deletions
+9 -26
View File
@@ -17,6 +17,9 @@
/**
* Form for scheduled tasks admin pages.
*
* @deprecated since Moodle 3.9 MDL-63580. Please use the \core\task\manager.
* @todo final deprecation. To be removed in Moodle 4.3 MDL-63594.
*
* @package tool_task
* @copyright 2018 Toni Barbera <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
@@ -55,7 +58,9 @@ class run_from_cli {
* @return bool
*/
public static function is_runnable():bool {
return self::find_php_cli_path() !== false;
debugging('run_from_cli class is deprecated. Please use \core\task\manager::run_from_cli() instead.',
DEBUG_DEVELOPER);
return \core\task\manager::is_runnable();
}
/**
@@ -66,30 +71,8 @@ class run_from_cli {
* @throws \moodle_exception
*/
public static function execute(\core\task\task_base $task):bool {
global $CFG;
if (!self::is_runnable()) {
$redirecturl = new \moodle_url('/admin/settings.php', ['section' => 'systempaths']);
throw new \moodle_exception('cannotfindthepathtothecli', 'tool_task', $redirecturl->out());
} else {
// Shell-escaped path to the PHP binary.
$phpbinary = escapeshellarg(self::find_php_cli_path());
// Shell-escaped path CLI script.
$pathcomponents = [$CFG->dirroot, $CFG->admin, 'tool', 'task', 'cli', 'schedule_task.php'];
$scriptpath = escapeshellarg(implode(DIRECTORY_SEPARATOR, $pathcomponents));
// Shell-escaped task name.
$classname = get_class($task);
$taskarg = escapeshellarg("--execute={$classname}");
// Build the CLI command.
$command = "{$phpbinary} {$scriptpath} {$taskarg}";
// Execute it.
passthru($command);
}
return true;
debugging('run_from_cli class is deprecated. Please use \core\task\manager::run_from_cli() instead.',
DEBUG_DEVELOPER);
return \core\task\manager::run_from_cli($task);
}
}