Execute back up manually.

@param string $task
@return \Illuminate\Http\JsonResponse
189594
public function backup($task = 'run')
    {
        if (! in_array($task, ['run', 'clean'])) {
            $message = trans('cms::utilities.backup.not_allowed',
                    ['task' => $task]) . trans('cms::utilities.field.executed_by',
                    ['name' => $this->getCurrentUserName()]);
            $this->log->info($message);

            return $this->notifyError($message);
        }

        Artisan::call('backup:' . $task);
        $message = $task == 'clean' ? trans('cms::utilities.backup.cleanup_complete') : trans('cms::utilities.backup.complete');
        $this->log->info($message . trans('cms::utilities.field.executed_by', ['name' => $this->getCurrentUserName()]));

        return $this->notifySuccess($message);
    }
948912
private static function get_root_backup_information($task) {

        // Now get root settings
        $settingsinfo = array();
        foreach ($task->get_settings() as $setting) {
            // Validate level is correct (root)
            if ($setting->get_level() != backup_setting::ROOT_LEVEL) {
                throw new backup_controller_exception('setting_not_root_level', $setting);
            }
            $settinginfo = array(
                'level'    => 'root',
                'name'     => $setting->get_name(),
                'value'    => $setting->get_value());
            $settingsinfo[$setting->get_name()] = (object)$settinginfo;
        }
        return array(null, $settingsinfo);
    }
796904
protected function _run(array $task) {
		$this->ProcessManager->fork(function () use ($task) {
			$this->_makeRunner($task)->start();
		});
	}
1266124
public function restore_instance_data_from_backup(\restore_task $task, array $data) {
        $courseid = $task->get_courseid();
        $context = $this->get_instance_context($courseid);
        $editablefields = $this->get_editable_fields($courseid);
        $records = api::get_instance_fields_data($editablefields, $courseid);
        $target = $task->get_target();
        $override = ($target != \backup::TARGET_CURRENT_ADDING && $target != \backup::TARGET_EXISTING_ADDING);

        foreach ($records as $d) {
            $field = $d->get_field();
            if ($field->get('shortname') === $data['shortname'] && $field->get('type') === $data['type']) {
                if (!$d->get('id') || $override) {
                    $d->set($d->datafield(), $data['value']);
                    $d->set('value', $data['value']);
                    $d->set('valueformat', $data['valueformat']);
                    $d->set('contextid', $context->id);
                    $d->save();
                }
                return;
            }
        }
    }
456039
public function execute(\Stackable $task) {
        if (!$this->isStarted) {
            $this->start();
        }

        if ($this->maxTaskQueueSize < 0 || $this->maxTaskQueueSize > $this->outstandingTaskCount) {
            return $this->acceptNewTask($task);
        } else {
            return new Failure(new TooBusyException(
                sprintf('Cannot execute task of type %s; too busy', get_class($task))
            ));
        }
    }
984219
public function buildTaskFromClass($task)
    {
        if (is_object($task) && $task instanceof AbstractTask) {
            return $task;
        }

        // Cancel if class doesn't exist
        if (!$class = $this->taskClassExists($task)) {
            throw new TaskCompositionException($task);
        }

        // Build class
        $class = new $class();
        if ($class instanceof ContainerAwareInterface) {
            $class->setContainer($this->container);
        }

        return $class;
    }
1000888
public static function createProcess($task): Runnable
    {
        if (! self::$isInitialised) {
            self::init();
        }

        if (! Pool::isSupported()) {
            return SynchronousProcess::create($task, self::getId());
        }

        $process = new Process(implode(' ', [
            'exec php',
            self::$childProcessScript,
            self::$autoloader,
            self::encodeTask($task),
        ]));

        return ParallelProcess::create($process, self::getId());
    }
514414
public function resetCrashes(Task $task)
    {
        $task->setCrashed(0);

        $this->om->persist($task);
        $this->om->flush();

        $this->notify(NotifierInterface::MESSAGE_UPDATE);

        return $task;
    }
981319
public function confirmTaskWithUser($task, $question)
    {
        $question = $question === true ? 'Are you sure you want to run the ['.$task.'] task?' : (string) $question;

        $question = '<comment>'.$question.' [y/N]:</comment> ';

        $question = new ConfirmationQuestion($question, false);

        return $this->getHelperSet()->get('question')->ask($this->input, $this->output, $question);
    }
1242504
private static function get_activity_backup_information($task) {

        $contentinfo = array(
            'moduleid'   => $task->get_moduleid(),
            'sectionid'  => $task->get_sectionid(),
            'modulename' => $task->get_modulename(),
            'title'      => $task->get_name(),
            'directory'  => 'activities/' . $task->get_modulename() . '_' . $task->get_moduleid());

        // Now get activity settings
        // Calculate prefix to find valid settings
        $prefix = basename($contentinfo['directory']);
        $settingsinfo = array();
        foreach ($task->get_settings() as $setting) {
            // Discard ones without valid prefix
            if (strpos($setting->get_name(), $prefix) !== 0) {
                continue;
            }
            // Validate level is correct (activity)
            if ($setting->get_level() != backup_setting::ACTIVITY_LEVEL) {
                throw new backup_controller_exception('setting_not_activity_level', $setting);
            }
            $settinginfo = array(
                'level'    => 'activity',
                'activity' => $prefix,
                'name'     => $setting->get_name(),
                'value'    => $setting->get_value());
            $settingsinfo[$setting->get_name()] = (object)$settinginfo;
        }
        return array($contentinfo, $settingsinfo);
    }
