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