From 1927ac30ab73f43caf5d00748cf6108ee300653d Mon Sep 17 00:00:00 2001 From: Andy Irvine Date: Fri, 21 Apr 2017 14:15:50 +0100 Subject: [PATCH 1/2] Fixed error when using magento cli catalog:images:resize. Was getting error 'Area code is already set'. --- Model/Processor.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Model/Processor.php b/Model/Processor.php index f904090..f17813a 100644 --- a/Model/Processor.php +++ b/Model/Processor.php @@ -7,6 +7,8 @@ use CtiDigital\Configurator\Model\Exception\ComponentException; use Magento\Framework\ObjectManagerInterface; use Symfony\Component\Yaml\Parser; +use Magento\Framework\App\State; +use Magento\Framework\App\Area; class Processor { @@ -36,16 +38,21 @@ class Processor */ protected $objectManager; + /** + * @var State + */ + protected $state; + public function __construct( ConfigInterface $configInterface, ObjectManagerInterface $objectManager, LoggingInterface $logging, - \Magento\Framework\App\State $state + State $state ) { $this->log = $logging; $this->configInterface = $configInterface; $this->objectManager = $objectManager; - $state->setAreaCode('adminhtml'); + $this->state = $state; } @@ -125,7 +132,7 @@ private function runIndividualComponents() $masterConfig = $master[$componentAlias]; // Run that component - $this->runComponent($componentAlias, $masterConfig); + $this->state->emulateAreaCode(Area::AREA_ADMINHTML, [$this, 'runComponent'], [$componentAlias, $masterConfig]); } } catch (ComponentException $e) { $this->log->logError($e->getMessage()); @@ -143,14 +150,14 @@ private function runAllComponents() foreach ($master as $componentAlias => $componentConfig) { // Run the component in question - $this->runComponent($componentAlias, $componentConfig); + $this->state->emulateAreaCode(Area::AREA_ADMINHTML, [$this, 'runComponent'], [$componentAlias, $componentConfig]); } } catch (ComponentException $e) { $this->log->logError($e->getMessage()); } } - private function runComponent($componentAlias, $componentConfig) + public function runComponent($componentAlias, $componentConfig) { $this->log->logComment(""); $this->log->logComment(str_pad("----------------------", (22 + strlen($componentAlias)), "-")); From a03a5cd0ffda9375052de8e20a2c8174e4556609 Mon Sep 17 00:00:00 2001 From: Andy Irvine Date: Fri, 21 Apr 2017 14:28:14 +0100 Subject: [PATCH 2/2] Shortened a couple of lines. --- Model/Processor.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Model/Processor.php b/Model/Processor.php index f17813a..9924a2b 100644 --- a/Model/Processor.php +++ b/Model/Processor.php @@ -132,7 +132,11 @@ private function runIndividualComponents() $masterConfig = $master[$componentAlias]; // Run that component - $this->state->emulateAreaCode(Area::AREA_ADMINHTML, [$this, 'runComponent'], [$componentAlias, $masterConfig]); + $this->state->emulateAreaCode( + Area::AREA_ADMINHTML, + [$this, 'runComponent'], + [$componentAlias, $masterConfig] + ); } } catch (ComponentException $e) { $this->log->logError($e->getMessage()); @@ -150,7 +154,11 @@ private function runAllComponents() foreach ($master as $componentAlias => $componentConfig) { // Run the component in question - $this->state->emulateAreaCode(Area::AREA_ADMINHTML, [$this, 'runComponent'], [$componentAlias, $componentConfig]); + $this->state->emulateAreaCode( + Area::AREA_ADMINHTML, + [$this, 'runComponent'], + [$componentAlias, $componentConfig] + ); } } catch (ComponentException $e) { $this->log->logError($e->getMessage());