Skip to content

Commit 4ab3ad1

Browse files
authored
Merge pull request #2 from jaychow/master
Fixed "Area code not set: Area code must be set before starting a session." error message.
2 parents 7d72b1b + bc6638d commit 4ab3ad1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Console/Command/RegenerateUrlRewrites.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ class RegenerateUrlRewrites extends Command
3232
*/
3333
protected $_storeManager;
3434

35+
/**
36+
* @var \Magento\Framework\App\State $appState
37+
*/
38+
protected $_appState;
39+
3540
/**
3641
* Constructor of RegenerateUrlRewrites
3742
*
@@ -42,11 +47,13 @@ class RegenerateUrlRewrites extends Command
4247
public function __construct(
4348
\Magento\Framework\App\ResourceConnection $resource,
4449
\Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $categoryCollectionFactory,
45-
\Magento\Catalog\Helper\Category $categoryHelper
50+
\Magento\Catalog\Helper\Category $categoryHelper,
51+
\Magento\Framework\App\State $appState
4652
) {
4753
$this->_resource = $resource;
4854
$this->_categoryCollectionFactory = $categoryCollectionFactory;
4955
$this->_categoryHelper = $categoryHelper;
56+
$this->_appState = $appState;
5057
parent::__construct();
5158
}
5259

@@ -100,6 +107,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
100107

101108
// remove all current url rewrites
102109
$this->removeAllUrlRewrites($storesList);
110+
111+
$this->_appState->setAreaCode('adminhtml');
103112

104113
foreach ($storesList as $storeId => $storeCode) {
105114
$output->write("[Store ID: {$storeId}, Store View code: {$storeCode}]:");

0 commit comments

Comments
 (0)