Skip to content

Commit

Permalink
Merge pull request #30 from ctidigital/cli
Browse files Browse the repository at this point in the history
Emulating area code
  • Loading branch information
chevli authored Apr 21, 2017
2 parents bf2225c + a03a5cd commit 0ad8b19
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions Model/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}


Expand Down Expand Up @@ -125,7 +132,11 @@ 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());
Expand All @@ -143,14 +154,18 @@ 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)), "-"));
Expand Down

0 comments on commit 0ad8b19

Please sign in to comment.