2 namespace Drush\Drupal\Commands\core;
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;
10 use Drush\Utils\StringUtils;
11 use Symfony\Component\Finder\Finder;
12 use Webmozart\PathUtil\Path;
14 class DrupalCommands extends DrushCommands
18 * @var \Drupal\Core\CronInterface
23 * @var \Drupal\Core\Extension\ModuleHandlerInterface
25 protected $moduleHandler;
28 * @return \Drupal\Core\CronInterface
30 public function getCron()
36 * @return \Drupal\Core\Extension\ModuleHandlerInterface
38 public function getModuleHandler()
40 return $this->moduleHandler;
44 * @param \Drupal\Core\CronInterface $cron
45 * @param ModuleHandlerInterface $moduleHandler
47 public function __construct(CronInterface $cron, ModuleHandlerInterface $moduleHandler)
50 $this->moduleHandler = $moduleHandler;
54 * Run all cron hooks in all active modules for specified site.
57 * @aliases cron,core-cron
60 public function cron()
62 $result = $this->getCron()->run();
64 throw new \Exception(dt('Cron run failed.'));
69 * Information about things that may be wrong in your Drupal installation.
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
84 * description: Description
86 * @default-fields title,severity,value
87 * @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields
89 public function requirements($options = ['format' => 'table', 'severity' => -1, 'ignore' => ''])
91 include_once DRUSH_DRUPAL_CORE . '/includes/install.inc';
93 REQUIREMENT_INFO => dt('Info'),
94 REQUIREMENT_OK => dt('OK'),
95 REQUIREMENT_WARNING => dt('Warning'),
96 REQUIREMENT_ERROR => dt('Error'),
99 drupal_load_updates();
101 $requirements = $this->getModuleHandler()->invokeAll('requirements', ['runtime']);
102 // If a module uses "$requirements[] = " instead of
103 // "$requirements['label'] = ", then build a label from
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;
112 $ignore_requirements = StringUtils::csvToArray($options['ignore']);
113 foreach ($ignore_requirements as $ignore) {
114 unset($requirements[$ignore]);
116 ksort($requirements);
118 $min_severity = $options['severity'];
120 foreach ($requirements as $key => $info) {
121 $severity = array_key_exists('severity', $info) ? $info['severity'] : -1;
123 'title' => (string) $info['title'],
124 'value' => (string) $info['value'],
125 'description' => DrupalUtil::drushRender($info['description']),
127 'severity' => @$severities[$severity]
129 if ($severity < $min_severity) {
134 $result = new RowsOfFields($rows);