Yaffs site version 1.1
[yaffs-website] / vendor / drupal / console / src / Command / Update / DebugCommand.php
1 <?php
2
3 /**
4  * @file
5  * Contains \Drupal\Console\Command\Update\DebugCommand.
6  */
7
8 namespace Drupal\Console\Command\Update;
9
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Output\OutputInterface;
12 use Symfony\Component\Console\Command\Command;
13 use Drupal\Core\Update\UpdateRegistry;
14 use Drupal\Console\Core\Command\Shared\CommandTrait;
15 use Drupal\Console\Utils\Site;
16 use Drupal\Console\Core\Style\DrupalStyle;
17
18 class DebugCommand extends Command
19 {
20     use CommandTrait;
21
22     /**
23      * @var Site
24      */
25     protected $site;
26
27     /**
28      * @var UpdateRegistry
29      */
30     protected $postUpdateRegistry;
31
32     /**
33      * DebugCommand constructor.
34      *
35      * @param Site           $site
36      * @param UpdateRegistry $postUpdateRegistry
37      */
38     public function __construct(
39         Site $site,
40         UpdateRegistry $postUpdateRegistry
41     ) {
42         $this->site = $site;
43         $this->postUpdateRegistry = $postUpdateRegistry;
44         parent::__construct();
45     }
46
47     /**
48      * @inheritdoc
49      */
50     protected function configure()
51     {
52         $this
53             ->setName('update:debug')
54             ->setDescription($this->trans('commands.update.debug.description'));
55     }
56
57     /**
58      * @inheritdoc
59      */
60     protected function execute(InputInterface $input, OutputInterface $output)
61     {
62         $io = new DrupalStyle($input, $output);
63
64         $this->site->loadLegacyFile('/core/includes/update.inc');
65         $this->site->loadLegacyFile('/core/includes/install.inc');
66
67         drupal_load_updates();
68         update_fix_compatibility();
69
70         $requirements = update_check_requirements();
71         $severity = drupal_requirements_severity($requirements);
72         $updates = update_get_update_list();
73
74         $io->newLine();
75
76         if ($severity == REQUIREMENT_ERROR || ($severity == REQUIREMENT_WARNING)) {
77             $this->populateRequirements($io, $requirements);
78         } elseif (empty($updates)) {
79             $io->info($this->trans('commands.update.debug.messages.no-updates'));
80         } else {
81             $this->populateUpdate($io, $updates);
82             $this->populatePostUpdate($io);
83         }
84     }
85
86     /**
87      * @param \Drupal\Console\Core\Style\DrupalStyle $io
88      * @param $requirements
89      */
90     private function populateRequirements(DrupalStyle $io, $requirements)
91     {
92         $io->info($this->trans('commands.update.debug.messages.requirements-error'));
93
94         $tableHeader = [
95           $this->trans('commands.update.debug.messages.severity'),
96           $this->trans('commands.update.debug.messages.title'),
97           $this->trans('commands.update.debug.messages.value'),
98           $this->trans('commands.update.debug.messages.description'),
99         ];
100
101         $tableRows = [];
102         foreach ($requirements as $requirement) {
103             $minimum = in_array(
104                 $requirement['minimum schema'],
105                 [REQUIREMENT_ERROR, REQUIREMENT_WARNING]
106             );
107             if ((isset($requirement['minimum schema'])) && ($minimum)) {
108                 $tableRows[] = [
109                   $requirement['severity'],
110                   $requirement['title'],
111                   $requirement['value'],
112                   $requirement['description'],
113                 ];
114             }
115         }
116
117         $io->table($tableHeader, $tableRows);
118     }
119
120     /**
121      * @param \Drupal\Console\Core\Style\DrupalStyle $io
122      * @param $updates
123      */
124     private function populateUpdate(DrupalStyle $io, $updates)
125     {
126         $io->info($this->trans('commands.update.debug.messages.module-list'));
127         $tableHeader = [
128           $this->trans('commands.update.debug.messages.module'),
129           $this->trans('commands.update.debug.messages.update-n'),
130           $this->trans('commands.update.debug.messages.description')
131         ];
132         $tableRows = [];
133         foreach ($updates as $module => $module_updates) {
134             foreach ($module_updates['pending'] as $update_n => $update) {
135                 list(, $description) = explode($update_n . " - ", $update);
136                 $tableRows[] = [
137                   $module,
138                   $update_n,
139                   trim($description),
140                 ];
141             }
142         }
143         $io->table($tableHeader, $tableRows);
144     }
145
146     /**
147      * @param \Drupal\Console\Core\Style\DrupalStyle $io
148      */
149     private function populatePostUpdate(DrupalStyle $io)
150     {
151         $io->info(
152             $this->trans('commands.update.debug.messages.module-list-post-update')
153         );
154         $tableHeader = [
155           $this->trans('commands.update.debug.messages.module'),
156           $this->trans('commands.update.debug.messages.post-update'),
157           $this->trans('commands.update.debug.messages.description')
158         ];
159
160         $postUpdates = $this->postUpdateRegistry->getPendingUpdateInformation();
161         $tableRows = [];
162         foreach ($postUpdates as $module => $module_updates) {
163             foreach ($module_updates['pending'] as $postUpdateFunction => $message) {
164                 $tableRows[] = [
165                   $module,
166                   $postUpdateFunction,
167                   $message,
168                 ];
169             }
170         }
171         $io->table($tableHeader, $tableRows);
172     }
173 }