Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Queue / DebugCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Queue\DebugCommand.
6  */
7
8 namespace Drupal\Console\Command\Queue;
9
10 use Symfony\Component\Console\Command\Command;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Drupal\Core\Queue\QueueWorkerManagerInterface;
14 use Drupal\Console\Core\Command\Shared\CommandTrait;
15 use Drupal\Console\Core\Style\DrupalStyle;
16
17 /**
18  * Class DebugCommand
19  *
20  * @package Drupal\Console\Command\Queue
21  */
22 class DebugCommand extends Command
23 {
24     use CommandTrait;
25
26     /**
27      * @var QueueWorkerManagerInterface
28      */
29     protected $queueWorker;
30
31     /**
32      * DebugCommand constructor.
33      *
34      * @param QueueWorkerManagerInterface $queueWorker
35      */
36     public function __construct(QueueWorkerManagerInterface $queueWorker)
37     {
38         $this->queueWorker = $queueWorker;
39         parent::__construct();
40     }
41
42     /**
43      * {@inheritdoc}
44      */
45     protected function configure()
46     {
47         $this
48             ->setName('queue:debug')
49             ->setDescription($this->trans('commands.queue.debug.description'));
50     }
51
52     /**
53      * {@inheritdoc}
54      */
55     protected function execute(InputInterface $input, OutputInterface $output)
56     {
57         $io = new DrupalStyle($input, $output);
58
59         $tableHeader = [
60             $this->trans('commands.queue.debug.messages.queue'),
61             $this->trans('commands.queue.debug.messages.items'),
62             $this->trans('commands.queue.debug.messages.class')
63         ];
64
65         $tableBody = $this->listQueues();
66
67         $io->table($tableHeader, $tableBody);
68
69         return 0;
70     }
71
72     /**
73      * listQueues.
74      */
75     private function listQueues()
76     {
77         $queues = [];
78         foreach ($this->queueWorker->getDefinitions() as $name => $info) {
79             $queues[$name] = $this->formatQueue($name);
80         }
81
82         return $queues;
83     }
84
85     /**
86      * @param $name
87      * @return array
88      */
89     private function formatQueue($name)
90     {
91         $q = $this->getDrupalService('queue')->get($name);
92
93         return [
94             $name,
95             $q->numberOfItems(),
96             get_class($q)
97         ];
98     }
99 }