2121
2222class ExecuteCommand extends Command
2323{
24+
2425 use UpdateTrait;
2526
2627 /**
@@ -67,12 +68,12 @@ class ExecuteCommand extends Command
6768 /**
6869 * EntitiesCommand constructor.
6970 *
70- * @param Site $site
71- * @param StateInterface $state
72- * @param ModuleHandlerInterface $moduleHandler
73- * @param UpdateRegistry $postUpdateRegistry
74- * @param Manager $extensionManager
75- * @param ChainQueue $chainQueue
71+ * @param Site $site
72+ * @param StateInterface $state
73+ * @param ModuleHandlerInterface $moduleHandler
74+ * @param UpdateRegistry $postUpdateRegistry
75+ * @param Manager $extensionManager
76+ * @param ChainQueue $chainQueue
7677 */
7778 public function __construct (
7879 Site $ site ,
@@ -82,12 +83,12 @@ public function __construct(
8283 Manager $ extensionManager ,
8384 ChainQueue $ chainQueue
8485 ) {
85- $ this ->site = $ site ;
86- $ this ->state = $ state ;
87- $ this ->moduleHandler = $ moduleHandler ;
86+ $ this ->site = $ site ;
87+ $ this ->state = $ state ;
88+ $ this ->moduleHandler = $ moduleHandler ;
8889 $ this ->postUpdateRegistry = $ postUpdateRegistry ;
89- $ this ->extensionManager = $ extensionManager ;
90- $ this ->chainQueue = $ chainQueue ;
90+ $ this ->extensionManager = $ extensionManager ;
91+ $ this ->chainQueue = $ chainQueue ;
9192 parent ::__construct ();
9293 }
9394
@@ -98,7 +99,9 @@ protected function configure()
9899 {
99100 $ this
100101 ->setName ('update:execute ' )
101- ->setDescription ($ this ->trans ('commands.update.execute.description ' ))
102+ ->setDescription (
103+ $ this ->trans ('commands.update.execute.description ' )
104+ )
102105 ->addArgument (
103106 'module ' ,
104107 InputArgument::OPTIONAL ,
@@ -120,18 +123,20 @@ protected function configure()
120123 */
121124 protected function execute (InputInterface $ input , OutputInterface $ output )
122125 {
123- $ this ->module = $ input ->getArgument ('module ' );
126+ $ this ->module = $ input ->getArgument ('module ' );
124127 $ this ->update_n = (int )$ input ->getArgument ('update-n ' );
125128
126129 $ this ->site ->loadLegacyFile ('/core/includes/install.inc ' );
127130 $ this ->site ->loadLegacyFile ('/core/includes/update.inc ' );
128131
129132 drupal_load_updates ();
130133
131- $ start = $ this ->getUpdates ($ this ->module !=='all ' ?$ this ->module :null );
132- $ updates = update_resolve_dependencies ($ start );
134+ $ start = $ this ->getUpdates (
135+ $ this ->module !== 'all ' ? $ this ->module : null
136+ );
137+ $ updates = update_resolve_dependencies ($ start );
133138 $ allowUpdate = false ;
134- $ assumeYes = $ input ->getOption ('yes ' );
139+ $ assumeYes = $ input ->getOption ('yes ' );
135140
136141 if (!$ this ->checkUpdates ($ start , $ updates )) {
137142 if ($ this ->module === 'all ' ) {
@@ -155,54 +160,72 @@ protected function execute(InputInterface $input, OutputInterface $output)
155160 $ this ->getIo ()->info ('' );
156161 } else {
157162 $ updateList = update_get_update_list ();
158- $ this ->showUpdateTable ($ this ->module === 'all ' ? $ updateList : $ updateList [$ this ->module ], $ this ->trans ('commands.update.execute.messages.pending-updates ' ));
159-
160- $ allowUpdate = $ assumeYes || $ this ->getIo ()->confirm (
161- $ this ->trans ('commands.update.execute.questions.update ' ),
162- true
163+ $ this ->showUpdateTable (
164+ $ this ->module === 'all ' ? $ updateList
165+ : $ updateList [$ this ->module ],
166+ $ this ->trans ('commands.update.execute.messages.pending-updates ' )
163167 );
168+
169+ $ allowUpdate = $ assumeYes
170+ || $ this ->getIo ()->confirm (
171+ $ this ->trans ('commands.update.execute.questions.update ' ),
172+ true
173+ );
164174 }
165175
166176 // Handle Post update to execute
167177 $ allowPostUpdate = false ;
168- if (!$ postUpdates = $ this ->postUpdateRegistry ->getPendingUpdateInformation ()) {
178+ if (!$ postUpdates
179+ = $ this ->postUpdateRegistry ->getPendingUpdateInformation ()
180+ ) {
169181 $ this ->getIo ()->info (
170- $ this ->trans ('commands.update.execute.messages.no-pending-post-updates ' )
182+ $ this ->trans (
183+ 'commands.update.execute.messages.no-pending-post-updates '
184+ )
171185 );
172186 } else {
173- $ this ->showPostUpdateTable ($ postUpdates , $ this ->trans ('commands.update.execute.messages.pending-post-updates ' ));
174- $ allowPostUpdate = $ assumeYes || $ this ->getIo ()->confirm (
175- $ this ->trans ('commands.update.execute.questions.post-update ' ),
176- true
187+ $ this ->showPostUpdateTable (
188+ $ postUpdates ,
189+ $ this ->trans (
190+ 'commands.update.execute.messages.pending-post-updates '
191+ )
177192 );
193+ $ allowPostUpdate = $ assumeYes
194+ || $ this ->getIo ()->confirm (
195+ $ this ->trans (
196+ 'commands.update.execute.questions.post-update '
197+ ),
198+ true
199+ );
178200 }
179201
180- if ($ allowUpdate ) {
202+ if ($ allowUpdate ) {
181203 try {
182204 $ this ->runUpdates (
183205 $ updates
184206 );
185207 } catch (\Exception $ e ) {
186208 watchdog_exception ('update ' , $ e );
187209 $ this ->getIo ()->error ($ e ->getMessage ());
210+
188211 return 1 ;
189212 }
190213 }
191214
192- if ($ allowPostUpdate ) {
215+ if ($ allowPostUpdate ) {
193216 $ this ->runPostUpdates ($ postUpdates );
194217 }
195218
196- if ($ allowPostUpdate || $ allowUpdate ) {
219+ if ($ allowPostUpdate || $ allowUpdate ) {
197220 $ this ->chainQueue ->addCommand ('cache:rebuild ' , ['cache ' => 'all ' ]);
198221 }
199222
200223 return 0 ;
201224 }
202225
203226 /**
204- * @param array $start
205- * @param array $updates
227+ * @param array $start
228+ * @param array $updates
206229 *
207230 * @return bool true if the selected module/update number exists.
208231 */
@@ -216,8 +239,8 @@ private function checkUpdates(
216239
217240 if ($ this ->module !== 'all ' ) {
218241 $ module = $ this ->module ;
219- $ hooks = array_keys ($ updates );
220- $ hooks = array_map (
242+ $ hooks = array_keys ($ updates );
243+ $ hooks = array_map (
221244 function ($ v ) use ($ module ) {
222245 return (int )str_replace (
223246 $ module .'_update_ ' ,
@@ -237,27 +260,33 @@ function ($v) use ($module) {
237260 }
238261
239262 /**
240- * @param array $updates
263+ * @param array $updates
241264 */
242265 private function runUpdates (
243266 array $ updates
244267 ) {
245268 $ this ->getIo ()->info (
246- $ this ->trans ('commands.update.execute.messages.executing-required-previous-updates ' )
269+ $ this ->trans (
270+ 'commands.update.execute.messages.executing-required-previous-updates '
271+ )
247272 );
248273
249274 foreach ($ updates as $ function => $ update ) {
250275 if (!$ update ['allowed ' ]) {
251276 continue ;
252277 }
253278
254- if ($ this ->module !== 'all ' && $ update ['number ' ] > $ this ->update_n ) {
279+ if ($ this ->module !== 'all '
280+ && $ update ['number ' ] > $ this ->update_n
281+ ) {
255282 break ;
256283 }
257284
258285 $ this ->getIo ()->comment (
259286 sprintf (
260- $ this ->trans ('commands.update.execute.messages.executing-update ' ),
287+ $ this ->trans (
288+ 'commands.update.execute.messages.executing-update '
289+ ),
261290 $ update ['number ' ],
262291 $ update ['module ' ]
263292 )
@@ -278,20 +307,23 @@ private function runUpdates(
278307 }
279308
280309 /**
281- * @param array $postUpdates
310+ * @param array $postUpdates
311+ *
282312 * @return bool
283313 */
284314 private function runPostUpdates ($ postUpdates )
285315 {
286- if (!$ postUpdates ) {
316+ if (!$ postUpdates ) {
287317 return 0 ;
288318 }
289319
290320 foreach ($ postUpdates as $ module => $ updates ) {
291321 foreach ($ updates ['pending ' ] as $ updateName => $ update ) {
292322 $ this ->getIo ()->info (
293323 sprintf (
294- $ this ->trans ('commands.update.execute.messages.executing-post-update ' ),
324+ $ this ->trans (
325+ 'commands.update.execute.messages.executing-post-update '
326+ ),
295327 $ updateName ,
296328 $ module
297329 )
@@ -322,7 +354,7 @@ protected function getUpdates($module = null)
322354 if ($ module ) {
323355 if (isset ($ start [$ module ])) {
324356 $ start = [
325- $ module => $ start [$ module ]
357+ $ module => $ start [$ module ],
326358 ];
327359 } else {
328360 $ start = [];
@@ -335,7 +367,7 @@ protected function getUpdates($module = null)
335367 // Copy of protected \Drupal\system\Controller\DbUpdateController::getModuleUpdates.
336368 protected function getUpdateList ()
337369 {
338- $ start = [];
370+ $ start = [];
339371 $ updates = update_get_update_list ();
340372 foreach ($ updates as $ module => $ update ) {
341373 $ start [$ module ] = $ update ['start ' ];
@@ -357,14 +389,21 @@ private function executeUpdate($function, &$context)
357389 );
358390 }
359391
360- if (isset ($ context ['sandbox ' ]['#finished ' ]) && ($ context ['sandbox ' ]['#finished ' ] < 1 )) {
392+ if (isset ($ context ['sandbox ' ]['#finished ' ])
393+ && ($ context ['sandbox ' ]['#finished ' ] < 1 )
394+ ) {
361395 $ this ->getIo ()->info (
362- ' Processed ' .number_format ($ context ['sandbox ' ]['#finished ' ] * 100 , 2 ).'% '
396+ ' Processed ' .number_format (
397+ $ context ['sandbox ' ]['#finished ' ] * 100 ,
398+ 2
399+ ).'% '
363400 );
364401 }
365402 }
366- } while (isset ($ context ['sandbox ' ]['#finished ' ]) && ($ context ['sandbox ' ]['#finished ' ] < 1 ));
403+ } while (isset ($ context ['sandbox ' ]['#finished ' ])
404+ && ($ context ['sandbox ' ]['#finished ' ] < 1 ));
367405
368406 return true ;
369407 }
408+
370409}
0 commit comments