Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RunScheduledTasks.php « Commands « CoreAdminHome « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3cccb94339939b8e134a8bcacc32c40abcf4ae18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 */

namespace Piwik\Plugins\CoreAdminHome\Commands;

use Piwik\FrontController;
use Piwik\Plugin\ConsoleCommand;
use Piwik\Plugins\CoreAdminHome\API;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

class RunScheduledTasks extends ConsoleCommand
{
    protected function configure()
    {
        $this->setName('core:run-scheduled-tasks');
        $this->setDescription('Will run all scheduled tasks due to run at this time.');
        $this->addOption('force', null, InputOption::VALUE_NONE, 'If set, it will execute all tasks even the ones not due to run at this time.');
    }

    /**
     * Execute command like: ./console core:run-scheduled-tasks
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->forceRunAllTasksIfRequested($input);

        FrontController::getInstance()->init();
        $scheduledTasksResults = API::getInstance()->runScheduledTasks();

        foreach ($scheduledTasksResults as $scheduledTasksResult) {
            $output->writeln(sprintf(
                '<comment>%s</comment> - %s',
                $scheduledTasksResult['task'],
                $scheduledTasksResult['output']
            ));
        }

        $this->writeSuccessMessage($output, array('Scheduled Tasks executed'));
    }

    private function forceRunAllTasksIfRequested(InputInterface $input)
    {
        $force = $input->getOption('force');

        if ($force) {
            define('DEBUG_FORCE_SCHEDULED_TASKS', true);
        }
    }
}