33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6+
67namespace Magento \Deploy \Console \Command \App ;
78
9+ use Magento \Config \Console \Command \EmulatedAdminhtmlAreaProcessor ;
10+ use Magento \Deploy \Console \Command \App \ConfigImport \Processor ;
11+ use Magento \Framework \App \Area ;
12+ use Magento \Framework \App \AreaList ;
13+ use Magento \Framework \App \DeploymentConfig ;
14+ use Magento \Framework \App \ObjectManager ;
15+ use Magento \Framework \Console \Cli ;
16+ use Magento \Framework \Exception \FileSystemException ;
817use Magento \Framework \Exception \RuntimeException ;
918use Symfony \Component \Console \Command \Command ;
1019use Symfony \Component \Console \Input \InputInterface ;
1120use Symfony \Component \Console \Output \OutputInterface ;
12- use Magento \Framework \Console \Cli ;
13- use Magento \Deploy \Console \Command \App \ConfigImport \Processor ;
1421
1522/**
1623 * Runs the process of importing configuration data from shared source to appropriate application sources
2128 */
2229class ConfigImportCommand extends Command
2330{
24- /**
25- * Command name.
26- */
2731 const COMMAND_NAME = 'app:config:import ' ;
2832
2933 /**
@@ -33,12 +37,40 @@ class ConfigImportCommand extends Command
3337 */
3438 private $ processor ;
3539
40+ /**
41+ * @var EmulatedAdminhtmlAreaProcessor
42+ */
43+ private $ adminhtmlAreaProcessor ;
44+
45+ /**
46+ * @var DeploymentConfig
47+ */
48+ private $ deploymentConfig ;
49+
50+ /**
51+ * @var AreaList
52+ */
53+ private $ areaList ;
54+
3655 /**
3756 * @param Processor $processor the configuration importer
57+ * @param DeploymentConfig|null $deploymentConfig
58+ * @param EmulatedAdminhtmlAreaProcessor|null $adminhtmlAreaProcessor
59+ * @param AreaList|null $areaList
3860 */
39- public function __construct (Processor $ processor )
40- {
61+ public function __construct (
62+ Processor $ processor ,
63+ DeploymentConfig $ deploymentConfig = null ,
64+ EmulatedAdminhtmlAreaProcessor $ adminhtmlAreaProcessor = null ,
65+ AreaList $ areaList = null
66+ ) {
4167 $ this ->processor = $ processor ;
68+ $ this ->deploymentConfig = $ deploymentConfig
69+ ?? ObjectManager::getInstance ()->get (DeploymentConfig::class);
70+ $ this ->adminhtmlAreaProcessor = $ adminhtmlAreaProcessor
71+ ?? ObjectManager::getInstance ()->get (EmulatedAdminhtmlAreaProcessor::class);
72+ $ this ->areaList = $ areaList
73+ ?? ObjectManager::getInstance ()->get (AreaList::class);
4274
4375 parent ::__construct ();
4476 }
@@ -55,12 +87,26 @@ protected function configure()
5587 }
5688
5789 /**
58- * Imports data from deployment configuration files to the DB. {@inheritdoc}
90+ * Imports data from deployment configuration files to the DB.
91+ * {@inheritdoc}
92+ *
93+ * @param InputInterface $input
94+ * @param OutputInterface $output
95+ * @return int
96+ * @throws \Exception
5997 */
6098 protected function execute (InputInterface $ input , OutputInterface $ output )
6199 {
62100 try {
63- $ this ->processor ->execute ($ input , $ output );
101+ if ($ this ->canEmulateAdminhtmlArea ()) {
102+ // Emulate adminhtml area in order to execute all needed plugins declared only for this area
103+ // For instance URL rewrite generation during creating store view
104+ $ this ->adminhtmlAreaProcessor ->process (function () use ($ input , $ output ) {
105+ $ this ->processor ->execute ($ input , $ output );
106+ });
107+ } else {
108+ $ this ->processor ->execute ($ input , $ output );
109+ }
64110 } catch (RuntimeException $ e ) {
65111 $ output ->writeln ('<error> ' . $ e ->getMessage () . '</error> ' );
66112
@@ -69,4 +115,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
69115
70116 return Cli::RETURN_SUCCESS ;
71117 }
118+
119+ /**
120+ * Detects if we can emulate adminhtml area
121+ *
122+ * This area could be not available for instance during setup:install
123+ *
124+ * @return bool
125+ * @throws RuntimeException
126+ * @throws FileSystemException
127+ */
128+ private function canEmulateAdminhtmlArea (): bool
129+ {
130+ return $ this ->deploymentConfig ->isAvailable ()
131+ && in_array (Area::AREA_ADMINHTML , $ this ->areaList ->getCodes ());
132+ }
72133}
0 commit comments