From 0a807a85d7c7659c149c581f6c45e9d1795305d4 Mon Sep 17 00:00:00 2001 From: alexpott Date: Wed, 13 Apr 2022 12:02:26 +0200 Subject: [PATCH] Run theme post updates when supported by core (#5120) --- src/Commands/core/UpdateDBCommands.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Commands/core/UpdateDBCommands.php b/src/Commands/core/UpdateDBCommands.php index aab0f9cbeb..b025d3e2a4 100644 --- a/src/Commands/core/UpdateDBCommands.php +++ b/src/Commands/core/UpdateDBCommands.php @@ -265,11 +265,18 @@ public static function updateDoOnePostUpdate(string $function, DrushBatchContext return; } - list($module, $name) = explode('_post_update_', $function, 2); - $filename = $module . '.post_update'; - \Drupal::moduleHandler()->loadInclude($module, 'php', $filename); + list($extension, $name) = explode('_post_update_', $function, 2); + $update_registry = \Drupal::service('update.post_update_registry'); + // https://www.drupal.org/project/drupal/issues/3259188 Support theme's + // having post update functions when it is supported in Drupal core. + if (method_exists($update_registry, 'getUpdateFunctions')) { + \Drupal::service('update.post_update_registry')->getUpdateFunctions($extension); + } else { + \Drupal::service('update.post_update_registry')->getModuleUpdateFunctions($extension); + } + if (function_exists($function)) { - if (empty($context['results'][$module][$name]['type'])) { + if (empty($context['results'][$extension][$name]['type'])) { Drush::logger()->notice("Update started: $function"); } try { @@ -306,10 +313,10 @@ public static function updateDoOnePostUpdate(string $function, DrushBatchContext $context['finished'] = $context['sandbox']['#finished']; unset($context['sandbox']['#finished']); } - if (!isset($context['results'][$module][$name])) { - $context['results'][$module][$name] = []; + if (!isset($context['results'][$extension][$name])) { + $context['results'][$extension][$name] = []; } - $context['results'][$module][$name] = array_merge($context['results'][$module][$name], $ret); + $context['results'][$extension][$name] = array_merge($context['results'][$extension][$name], $ret); // Log the message that was returned. if (!empty($ret['results']['query'])) {