Skip to content

Commit 7fe66c5

Browse files
author
Olga Kopylova
committed
MAGETWO-39841: [GitHub] Running 'log:clean' through cli results in an error: 'Area code not set' #1442
- fixed log commands
1 parent 35a2d53 commit 7fe66c5

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

app/code/Magento/Log/Console/Command/AbstractLogCommand.php

+37-15
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
namespace Magento\Log\Console\Command;
77

88
use Symfony\Component\Console\Command\Command;
9-
use Magento\Store\Model\StoreManager;
10-
use Magento\Framework\App\DeploymentConfig;
11-
use Magento\Framework\App\ObjectManagerFactory;
12-
use Magento\Framework\App\ObjectManager;
9+
use Magento\Backend\App\Area\FrontNameResolver;
10+
use Magento\Framework\App\ObjectManager\ConfigLoader;
11+
use Magento\Framework\App\State;
12+
use Magento\Framework\ObjectManagerInterface;
1313

1414
/**
1515
* Abstract class for commands related to manage Magento logs
@@ -19,29 +19,51 @@ abstract class AbstractLogCommand extends Command
1919
/**
2020
* Object Manager
2121
*
22-
* @var ObjectManager
22+
* @var ObjectManagerInterface
2323
*/
2424
protected $objectManager;
2525

26+
/**
27+
* Config loader
28+
*
29+
* @var ConfigLoader
30+
*/
31+
private $configLoader;
32+
33+
/**
34+
* Application state
35+
*
36+
* @var State
37+
*/
38+
private $state;
39+
2640
/**
2741
* Constructor
2842
*
29-
* @param ObjectManagerFactory $objectManagerFactory
43+
* @param ObjectManagerInterface $objectManager
44+
* @param ConfigLoader $configLoader
45+
* @param State $state
3046
*/
31-
public function __construct(ObjectManagerFactory $objectManagerFactory)
32-
{
33-
$params = $_SERVER;
34-
$params[StoreManager::PARAM_RUN_CODE] = 'admin';
35-
$params[StoreManager::PARAM_RUN_TYPE] = 'store';
36-
$this->objectManager = $objectManagerFactory->create($params);
47+
public function __construct(
48+
ObjectManagerInterface $objectManager,
49+
ConfigLoader $configLoader,
50+
State $state
51+
) {
52+
$this->objectManager = $objectManager;
53+
$this->configLoader = $configLoader;
54+
$this->state = $state;
3755
parent::__construct();
3856
}
3957

4058
/**
41-
* {@inheritdoc}
59+
* Reinitialise object manager with correct area
60+
*
61+
* @return void
4262
*/
43-
protected function configure()
63+
protected function initApplicationArea()
4464
{
45-
parent::configure();
65+
$area = FrontNameResolver::AREA_CODE;
66+
$this->state->setAreaCode($area);
67+
$this->objectManager->configure($this->configLoader->load($area));
4668
}
4769
}

app/code/Magento/Log/Console/Command/LogCleanCommand.php

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protected function configure()
4646
*/
4747
protected function execute(InputInterface $input, OutputInterface $output)
4848
{
49+
$this->initApplicationArea();
4950
$errorMsg = 'Invalid value for option "' . self::INPUT_KEY_DAYS
5051
. '". It should be a whole number greater than 0.';
5152
$days = $input->getOption(self::INPUT_KEY_DAYS);

app/code/Magento/Log/Console/Command/LogStatusCommand.php

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ protected function configure()
3535
*/
3636
protected function execute(InputInterface $input, OutputInterface $output)
3737
{
38+
$this->initApplicationArea();
3839
/** @var \Magento\Log\Model\Resource\ShellFactory $resourceFactory */
3940
$resourceFactory = $this->objectManager->create('Magento\Log\Model\Resource\ShellFactory');
4041
/** @var \Magento\Log\Model\Resource\Shell $resource */

0 commit comments

Comments
 (0)