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;
    }
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;
    }
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 ; }
Executes a cron from web invocation using PHP CLI.

@param \core\task\task_base $task Task that be executed via CLI.
@return bool
@throws \moodle_exception
Executes a cron from web invocation using PHP CLI .