@@ -16,6 +16,8 @@ class UpdateDBCommands extends DrushCommands
1616{
1717    protected  $ cache_clear ;
1818
19+     protected  $ maintenanceModeOriginalState ;
20+ 
1921    /** 
2022     * Apply any database updates required (as with running update.php). 
2123     * 
@@ -386,10 +388,10 @@ public function updateBatch($options)
386388        ];
387389        batch_set ($ batch );
388390
389-         $ maintenance_mode_original_state  = \Drupal::service ('state ' )->get ('system.maintenance_mode ' );
391+         // See updateFinished() for the restore of maint mode. 
392+         $ this  ->maintenanceModeOriginalState  = \Drupal::service ('state ' )->get ('system.maintenance_mode ' );
390393        \Drupal::service ('state ' )->set ('system.maintenance_mode ' , true );
391394        $ result  = drush_backend_batch_process ('updatedb:batch-process ' );
392-         \Drupal::service ('state ' )->set ('system.maintenance_mode ' , $ maintenance_mode_original_state );
393395
394396        $ success  = false ;
395397        if  (!is_array ($ result )) {
@@ -468,7 +470,7 @@ public function cacheRebuild()
468470    }
469471
470472    /** 
471-      * Batch update callback, clears the cache if needed. 
473+      * Batch update callback, clears the cache if needed, and restores maint mode . 
472474     * 
473475     * @see \Drupal\system\Controller\DbUpdateController::batchFinished() 
474476     * @see \Drupal\system\Controller\DbUpdateController::results() 
@@ -484,6 +486,8 @@ public function updateFinished($success, $results, $operations)
484486        } else  {
485487            drupal_flush_all_caches ();
486488        }
489+ 
490+         \Drupal::service ('state ' )->set ('system.maintenance_mode ' , $ this  ->maintenanceModeOriginalState );
487491    }
488492
489493    /** 
@@ -587,10 +591,11 @@ public function entityUpdatesMain()
587591                'finished '  => [$ this  , 'updateFinished ' ],
588592            ];
589593            batch_set ($ batch );
590-             $ maintenance_mode_original_state  = \Drupal::service ('state ' )->get ('system.maintenance_mode ' );
594+ 
595+             // See updateFinished() for the restore of maint mode. 
596+             $ this  ->maintenanceModeOriginalState  = \Drupal::service ('state ' )->get ('system.maintenance_mode ' );
591597            \Drupal::service ('state ' )->set ('system.maintenance_mode ' , true );
592598            drush_backend_batch_process ();
593-             \Drupal::service ('state ' )->set ('system.maintenance_mode ' , $ maintenance_mode_original_state );
594599        } else  {
595600            $ this  ->logger ()->success (dt ("No entity schema updates required " ));
596601        }
0 commit comments