processor = $processor; $this->deploymentConfig = $deploymentConfig ?? ObjectManager::getInstance()->get(DeploymentConfig::class); $this->adminhtmlAreaProcessor = $adminhtmlAreaProcessor ?? ObjectManager::getInstance()->get(EmulatedAdminhtmlAreaProcessor::class); $this->areaList = $areaList ?? ObjectManager::getInstance()->get(AreaList::class); parent::__construct(); } /** * @inheritdoc */ protected function configure() { $this->setName(self::COMMAND_NAME) ->setDescription('Import data from shared configuration files to appropriate data storage'); parent::configure(); } /** * Imports data from deployment configuration files to the DB. * {@inheritdoc} * * @param InputInterface $input * @param OutputInterface $output * @return int * @throws \Exception */ protected function execute(InputInterface $input, OutputInterface $output) { try { if ($this->canEmulateAdminhtmlArea()) { // Emulate adminhtml area in order to execute all needed plugins declared only for this area // For instance URL rewrite generation during creating store view $this->adminhtmlAreaProcessor->process(function () use ($input, $output) { $this->processor->execute($input, $output); }); } else { $this->processor->execute($input, $output); } } catch (RuntimeException $e) { $output->writeln('' . $e->getMessage() . ''); return Cli::RETURN_FAILURE; } return Cli::RETURN_SUCCESS; } /** * Detects if we can emulate adminhtml area * * This area could be not available for instance during setup:install * * @return bool * @throws RuntimeException * @throws FileSystemException */ private function canEmulateAdminhtmlArea(): bool { return $this->deploymentConfig->isAvailable() && in_array(Area::AREA_ADMINHTML, $this->areaList->getCodes()); } }