@@ -77,56 +77,63 @@ public function execute(): void
77
77
throw new StepException ($ exception ->getMessage (), $ exception ->getCode (), $ exception );
78
78
}
79
79
80
- $ driver = $ this ->config ->getDriver ();
81
-
82
- if ($ driver ) {
83
- $ config = $ this ->config ->getConfig ();
80
+ if ($ driver = $ this ->config ->getDriver ()) {
81
+ $ this ->updateConfig ($ driver );
82
+ } else {
83
+ $ this ->magentoShell ->execute ('setup:config:set --remote-storage-driver=file -n ' );
84
+ }
85
+ }
84
86
85
- if (empty ($ config ['bucket ' ]) || empty ($ config ['region ' ])) {
86
- throw new StepException ('Bucket and region are required configurations ' );
87
- }
87
+ /**
88
+ * Update configuration.
89
+ *
90
+ * @param string $driver
91
+ * @throws StepException
92
+ */
93
+ private function updateConfig (string $ driver ): void
94
+ {
95
+ $ config = $ this ->config ->getConfig ();
88
96
89
- $ options = [
90
- '--remote-storage-driver= ' . $ driver ,
91
- '--remote-storage-bucket= ' . $ config ['bucket ' ],
92
- '--remote-storage-region= ' . $ config ['region ' ]
93
- ];
97
+ if (empty ($ config ['bucket ' ]) || empty ($ config ['region ' ])) {
98
+ throw new StepException ('Bucket and region are required configurations ' );
99
+ }
94
100
95
- if ($ prefix = $ this ->config ->getPrefix ()) {
96
- $ options [] = '--remote-storage-prefix= ' . $ prefix ;
97
- }
101
+ $ options = [
102
+ '--remote-storage-driver= ' . $ driver ,
103
+ '--remote-storage-bucket= ' . $ config ['bucket ' ],
104
+ '--remote-storage-region= ' . $ config ['region ' ]
105
+ ];
98
106
99
- if (isset ($ config ['key ' ], $ config ['secret ' ])) {
100
- $ options [] = '--remote-storage-key= ' . $ config ['key ' ];
101
- $ options [] = '--remote-storage-secret= ' . $ config ['secret ' ];
102
- }
107
+ if ($ prefix = $ this ->config ->getPrefix ()) {
108
+ $ options [] = '--remote-storage-prefix= ' . $ prefix ;
109
+ }
103
110
104
- try {
105
- $ this ->magentoShell ->execute (sprintf (
106
- 'setup:config:set %s -n ' ,
107
- implode (' ' , $ options )
108
- ));
109
- } catch (ShellException $ exception ) {
110
- $ this ->logger ->critical (
111
- $ exception ->getMessage (),
112
- ['errorCode ' => Error::WARN_REMOTE_STORAGE_CANNOT_BE_ENABLED ]
113
- );
114
-
115
- throw new StepException (
116
- $ exception ->getMessage (),
117
- Error::WARN_REMOTE_STORAGE_CANNOT_BE_ENABLED ,
118
- $ exception
119
- );
120
- }
111
+ if (isset ($ config ['key ' ], $ config ['secret ' ])) {
112
+ $ options [] = '--remote-storage-key= ' . $ config ['key ' ];
113
+ $ options [] = '--remote-storage-secret= ' . $ config ['secret ' ];
114
+ }
121
115
122
- $ this ->logger ->info (sprintf (
123
- 'Remote storage with driver "%s" was enabled ' ,
124
- $ driver
116
+ try {
117
+ $ this ->magentoShell ->execute (sprintf (
118
+ 'setup:config:set %s -n ' ,
119
+ implode (' ' , $ options )
125
120
));
126
-
127
- return ;
121
+ } catch (ShellException $ exception ) {
122
+ $ this ->logger ->critical (
123
+ $ exception ->getMessage (),
124
+ ['errorCode ' => Error::WARN_REMOTE_STORAGE_CANNOT_BE_ENABLED ]
125
+ );
126
+
127
+ throw new StepException (
128
+ $ exception ->getMessage (),
129
+ Error::WARN_REMOTE_STORAGE_CANNOT_BE_ENABLED ,
130
+ $ exception
131
+ );
128
132
}
129
133
130
- $ this ->magentoShell ->execute ('setup:config:set --remote-storage-driver=file -n ' );
134
+ $ this ->logger ->info (sprintf (
135
+ 'Remote storage with driver "%s" was enabled ' ,
136
+ $ driver
137
+ ));
131
138
}
132
139
}
0 commit comments