668912
public function addTask($task) {
        $redis = Cache::redis();
        $task_id = md5('gg' . $redis->incr('swoole_task_incr') . 'df');
        $redis->hSet(self::TIMER_QUEUE, $task_id, json_encode($task));
        $after = $task[ 'time' ] - time();
        $after = $after * 1000;
        if ($after <= 0) {
            $after = 1000;
        }
        //定时时间大于一天的
        if ($after > 86400000) {
            $redis->hSet(self::SWOOLE_TASK_WAIT, $task_id, json_encode($task));
        } else {
            $this->addTaskToQueue($after, $task_id);
        }
        return $task_id;
    }
1046304
protected function cache($task, $data = null)
    {
        $config = array_merge($this->cache, $task['cache']);
        if (! $config['enable']) {
            return null;
        }
        if (! isset($config['dir'])) {
            user_error('cache dir is not defined', E_USER_WARNING);
            return null;
        }
        $url = $task['opt'][CURLOPT_URL];
        $post = null;
        if (true == $config['verifyPost'] && ! empty($task['opt'][CURLOPT_POSTFIELDS])) {
            $post = $task['opt'][CURLOPT_POSTFIELDS];
        }
        $file = rtrim($config['dir'], '/') . '/';
        $file .= $this->getCacheFile($url, $post);
        if (! isset($data)) {
            if (file_exists($file)) {
                $time = time();
                $mtime = filemtime($file);
                if ($time - $mtime < $config['expire']) {
                    return unserialize(gzuncompress(file_get_contents($file)));
                }
            }
        } else {
            if (! isset($data['cache'])) {
                $data['cache'] = array();
            }
            $data['cacheFile'] = $file;
            unset($data['curl']);
            $dir = dirname($file);
            $dir1 = dirname($dir);
            if (! is_dir($dir1)) {
                mkdir($dir1);
            }
            if (! is_dir($dir)) {
                mkdir($dir);
            }
            // Cache response from downloaded file.
            if (isset($task['fileMeta']['uri'])) {
                $data['body'] = file_get_contents($task['fileMeta']['uri']);
            }
            file_put_contents($file, gzcompress(serialize($data), $config['compress']), LOCK_EX);
        }
        return null;
    }
485870
public function updateTask(AbstractTask $task) {        
        try{
            Database::prepare(
                'UPDATE `##maj_admintasks`'.
                ' SET majat_status = :status,'.
                ' majat_last_run = :last_run,'.
                ' majat_last_result = :last_result,'.
                ' majat_frequency = :frequency,'.
                ' majat_nb_occur = :nb_occurrences,'.
                ' majat_running = :is_running'.
                ' WHERE majat_name = :name'
                )->execute(array(
                    'name' => $task->getName(),
                    'status' => $task->isEnabled() ? 'enabled' : 'disabled',
                    'last_run' => $task->getLastUpdated()->format('Y-m-d H:i:s'),
                    'last_result' =>  $task->isLastRunSuccess() ? 1 : 0,
                    'frequency' => $task->getFrequency(),
                    'nb_occurrences' => $task->getRemainingOccurrences(),
                    'is_running' => $task->isRunning() ? 1 : 0
                ));
            return true;
        }
        catch (\Exception $ex) {
            Log::addErrorLog(sprintf('Error while updating the Admin Task %s. Exception: %s', $task->getName(), $ex->getMessage()));
            return false;
        }        
    }
1013704
public function does($task)
    {
        // Store the original task before transformation
        $this->setStringTask($task);

        // Wrap string tasks
        if (is_string($task) || is_array($task)) {
            $task = $this->builder->wrapStringTasks($task);
        }

        $this->setClosure($task);

        return $this;
    }
133327
protected function runTask($container, $task)
    {
        $macroOptions = $container->getMacroOptions($this->argument('task'));

        $confirm = $container->getTask($task, $macroOptions)->confirm;

        if ($confirm && ! $this->confirmTaskWithUser($task, $confirm)) {
            return;
        }

        if (($exitCode = $this->runTaskOverSSH($container->getTask($task, $macroOptions))) > 0) {
            foreach ($container->getErrorCallbacks() as $callback) {
                call_user_func($callback, $task);
            }

            return $exitCode;
        }

        foreach ($container->getAfterCallbacks() as $callback) {
            call_user_func($callback, $task);
        }
    }
769423
public function action($action, $task = null)
    {
        return $this->app->make(ResolverManagerInterface::class)->resolve(func_get_args());
    }
177933
public function insertTask($task): Google_Service_Tasks
    {
        if ($task instanceof Tasks) {
            $task = $task->googleTasks;
        }

        return $this->service->tasks->insert($this->tasklist, $task);
    }