Skip to content

Commit 5f1f9fd

Browse files
author
Olga Kopylova
committed
MAGETWO-39778: Reindex by cron cannot finish: "Area code not set"
- fixed init of object manager in cron:run command
1 parent e9b1713 commit 5f1f9fd

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

app/code/Magento/Cron/Console/Command/CronCommand.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ class CronCommand extends Command
2929
const INPUT_KEY_GROUP = 'group';
3030

3131
/**
32-
* Object Manager
32+
* Object manager factory
3333
*
34-
* @var ObjectManagerInterface
34+
* @var ObjectManagerFactory
3535
*/
36-
protected $objectManager;
36+
private $objectManagerFactory;
3737

3838
/**
3939
* Constructor
@@ -42,10 +42,7 @@ class CronCommand extends Command
4242
*/
4343
public function __construct(ObjectManagerFactory $objectManagerFactory)
4444
{
45-
$params = $_SERVER;
46-
$params[StoreManager::PARAM_RUN_CODE] = 'admin';
47-
$params[Store::CUSTOM_ENTRY_POINT_PARAM] = true;
48-
$this->objectManager = $objectManagerFactory->create($params);
45+
$this->objectManagerFactory = $objectManagerFactory;
4946
parent::__construct();
5047
}
5148

@@ -80,6 +77,11 @@ protected function configure()
8077
*/
8178
protected function execute(InputInterface $input, OutputInterface $output)
8279
{
80+
$omParams = $_SERVER;
81+
$omParams[StoreManager::PARAM_RUN_CODE] = 'admin';
82+
$omParams[Store::CUSTOM_ENTRY_POINT_PARAM] = true;
83+
$objectManager = $this->objectManagerFactory->create($omParams);
84+
8385
$params[self::INPUT_KEY_GROUP] = $input->getOption(self::INPUT_KEY_GROUP);
8486
$params[Observer::STANDALONE_PROCESS_STARTED] = '0';
8587
$bootstrap = $input->getOption(Cli::INPUT_KEY_BOOTSTRAP);
@@ -94,7 +96,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9496
}
9597
}
9698
/** @var \Magento\Framework\App\Cron $cronObserver */
97-
$cronObserver = $this->objectManager->create('Magento\Framework\App\Cron', ['parameters' => $params]);
99+
$cronObserver = $objectManager->create('Magento\Framework\App\Cron', ['parameters' => $params]);
98100
$cronObserver->launch();
99101
$output->writeln('<info>' . 'Ran jobs by schedule.' . '</info>');
100102
}

app/code/Magento/Cron/Model/Observer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public function dispatch($observer)
182182
}
183183
} catch (\Exception $e) {
184184
$schedule->setMessages($e->getMessage());
185+
$schedule->setStatus(Schedule::STATUS_ERROR);
185186
}
186187
$schedule->save();
187188
}

0 commit comments

Comments
 (0)