5 * Contains \Drupal\Console\Command\Cron\ExecuteCommand.
8 namespace Drupal\Console\Command\Cron;
10 use Symfony\Component\Console\Input\InputArgument;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Core\Extension\ModuleHandlerInterface;
15 use Drupal\Core\Lock\LockBackendInterface;
16 use Drupal\Core\State\StateInterface;
17 use Drupal\Console\Core\Command\Shared\CommandTrait;
18 use Drupal\Console\Core\Style\DrupalStyle;
19 use Drupal\Console\Core\Utils\ChainQueue;
21 class ExecuteCommand extends Command
26 * @var ModuleHandlerInterface
28 protected $moduleHandler;
31 * @var LockBackendInterface
43 protected $chainQueue;
46 * DebugCommand constructor.
48 * @param ModuleHandlerInterface $moduleHandler
49 * @param LockBackendInterface $lock
50 * @param StateInterface $state
51 * @param ChainQueue $chainQueue
53 public function __construct(
54 ModuleHandlerInterface $moduleHandler,
55 LockBackendInterface $lock,
56 StateInterface $state,
57 ChainQueue $chainQueue
59 $this->moduleHandler = $moduleHandler;
61 $this->state = $state;
62 $this->chainQueue = $chainQueue;
63 parent::__construct();
69 protected function configure()
72 ->setName('cron:execute')
73 ->setDescription($this->trans('commands.cron.execute.description'))
76 InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
77 $this->trans('commands.common.options.module')
84 protected function execute(InputInterface $input, OutputInterface $output)
86 $io = new DrupalStyle($input, $output);
87 $modules = $input->getArgument('module');
89 if (!$this->lock->acquire('cron', 900.0)) {
90 $io->warning($this->trans('commands.cron.execute.messages.lock'));
95 if ($modules === null || in_array('all', $modules)) {
96 $modules = $this->moduleHandler->getImplementations('cron');
99 foreach ($modules as $module) {
100 if (!$this->moduleHandler->implementsHook($module, 'cron')) {
103 $this->trans('commands.cron.execute.messages.module-invalid'),
112 $this->trans('commands.cron.execute.messages.executing-cron'),
116 $this->moduleHandler->invoke($module, 'cron');
117 } catch (\Exception $e) {
118 watchdog_exception('cron', $e);
119 $io->error($e->getMessage());
123 $this->state->set('system.cron_last', REQUEST_TIME);
124 $this->lock->release('cron');
126 $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']);
128 $io->success($this->trans('commands.cron.execute.messages.success'));