diff --git a/core/includes/install.inc b/core/includes/install.inc index bf88901..aa8d049 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -1001,7 +1001,7 @@ function drupal_check_module($module) { // We can't use the module handler here because it only gives us enabled // extensions. $extension = new Extension(DRUPAL_ROOT, 'module', drupal_get_filename('module', $module)); - $requirements = array_merge($requirements, $dependency_requirements->extensionComposerRequirements($extension)); + $requirements = array_merge($requirements, $dependency_requirements->buildRequirements([$extension])); if (drupal_requirements_severity($requirements) == REQUIREMENT_ERROR) { // Print any error messages diff --git a/core/lib/Drupal/Core/Composer/ExtensionDependencyRequirements.php b/core/lib/Drupal/Core/Composer/ExtensionDependencyRequirements.php index 00211f1..fa5eecb 100644 --- a/core/lib/Drupal/Core/Composer/ExtensionDependencyRequirements.php +++ b/core/lib/Drupal/Core/Composer/ExtensionDependencyRequirements.php @@ -40,34 +40,42 @@ public function __construct(ExtensionDependencyChecker $dependency_checker, Tran } /** - * Determines whether Composer-based dependencies are still required. + * Builds the Composer requirements for extensions. * - * @param \Drupal\Core\Extension\Extension $extension - * Extension to check. + * @param \Drupal\Core\Extension\Extension[] $extensions + * The extensions to build the requirements for. * * @return array[] * Requirements array, suitable for hook_requirements(). */ - public function extensionComposerRequirements(Extension $extension) { + public function buildRequirements(array $extensions) { $requirements = [ 'composer_dependencies' => [ 'title' => $this->t('Composer dependencies'), ], ]; - if (!$this->dependencyChecker->dependenciesAreMet($extension)) { - $requirements['composer_dependencies'] = [ - 'description' => $this->t('Not all the modules have their Composer dependencies installed yet. Find more information on this handbook page.', [ - '@handbook' => 'https://www.drupal.org/node/2627292' + $unmet_dependencies = FALSE; + foreach ($extensions as $extension) { + if (!$this->dependencyChecker->dependenciesAreMet($extension)) { + $unmet_dependencies = TRUE; + break; + } + } + if ($unmet_dependencies) { + $requirements['composer_dependencies'] += [ + 'description' => $this->t('Some modules require Composer dependencies. Read the documentation on how to install them.', [ + '@documentation' => 'https://www.drupal.org/node/2627292' ]), 'severity' => REQUIREMENT_ERROR, ]; } else { - $requirements['composer_dependencies'] = [ + $requirements['composer_dependencies'] += [ 'description' => $this->t('All Composer dependencies have been installed.'), 'severity' => REQUIREMENT_OK, ]; } + return $requirements; } diff --git a/core/modules/system/system.install b/core/modules/system/system.install index afa5892..9e21ff2 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -7,6 +7,8 @@ use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\Environment; +use Drupal\Core\Composer\ExtensionDependencyChecker; +use Drupal\Core\Composer\ExtensionDependencyRequirements; use Drupal\Core\Url; use Drupal\Core\Database\Database; use Drupal\Core\DrupalKernel; @@ -239,6 +241,14 @@ function system_requirements($phase) { $requirements['php_extensions']['value'] = t('Enabled'); } + // Check Composer dependencies during runtime, because drupal_check_module() + // does it when installing modules already. + if ($phase == 'runtime') { + $dependency_checker = new ExtensionDependencyChecker(DRUPAL_ROOT); + $dependency_requirements = new ExtensionDependencyRequirements($dependency_checker, \Drupal::translation()); + $requirements = array_merge($requirements, $dependency_requirements->buildRequirements(\Drupal::moduleHandler()->getModuleList())); + } + if ($phase == 'install' || $phase == 'runtime') { // Check to see if OPcache is installed. $opcache_enabled = (function_exists('opcache_get_status') && opcache_get_status()['opcache_enabled']); diff --git a/core/tests/Drupal/Tests/Core/Composer/ExtensionDependencyRequirementsTest.php b/core/tests/Drupal/Tests/Core/Composer/ExtensionDependencyRequirementsTest.php index e21b91b..1960315 100644 --- a/core/tests/Drupal/Tests/Core/Composer/ExtensionDependencyRequirementsTest.php +++ b/core/tests/Drupal/Tests/Core/Composer/ExtensionDependencyRequirementsTest.php @@ -21,14 +21,14 @@ class ExtensionDependencyRequirementsTest extends KernelTestBase { /** - * Provides data to self::testDependenciesAreMet(). + * Provides data to self::testBuildRequirements(). * * @return array[] * Every item is an array with the following items: * - One of the REQUIREMENT_* constants. * - A boolean TRUE if dependencies are met, FALSE otherwise. */ - public function providerExtensionComposerRequirements() { + public function providerBuildRequirements() { // We cannot use any of the REQUIREMENT_* constants here, because providers // are run before environments are booted. return [ @@ -40,16 +40,16 @@ public function providerExtensionComposerRequirements() { } /** - * @covers ::extensionComposerRequirements + * @covers ::buildRequirements * - * @dataProvider providerExtensionComposerRequirements + * @dataProvider providerBuildRequirements * * @param int $expected_severity * One of the REQUIREMENT_* constants. * @param bool $dependencies_met * Whether the extension's dependencies have been met. */ - public function testExtensionComposerRequirements($expected_severity, $dependencies_met) { + public function testBuildRequirements($expected_severity, $dependencies_met) { $dependency_checker = $this->getMockBuilder(ExtensionDependencyChecker::class) ->disableOriginalConstructor() ->getMock(); @@ -65,7 +65,7 @@ public function testExtensionComposerRequirements($expected_severity, $dependenc $sut = new ExtensionDependencyRequirements($dependency_checker, $string_translation); - $requirements = $sut->extensionComposerRequirements($extension); + $requirements = $sut->buildRequirements([$extension]); $this->assertCount(1, $requirements); $this->assertArrayHasKey('composer_dependencies', $requirements); $this->assertArrayHasKey('severity', $requirements['composer_dependencies']);