Skip to content

Commit 901b8d1

Browse files
tstoecklermikeker
authored andcommitted
Fixes drush-ops#2671: Perform cache rebuild during updb in same process (drush-ops#2620)
1 parent 0b74bc0 commit 901b8d1

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

lib/Drush/Commands/core/UpdateDBCommands.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ function updateBatch($options) {
286286
// Apply post update hooks.
287287
$post_updates = \Drupal::service('update.post_update_registry')->getPendingUpdateFunctions();
288288
if ($post_updates) {
289-
$operations[] = ['drush_drupal_cache_clear_all', []];
289+
$operations[] = [[$this, 'cacheRebuild'], []];
290290
foreach ($post_updates as $function) {
291291
$operations[] = ['update_invoke_post_update', [$function]];
292292
}
@@ -346,6 +346,25 @@ function getUpdateList() {
346346
return $return;
347347
}
348348

349+
/**
350+
* Clears caches and rebuilds the container.
351+
*
352+
* This is called in between regular updates and post updates. Do not use
353+
* drush_drupal_cache_clear_all() as the cache clearing and container rebuild
354+
* must happen in the same process that the updates are run in.
355+
*
356+
* Drupal core's update.php uses drupal_flush_all_caches() directly without
357+
* explicitly rebuilding the container as the container is rebuilt on the next
358+
* HTTP request of the batch.
359+
*
360+
* @see drush_drupal_cache_clear_all()
361+
* @see \Drupal\system\Controller\DbUpdateController::triggerBatch()
362+
*/
363+
function cacheRebuild() {
364+
drupal_flush_all_caches();
365+
\Drupal::service('kernel')->rebuildContainer();
366+
}
367+
349368
/**
350369
* Process and display any returned update output.
351370
*

0 commit comments

Comments
 (0)