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 Drupal\Console\Core\Command\Command;
14 use Drupal\Core\Extension\ModuleHandlerInterface;
15 use Drupal\Core\Lock\LockBackendInterface;
16 use Drupal\Core\State\StateInterface;
18 class ExecuteCommand extends Command
21 * @var ModuleHandlerInterface
23 protected $moduleHandler;
26 * @var LockBackendInterface
36 * DebugCommand constructor.
38 * @param ModuleHandlerInterface $moduleHandler
39 * @param LockBackendInterface $lock
40 * @param StateInterface $state
42 public function __construct(
43 ModuleHandlerInterface $moduleHandler,
44 LockBackendInterface $lock,
47 $this->moduleHandler = $moduleHandler;
49 $this->state = $state;
50 parent::__construct();
56 protected function configure()
59 ->setName('cron:execute')
60 ->setDescription($this->trans('commands.cron.execute.description'))
63 InputArgument::IS_ARRAY | InputArgument::OPTIONAL,
64 $this->trans('commands.common.options.module')
66 ->setAliases(['croe']);
72 protected function execute(InputInterface $input, OutputInterface $output)
74 $modules = $input->getArgument('module');
76 if (!$this->lock->acquire('cron', 900.0)) {
77 $this->getIo()->warning($this->trans('commands.cron.execute.messages.lock'));
82 if ($modules === null || in_array('all', $modules)) {
83 $modules = $this->moduleHandler->getImplementations('cron');
86 foreach ($modules as $module) {
87 if (!$this->moduleHandler->implementsHook($module, 'cron')) {
88 $this->getIo()->warning(
90 $this->trans('commands.cron.execute.messages.module-invalid'),
99 $this->trans('commands.cron.execute.messages.executing-cron'),
103 $this->moduleHandler->invoke($module, 'cron');
104 } catch (\Exception $e) {
105 watchdog_exception('cron', $e);
106 $this->getIo()->error($e->getMessage());
110 $this->state->set('system.cron_last', REQUEST_TIME);
111 $this->lock->release('cron');
113 $this->getIo()->success($this->trans('commands.cron.execute.messages.success'));