From fc0331b50a23b7d561135cb76d13dbe9b3c1c96d Mon Sep 17 00:00:00 2001 From: catch Date: Mon, 1 Jul 2019 13:41:27 +0100 Subject: [PATCH] Revert "Issue #2863986 by bircher, pfrenssen, alexpott, claudiu.cristea, Adita, dawehner, gambry, chr.fritsch: Allow updating modules with new service dependencies" This reverts commit 8f430db9e6ddf33db14940e68e97cc64df0e50ac. --- .../Core/Update/UpdateServiceProvider.php | 28 -------- .../new_dependency_test.info.yml | 8 --- .../new_dependency_test.install | 15 ----- .../new_dependency_test.services.yml | 12 ---- .../src/DecoratedDependentService.php | 42 ------------ .../src/DependentService.php | 39 ----------- .../new_dependency_test_with_service.info.yml | 6 -- ..._dependency_test_with_service.services.yml | 3 - .../src/NewService.php | 20 ------ .../Update/UpdatePathNewDependencyTest.php | 65 ------------------- 10 files changed, 238 deletions(-) delete mode 100644 core/modules/system/tests/modules/new_dependency_test/new_dependency_test.info.yml delete mode 100644 core/modules/system/tests/modules/new_dependency_test/new_dependency_test.install delete mode 100644 core/modules/system/tests/modules/new_dependency_test/new_dependency_test.services.yml delete mode 100644 core/modules/system/tests/modules/new_dependency_test/src/DecoratedDependentService.php delete mode 100644 core/modules/system/tests/modules/new_dependency_test/src/DependentService.php delete mode 100644 core/modules/system/tests/modules/new_dependency_test_with_service/new_dependency_test_with_service.info.yml delete mode 100644 core/modules/system/tests/modules/new_dependency_test_with_service/new_dependency_test_with_service.services.yml delete mode 100644 core/modules/system/tests/modules/new_dependency_test_with_service/src/NewService.php delete mode 100644 core/modules/system/tests/src/Functional/Update/UpdatePathNewDependencyTest.php diff --git a/core/lib/Drupal/Core/Update/UpdateServiceProvider.php b/core/lib/Drupal/Core/Update/UpdateServiceProvider.php index 14457ceedabc..1971ef260ab2 100644 --- a/core/lib/Drupal/Core/Update/UpdateServiceProvider.php +++ b/core/lib/Drupal/Core/Update/UpdateServiceProvider.php @@ -5,7 +5,6 @@ namespace Drupal\Core\Update; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ServiceModifierInterface; use Drupal\Core\DependencyInjection\ServiceProviderInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; @@ -53,33 +52,6 @@ class UpdateServiceProvider implements ServiceProviderInterface, ServiceModifier ->clearTag('path_processor_inbound') ->clearTag('path_processor_outbound'); } - - // Loop over the defined services and remove any with unmet dependencies. - // The kernel cannot be booted if the container has such services. This - // allows modules to run their update hooks to enable newly added - // dependencies. - do { - $definitions = $container->getDefinitions(); - foreach ($definitions as $key => $definition) { - foreach ($definition->getArguments() as $argument) { - if ($argument instanceof Reference) { - if (!$container->has((string) $argument) && $argument->getInvalidBehavior() === ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE) { - // If the container does not have the argument and would throw an - // exception, remove the service. - $container->removeDefinition($key); - } - } - } - } - // Remove any aliases which point to undefined services. - $aliases = $container->getAliases(); - foreach ($aliases as $key => $alias) { - if (!$container->has((string) $alias)) { - $container->removeAlias($key); - } - } - // Repeat if services or aliases have been removed. - } while (count($definitions) > count($container->getDefinitions()) || count($aliases) > count($container->getAliases())); } } diff --git a/core/modules/system/tests/modules/new_dependency_test/new_dependency_test.info.yml b/core/modules/system/tests/modules/new_dependency_test/new_dependency_test.info.yml deleted file mode 100644 index eab08261b53c..000000000000 --- a/core/modules/system/tests/modules/new_dependency_test/new_dependency_test.info.yml +++ /dev/null @@ -1,8 +0,0 @@ -name: 'New Dependency test' -type: module -description: 'Support module for update testing.' -package: Testing -version: VERSION -core: 8.x -dependencies: - - new_dependency_test_with_service diff --git a/core/modules/system/tests/modules/new_dependency_test/new_dependency_test.install b/core/modules/system/tests/modules/new_dependency_test/new_dependency_test.install deleted file mode 100644 index e500d72b2268..000000000000 --- a/core/modules/system/tests/modules/new_dependency_test/new_dependency_test.install +++ /dev/null @@ -1,15 +0,0 @@ -get('module_installer')->install(['new_dependency_test_with_service']); -} diff --git a/core/modules/system/tests/modules/new_dependency_test/new_dependency_test.services.yml b/core/modules/system/tests/modules/new_dependency_test/new_dependency_test.services.yml deleted file mode 100644 index 29a6de5b5f8a..000000000000 --- a/core/modules/system/tests/modules/new_dependency_test/new_dependency_test.services.yml +++ /dev/null @@ -1,12 +0,0 @@ -services: - new_dependency_test.dependent: - class: Drupal\new_dependency_test\DependentService - arguments: ['@new_dependency_test_with_service.service'] - new_dependency_test.decorated: - class: Drupal\new_dependency_test\DecoratedDependentService - arguments: ['@new_dependency_test.dependent'] - new_dependency_test.decorated_optional: - class: Drupal\new_dependency_test\DecoratedDependentService - arguments: ['@?new_dependency_test.dependent'] - new_dependency_test.alias: - alias: new_dependency_test.dependent diff --git a/core/modules/system/tests/modules/new_dependency_test/src/DecoratedDependentService.php b/core/modules/system/tests/modules/new_dependency_test/src/DecoratedDependentService.php deleted file mode 100644 index 6c37f6435e61..000000000000 --- a/core/modules/system/tests/modules/new_dependency_test/src/DecoratedDependentService.php +++ /dev/null @@ -1,42 +0,0 @@ -service = $service; - } - - /** - * Get the simple greeting from the service and decorate it. - * - * @return string - * The enhanced greeting. - */ - public function greet() { - if (isset($this->service)) { - return $this->service->greet() . ' World'; - } - return 'Sorry, no service.'; - } - -} diff --git a/core/modules/system/tests/modules/new_dependency_test/src/DependentService.php b/core/modules/system/tests/modules/new_dependency_test/src/DependentService.php deleted file mode 100644 index 22e1631a0958..000000000000 --- a/core/modules/system/tests/modules/new_dependency_test/src/DependentService.php +++ /dev/null @@ -1,39 +0,0 @@ -service = $service; - } - - /** - * Get the simple greeting from the service. - * - * @return string - * The greeting. - */ - public function greet() { - return $this->service->greet(); - } - -} diff --git a/core/modules/system/tests/modules/new_dependency_test_with_service/new_dependency_test_with_service.info.yml b/core/modules/system/tests/modules/new_dependency_test_with_service/new_dependency_test_with_service.info.yml deleted file mode 100644 index 5091a7f79d6a..000000000000 --- a/core/modules/system/tests/modules/new_dependency_test_with_service/new_dependency_test_with_service.info.yml +++ /dev/null @@ -1,6 +0,0 @@ -name: 'New Dependency test with service' -type: module -description: 'Support module for update testing.' -package: Testing -version: VERSION -core: 8.x diff --git a/core/modules/system/tests/modules/new_dependency_test_with_service/new_dependency_test_with_service.services.yml b/core/modules/system/tests/modules/new_dependency_test_with_service/new_dependency_test_with_service.services.yml deleted file mode 100644 index 26ba284e29be..000000000000 --- a/core/modules/system/tests/modules/new_dependency_test_with_service/new_dependency_test_with_service.services.yml +++ /dev/null @@ -1,3 +0,0 @@ -services: - new_dependency_test_with_service.service: - class: Drupal\new_dependency_test_with_service\NewService diff --git a/core/modules/system/tests/modules/new_dependency_test_with_service/src/NewService.php b/core/modules/system/tests/modules/new_dependency_test_with_service/src/NewService.php deleted file mode 100644 index 6137fc2ecf78..000000000000 --- a/core/modules/system/tests/modules/new_dependency_test_with_service/src/NewService.php +++ /dev/null @@ -1,20 +0,0 @@ -databaseDumpFiles = [ - __DIR__ . '/../../../../tests/fixtures/update/drupal-8.6.0.bare.testing.php.gz', - ]; - } - - /** - * Test that a module can add services that depend on new modules. - */ - public function testUpdateNewDependency() { - // The new_dependency_test before the update is just an empty info.yml file. - // The code of the new_dependency_test module is after the update and - // contains the dependency on the new_dependency_test_with_service module. - $extension_config = $this->container->get('config.factory')->getEditable('core.extension'); - $extension_config - ->set('module.new_dependency_test', 0) - ->set('module', module_config_sort($extension_config->get('module'))) - ->save(TRUE); - drupal_set_installed_schema_version('new_dependency_test', \Drupal::CORE_MINIMUM_SCHEMA_VERSION); - - // Rebuild the container and test that the service with the optional unmet - // dependency is still available while the ones that fail are not. - - try { - $this->rebuildContainer(); - $this->fail('The container has services with unmet dependencies and should have failed to rebuild.'); - } - catch (ServiceNotFoundException $exception) { - $this->assertEquals('The service "new_dependency_test.dependent" has a dependency on a non-existent service "new_dependency_test_with_service.service".', $exception->getMessage()); - } - - // Running the updates enables the dependency. - $this->runUpdates(); - - $this->assertTrue(array_key_exists('new_dependency_test', $this->container->get('config.factory')->get('core.extension')->get('module'))); - $this->assertTrue(array_key_exists('new_dependency_test_with_service', $this->container->get('config.factory')->get('core.extension')->get('module'))); - - // Tests that the new services are available and working as expected. - $this->assertEquals('Hello', $this->container->get('new_dependency_test_with_service.service')->greet()); - $this->assertEquals('Hello', $this->container->get('new_dependency_test.dependent')->greet()); - $this->assertEquals('Hello', $this->container->get('new_dependency_test.alias')->greet()); - $this->assertEquals('Hello World', $this->container->get('new_dependency_test.decorated')->greet()); - $this->assertEquals('Hello World', $this->container->get('new_dependency_test.decorated_optional')->greet()); - - } - -}