3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+
6
7
namespace Magento \Deploy \Console \Command \App ;
7
8
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 ;
8
17
use Magento \Framework \Exception \RuntimeException ;
9
18
use Symfony \Component \Console \Command \Command ;
10
19
use Symfony \Component \Console \Input \InputInterface ;
11
20
use Symfony \Component \Console \Output \OutputInterface ;
12
- use Magento \Framework \Console \Cli ;
13
- use Magento \Deploy \Console \Command \App \ConfigImport \Processor ;
14
21
15
22
/**
16
23
* Runs the process of importing configuration data from shared source to appropriate application sources
21
28
*/
22
29
class ConfigImportCommand extends Command
23
30
{
24
- /**
25
- * Command name.
26
- */
27
31
const COMMAND_NAME = 'app:config:import ' ;
28
32
29
33
/**
@@ -33,12 +37,40 @@ class ConfigImportCommand extends Command
33
37
*/
34
38
private $ processor ;
35
39
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
+
36
55
/**
37
56
* @param Processor $processor the configuration importer
57
+ * @param DeploymentConfig|null $deploymentConfig
58
+ * @param EmulatedAdminhtmlAreaProcessor|null $adminhtmlAreaProcessor
59
+ * @param AreaList|null $areaList
38
60
*/
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
+ ) {
41
67
$ 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);
42
74
43
75
parent ::__construct ();
44
76
}
@@ -55,12 +87,26 @@ protected function configure()
55
87
}
56
88
57
89
/**
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
59
97
*/
60
98
protected function execute (InputInterface $ input , OutputInterface $ output )
61
99
{
62
100
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
+ }
64
110
} catch (RuntimeException $ e ) {
65
111
$ output ->writeln ('<error> ' . $ e ->getMessage () . '</error> ' );
66
112
@@ -69,4 +115,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
69
115
70
116
return Cli::RETURN_SUCCESS ;
71
117
}
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
+ }
72
133
}
0 commit comments