objectManagerFactory = $objectManagerFactory;
$this->deploymentConfig = $deploymentConfig ?: ObjectManager::getInstance()->get(
DeploymentConfig::class
);
parent::__construct();
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$options = [
new InputOption(
self::INPUT_KEY_GROUP,
null,
InputOption::VALUE_REQUIRED,
'Run jobs only from specified group'
),
new InputOption(
Cli::INPUT_KEY_BOOTSTRAP,
null,
InputOption::VALUE_REQUIRED,
'Add or override parameters of the bootstrap'
),
];
$this->setName('cron:run')
->setDescription('Runs jobs by schedule')
->setDefinition($options);
parent::configure();
}
/**
* Runs cron jobs if cron is not disabled in Magento configurations
*
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
if (!$this->deploymentConfig->get('cron/enabled', 1)) {
$output->writeln('' . 'Cron is disabled. Jobs were not run.' . '');
return;
}
$omParams = $_SERVER;
$omParams[StoreManager::PARAM_RUN_CODE] = 'admin';
$omParams[Store::CUSTOM_ENTRY_POINT_PARAM] = true;
$objectManager = $this->objectManagerFactory->create($omParams);
$params[self::INPUT_KEY_GROUP] = $input->getOption(self::INPUT_KEY_GROUP);
$params[ProcessCronQueueObserver::STANDALONE_PROCESS_STARTED] = '0';
$bootstrap = $input->getOption(Cli::INPUT_KEY_BOOTSTRAP);
if ($bootstrap) {
$bootstrapProcessor = new ComplexParameter(Cli::INPUT_KEY_BOOTSTRAP);
$bootstrapOptionValues = $bootstrapProcessor->getFromString(
'--' . Cli::INPUT_KEY_BOOTSTRAP . '=' . $bootstrap
);
$bootstrapOptionValue = $bootstrapOptionValues[ProcessCronQueueObserver::STANDALONE_PROCESS_STARTED];
if ($bootstrapOptionValue) {
$params[ProcessCronQueueObserver::STANDALONE_PROCESS_STARTED] = $bootstrapOptionValue;
}
}
/** @var \Magento\Framework\App\Cron $cronObserver */
$cronObserver = $objectManager->create(\Magento\Framework\App\Cron::class, ['parameters' => $params]);
$cronObserver->launch();
$output->writeln('' . 'Ran jobs by schedule.' . '');
}
}