X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FCron%2FExecuteCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FCron%2FExecuteCommand.php;h=39181925ca5dad03948d7eb1ab49c169ad3d9607;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/Cron/ExecuteCommand.php b/vendor/drupal/console/src/Command/Cron/ExecuteCommand.php new file mode 100644 index 000000000..39181925c --- /dev/null +++ b/vendor/drupal/console/src/Command/Cron/ExecuteCommand.php @@ -0,0 +1,132 @@ +moduleHandler = $moduleHandler; + $this->lock = $lock; + $this->state = $state; + $this->chainQueue = $chainQueue; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('cron:execute') + ->setDescription($this->trans('commands.cron.execute.description')) + ->addArgument( + 'module', + InputArgument::IS_ARRAY | InputArgument::OPTIONAL, + $this->trans('commands.common.options.module') + ); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + $modules = $input->getArgument('module'); + + if (!$this->lock->acquire('cron', 900.0)) { + $io->warning($this->trans('commands.cron.execute.messages.lock')); + + return 1; + } + + if ($modules === null || in_array('all', $modules)) { + $modules = $this->moduleHandler->getImplementations('cron'); + } + + foreach ($modules as $module) { + if (!$this->moduleHandler->implementsHook($module, 'cron')) { + $io->warning( + sprintf( + $this->trans('commands.cron.execute.messages.module-invalid'), + $module + ) + ); + continue; + } + try { + $io->info( + sprintf( + $this->trans('commands.cron.execute.messages.executing-cron'), + $module + ) + ); + $this->moduleHandler->invoke($module, 'cron'); + } catch (\Exception $e) { + watchdog_exception('cron', $e); + $io->error($e->getMessage()); + } + } + + $this->state->set('system.cron_last', REQUEST_TIME); + $this->lock->release('cron'); + + $this->chainQueue->addCommand('cache:rebuild', ['cache' => 'all']); + + $io->success($this->trans('commands.cron.execute.messages.success')); + + return 0; + } +}