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