From 5f9ca1c07758c00d016a3aef2c923c573c634f7a Mon Sep 17 00:00:00 2001 From: Pieter Frenssen Date: Sat, 3 Sep 2022 16:27:57 +0300 Subject: [PATCH] Fix execution of deploy hooks inside a module with _deploy in the name. (#5217) * Test execution of deploy hooks inside a module with _deploy in the name. Test for #5216 * Support deploy hooks in modules with _deploy in the name. --- .../Commands/core/DeployHookCommands.php | 16 +++++++++++++--- .../modules/woot_deploy/woot_deploy.deploy.php | 17 +++++++++++++++++ .../modules/woot_deploy/woot_deploy.info.yml | 5 +++++ tests/functional/DeployHookTest.php | 18 ++++++++++++++++++ 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/modules/woot_deploy/woot_deploy.deploy.php create mode 100644 tests/fixtures/modules/woot_deploy/woot_deploy.info.yml diff --git a/src/Drupal/Commands/core/DeployHookCommands.php b/src/Drupal/Commands/core/DeployHookCommands.php index 9bcbb0a761..5517698de8 100644 --- a/src/Drupal/Commands/core/DeployHookCommands.php +++ b/src/Drupal/Commands/core/DeployHookCommands.php @@ -171,9 +171,19 @@ public static function updateDoOneDeployHook(string $function, DrushBatchContext return; } - list($module, $name) = explode('_deploy_', $function, 2); - $filename = $module . '.deploy'; - \Drupal::moduleHandler()->loadInclude($module, 'php', $filename); + // Module names can include '_deploy', so deploy functions like + // module_deploy_deploy_name() are ambiguous. Check every occurrence. + $components = explode('_', $function); + foreach (array_keys($components, 'deploy', TRUE) as $position) { + $module = implode('_', array_slice($components, 0, $position)); + $name = implode('_', array_slice($components, $position + 1)); + $filename = $module . '.deploy'; + \Drupal::moduleHandler()->loadInclude($module, 'php', $filename); + if (function_exists($function)) { + break; + } + } + if (function_exists($function)) { if (empty($context['results'][$module][$name]['type'])) { Drush::logger()->notice("Deploy hook started: $function"); diff --git a/tests/fixtures/modules/woot_deploy/woot_deploy.deploy.php b/tests/fixtures/modules/woot_deploy/woot_deploy.deploy.php new file mode 100644 index 0000000000..044bf3e1ac --- /dev/null +++ b/tests/fixtures/modules/woot_deploy/woot_deploy.deploy.php @@ -0,0 +1,17 @@ +drush('deploy:hook-status', [], $options, null, null, self::EXIT_SUCCESS); $this->assertStringContainsString('[]', $this->getOutput()); } + + public function testDeployHooksInModuleWithDeployInName() + { + $this->setUpDrupal(1, true); + $options = [ + 'yes' => null, + ]; + $this->setupModulesForTests(['woot_deploy'], Path::join(__DIR__, '/../fixtures/modules')); + $this->drush('pm-install', ['woot_deploy'], $options); + + // Run deploy hooks. + $this->drush('deploy:hook', [], $options, null, null, self::EXIT_SUCCESS); + + $this->assertStringContainsString('[notice] Deploy hook started: woot_deploy_deploy_function', $this->getErrorOutput()); + $this->assertStringContainsString('[notice] This is the update message from woot_deploy_deploy_function', $this->getErrorOutput()); + $this->assertStringContainsString('[notice] Performed: woot_deploy_deploy_function', $this->getErrorOutput()); + $this->assertStringContainsString('[success] Finished performing deploy hooks.', $this->getErrorOutput()); + } }