Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
cron_list
100.00% covered (success)
100.00%
23 / 23
100.00% covered (success)
100.00%
3 / 3
8
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 configure
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 execute
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
1 / 1
6
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13namespace phpbb\console\command\cron;
14
15use Symfony\Component\Console\Command\Command as symfony_command;
16use Symfony\Component\Console\Input\InputInterface;
17use Symfony\Component\Console\Output\OutputInterface;
18use Symfony\Component\Console\Style\SymfonyStyle;
19
20class cron_list extends \phpbb\console\command\command
21{
22    /** @var \phpbb\cron\manager */
23    protected $cron_manager;
24
25    /**
26    * Constructor
27    *
28    * @param \phpbb\user            $user            User instance
29    * @param \phpbb\cron\manager    $cron_manager    Cron manager
30    */
31    public function __construct(\phpbb\user $user, \phpbb\cron\manager $cron_manager)
32    {
33        $this->cron_manager = $cron_manager;
34        parent::__construct($user);
35    }
36
37    /**
38    * {@inheritdoc}
39    */
40    protected function configure()
41    {
42        $this
43            ->setName('cron:list')
44            ->setDescription($this->user->lang('CLI_DESCRIPTION_CRON_LIST'))
45        ;
46    }
47
48    /**
49    * Executes the command cron:list.
50    *
51    * Prints a list of ready and unready cron jobs.
52    *
53    * @param InputInterface  $input  An InputInterface instance
54    * @param OutputInterface $output An OutputInterface instance
55    *
56    * @return int
57    */
58    protected function execute(InputInterface $input, OutputInterface $output)
59    {
60        $io = new SymfonyStyle($input, $output);
61
62        $tasks = $this->cron_manager->get_tasks();
63
64        if (empty($tasks))
65        {
66            $io->error($this->user->lang('CRON_NO_TASKS'));
67            return symfony_command::FAILURE;
68        }
69
70        $ready_tasks = $not_ready_tasks = array();
71        foreach ($tasks as $task)
72        {
73            if ($task->is_ready())
74            {
75                $ready_tasks[] = $task->get_name();
76            }
77            else
78            {
79                $not_ready_tasks[] = $task->get_name();
80            }
81        }
82
83        if (!empty($ready_tasks))
84        {
85            $io->title($this->user->lang('TASKS_READY'));
86            $io->listing($ready_tasks);
87        }
88
89        if (!empty($not_ready_tasks))
90        {
91            $io->title($this->user->lang('TASKS_NOT_READY'));
92            $io->listing($not_ready_tasks);
93        }
94
95        return symfony_command::SUCCESS;
96    }
97}