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
46 public function __construct(CronInterface $cron, ModuleHandlerInterface $moduleHandler)
49 $this->moduleHandler = $moduleHandler;
53 * Run all cron hooks in all active modules for specified site.
56 * @aliases cron,core-cron
59 public function cron()
61 $result = $this->getCron()->run();
63 throw new \Exception(dt('Cron run failed.'));
68 * Compile all Twig template(s).
70 * @command twig:compile
71 * @aliases twigc,twig-compile
73 public function twigCompile()
75 require_once DRUSH_DRUPAL_CORE . "/themes/engines/twig/twig.engine";
76 // Scan all enabled modules and themes.
77 $modules = array_keys($this->getModuleHandler()->getModuleList());
78 foreach ($modules as $module) {
79 $searchpaths[] = drupal_get_path('module', $module);
82 $themes = \Drupal::service('theme_handler')->listInfo();
83 foreach ($themes as $name => $theme) {
84 $searchpaths[] = $theme->getPath();
87 $files = Finder::create()
92 foreach ($files as $file) {
93 $relative = Path::makeRelative($file->getRealPath(), Drush::bootstrapManager()->getRoot());
94 // @todo Dynamically disable twig debugging since there is no good info there anyway.
95 twig_render_template($relative, ['theme_hook_original' => '']);
96 $this->logger()->success(dt('Compiled twig template !path', ['!path' => $relative]));
101 * Information about things that may be wrong in your Drupal installation.
103 * @command core:requirements
104 * @option severity Only show status report messages with a severity greater than or equal to the specified value.
105 * @option ignore Comma-separated list of requirements to remove from output. Run with --format=yaml to see key values to use.
106 * @aliases status-report,rq,core-requirements
107 * @usage drush core:requirements
108 * Show all status lines from the Status Report admin page.
109 * @usage drush core:requirements --severity=2
110 * Show only the red lines from the Status Report admin page.
111 * @table-style default
116 * description: Description
118 * @default-fields title,severity,value
119 * @return \Consolidation\OutputFormatters\StructuredData\RowsOfFields
121 public function requirements($options = ['format' => 'table', 'severity' => -1, 'ignore' => ''])
123 include_once DRUSH_DRUPAL_CORE . '/includes/install.inc';
125 REQUIREMENT_INFO => dt('Info'),
126 REQUIREMENT_OK => dt('OK'),
127 REQUIREMENT_WARNING => dt('Warning'),
128 REQUIREMENT_ERROR => dt('Error'),
131 drupal_load_updates();
133 $requirements = $this->getModuleHandler()->invokeAll('requirements', ['runtime']);
134 // If a module uses "$requirements[] = " instead of
135 // "$requirements['label'] = ", then build a label from
137 foreach ($requirements as $key => $info) {
138 if (is_numeric($key)) {
139 unset($requirements[$key]);
140 $new_key = strtolower(str_replace(' ', '_', $info['title']));
141 $requirements[$new_key] = $info;
144 $ignore_requirements = StringUtils::csvToArray($options['ignore']);
145 foreach ($ignore_requirements as $ignore) {
146 unset($requirements[$ignore]);
148 ksort($requirements);
150 $min_severity = $options['severity'];
152 foreach ($requirements as $key => $info) {
153 $severity = array_key_exists('severity', $info) ? $info['severity'] : -1;
155 'title' => (string) $info['title'],
156 'value' => (string) $info['value'],
157 'description' => DrupalUtil::drushRender($info['description']),
159 'severity' => @$severities[$severity]
161 if ($severity < $min_severity) {
166 $result = new RowsOfFields($rows);