diff --git a/app/code/Magento/Cron/Console/Command/CronCommand.php b/app/code/Magento/Cron/Console/Command/CronCommand.php new file mode 100644 index 0000000000000000000000000000000000000000..5f820f208ef4494d7a2c4a2b11569fbff9b715b9 --- /dev/null +++ b/app/code/Magento/Cron/Console/Command/CronCommand.php @@ -0,0 +1,82 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Cron\Console\Command; + +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Input\InputOption; +use Magento\Framework\App\ObjectManagerFactory; +use Magento\Framework\App\ObjectManager; +use Magento\Store\Model\Store; +use Magento\Store\Model\StoreManager; + +/** + * Command for executing cron jobs + */ +class CronCommand extends Command +{ + /** + * Name of input option + */ + const INPUT_KEY_GROUP = 'group'; + + /** + * Object Manager + * + * @var ObjectManager + */ + protected $objectManager; + + /** + * Constructor + * + * @param ObjectManagerFactory $objectManagerFactory + */ + public function __construct(ObjectManagerFactory $objectManagerFactory) + { + $params = $_SERVER; + $params[StoreManager::PARAM_RUN_CODE] = 'admin'; + $params[Store::CUSTOM_ENTRY_POINT_PARAM] = true; + $this->objectManager = $objectManagerFactory->create($params); + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $options = [ + new InputOption( + self::INPUT_KEY_GROUP, + null, + InputOption::VALUE_REQUIRED, + 'Run jobs only from specified group', + 'default' + ), + ]; + $this->setName('cron:run') + ->setDescription('Runs jobs by schedule') + ->setDefinition($options); + parent::configure(); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $params['group'] = $input->getOption(self::INPUT_KEY_GROUP); + // This flag 'standaloneProcessStarted' is for internal communication between processes only + $params['standaloneProcessStarted'] = '0'; + /** @var \Magento\Framework\App\Cron $cronObserver */ + $cronObserver = $this->objectManager->create('Magento\Framework\App\Cron', ['parameters' => $params]); + $cronObserver->launch(); + $output->writeln('<info>' . 'Ran jobs by schedule.' . '</info>'); + } +} diff --git a/app/code/Magento/Cron/etc/di.xml b/app/code/Magento/Cron/etc/di.xml index 6680200ebc0407c7830d34ef8816ff9de14cef92..2be7e453defaf9d09b464165b4d3e1d94f497ea2 100644 --- a/app/code/Magento/Cron/etc/di.xml +++ b/app/code/Magento/Cron/etc/di.xml @@ -29,4 +29,11 @@ <argument name="shell" xsi:type="object">shellBackground</argument> </arguments> </type> + <type name="Magento\Framework\Console\CommandList"> + <arguments> + <argument name="commands" xsi:type="array"> + <item name="cronCommand" xsi:type="object">Magento\Cron\Console\Command\CronCommand</item> + </argument> + </arguments> + </type> </config> diff --git a/pub/cron.php b/pub/cron.php index 8e70c3cb0e927a0413449ee8277d3b4fff6d5500..9f1b816d2f74261f2437803559aeecf6095b63c4 100755 --- a/pub/cron.php +++ b/pub/cron.php @@ -29,7 +29,7 @@ if ($_GET){ if (empty($opt['group'])) { $opt['group'] = 'default'; } -// It is tracked for internal communication between processes, no user input is needed for this +// This flag is for internal communication between processes only; no user input is needed for this if (empty($opt['standaloneProcessStarted'])) { $opt['standaloneProcessStarted'] = '0'; }