8d0c98afa33db689fb1c9bad296ccd7b088dbd61
[yaffs-website] / vendor / drush / drush / src / Drupal / Commands / core / DrupalCommands.php
1 <?php
2 namespace Drush\Drupal\Commands\core;
3
4 use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
5 use Drupal\Core\CronInterface;
6 use Drupal\Core\Extension\ModuleHandlerInterface;
7 use Drush\Commands\DrushCommands;
8 use Drush\Drupal\DrupalUtil;
9 use Drush\Drush;
10 use Drush\Utils\StringUtils;
11 use Symfony\Component\Finder\Finder;
12 use Webmozart\PathUtil\Path;
13
14 class DrupalCommands extends DrushCommands
15 {
16
17     /**
18      * @var \Drupal\Core\CronInterface
19      */
20     protected $cron;
21
22     /**
23      * @var \Drupal\Core\Extension\ModuleHandlerInterface
24      */
25     protected $moduleHandler;
26
27     /**
28      * @return \Drupal\Core\CronInterface
29      */
30     public function getCron()
31     {
32         return $this->cron;
33     }
34
35     /**
36      * @return \Drupal\Core\Extension\ModuleHandlerInterface
37      */
38     public function getModuleHandler()
39     {
40         return $this->moduleHandler;
41     }
42
43     /**
44      * @param \Drupal\Core\CronInterface $cron
45      * @param ModuleHandlerInterface $moduleHandler
46      */
47     public function __construct(CronInterface $cron, ModuleHandlerInterface $moduleHandler)
48     {
49         $this->cron = $cron;
50         $this->moduleHandler = $moduleHandler;
51     }
52
53     /**
54      * Run all cron hooks in all active modules for specified site.
55      *
56      * @command core:cron
57      * @aliases cron,core-cron
58      * @topics docs:cron
59      */
60     public function cron()
61     {
62         $result = $this->getCron()->run();
63         if (!$result) {
64             throw new \Exception(dt('Cron run failed.'));
65         }
66     }
67
68     /**
69      * Information about things that may be wrong in your Drupal installation.
70      *
71      * @command core:requirements
72      * @option severity Only show status report messages with a severity greater than or equal to the specified value.
73      * @option ignore Comma-separated list of requirements to remove from output. Run with --format=yaml to see key values to use.
74      * @aliases status-report,rq,core-requirements
75      * @usage drush core:requirements
76      *   Show all status lines from the Status Report admin page.
77      * @usage drush core:requirements --severity=2
78      *   Show only the red lines from the Status Report admin page.
79      * @table-style default
80      * @field-labels
81      *   title: Title
82      *   severity: Severity
83      *   sid: SID
84      *   description: Description
85      *   value: Summary
86      * @default-fields title,severity,value
87      * @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields
88      */
89     public function requirements($options = ['format' => 'table', 'severity' => -1, 'ignore' => ''])
90     {
91         include_once DRUSH_DRUPAL_CORE . '/includes/install.inc';
92         $severities = [
93             REQUIREMENT_INFO => dt('Info'),
94             REQUIREMENT_OK => dt('OK'),
95             REQUIREMENT_WARNING => dt('Warning'),
96             REQUIREMENT_ERROR => dt('Error'),
97         ];
98
99         drupal_load_updates();
100
101         $requirements = $this->getModuleHandler()->invokeAll('requirements', ['runtime']);
102         // If a module uses "$requirements[] = " instead of
103         // "$requirements['label'] = ", then build a label from
104         // the title.
105         foreach ($requirements as $key => $info) {
106             if (is_numeric($key)) {
107                 unset($requirements[$key]);
108                 $new_key = strtolower(str_replace(' ', '_', $info['title']));
109                 $requirements[$new_key] = $info;
110             }
111         }
112         $ignore_requirements = StringUtils::csvToArray($options['ignore']);
113         foreach ($ignore_requirements as $ignore) {
114             unset($requirements[$ignore]);
115         }
116         ksort($requirements);
117
118         $min_severity = $options['severity'];
119         $i = 0;
120         foreach ($requirements as $key => $info) {
121             $severity = array_key_exists('severity', $info) ? $info['severity'] : -1;
122             $rows[$i] = [
123                 'title' => (string) $info['title'],
124                 'value' => (string) $info['value'],
125                 'description' => DrupalUtil::drushRender($info['description']),
126                 'sid' => $severity,
127                 'severity' => @$severities[$severity]
128             ];
129             if ($severity < $min_severity) {
130                 unset($rows[$i]);
131             }
132             $i++;
133         }
134         $result = new RowsOfFields($rows);
135         return $result;
136     }
137 }