diff -u b/core/lib/Drupal/Core/DependencyInjection/Compiler/BackendCompilerPass.php b/core/lib/Drupal/Core/DependencyInjection/Compiler/BackendCompilerPass.php --- b/core/lib/Drupal/Core/DependencyInjection/Compiler/BackendCompilerPass.php +++ b/core/lib/Drupal/Core/DependencyInjection/Compiler/BackendCompilerPass.php @@ -42,7 +42,11 @@ * {@inheritdoc} */ public function process(ContainerBuilder $container) { - $default_backend = $container->hasParameter('default_backend') ? $container->getParameter('default_backend') : 'mysql'; + $default_backend = $container->hasParameter('default_backend') ? $container->getParameter('default_backend') : NULL; + // No default backend was configured, so continue as normal. + if (!isset($default_backend)) { + return; + } foreach ($container->findTaggedServiceIds('backend_overridable') as $id => $attributes) { // If the service is already an alias it is not the original backend, so @@ -53,8 +57,7 @@ - if ($container->hasDefinition("$default_backend.$id")) { - $container->setDefinition($id, new Alias("$default_backend.$id")); + if ($container->hasDefinition("$default_backend.$id") || $container->hasAlias("$default_backend.$id")) { + $container->setAlias($id, new Alias("$default_backend.$id")); } } } } - only in patch2: unchanged: --- a/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php +++ b/core/lib/Drupal/Core/Installer/Form/SiteSettingsForm.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Installer\Form; +use Drupal\Component\Serialization\Yaml; use Drupal\Component\Utility\Crypt; use Drupal\Core\Database\Database; use Drupal\Core\Form\FormBase; @@ -156,6 +157,12 @@ public function submitForm(array &$form, array &$form_state) { drupal_rewrite_settings($settings); + $conf_path = './' . conf_path(FALSE); + $services_file = $conf_path . '/services.yml'; + // @TODO Should we put some logic in here to ensure that the file is read + // and writable? + file_put_contents($services_file, Yaml::encode(array('parameters' => array('default_backend' => $database['driver'])))); + // Add the config directories to settings.php. drupal_install_config_directories(); only in patch2: unchanged: --- a/core/modules/system/src/Tests/Installer/InstallerTest.php +++ b/core/modules/system/src/Tests/Installer/InstallerTest.php @@ -30,6 +30,9 @@ public function testInstaller() { $this->assertRaw(t('Congratulations, you installed @drupal!', array( '@drupal' => drupal_install_profile_distribution_name(), ))); + + // Ensures that the services YML file got written and read. + $this->assertEqual(\Drupal::getContainer()->getParameter('default_backend'), \Drupal::database()->driver()); } } only in patch2: unchanged: --- /dev/null +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/BackendCompilerPassTest.php @@ -0,0 +1,93 @@ +backendPass = new BackendCompilerPass(); + } + + /** + * Tests the process method. + * + * @param string $expected_class + * The expected used class. + * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container + * The container. + * + * @dataProvider providerTestProcess + * + * @covers ::process + */ + public function testProcess($expected_class, ContainerBuilder $container) { + $this->backendPass->process($container); + + $this->assertInstanceOf($expected_class, $container->get('service')); + } + + /** + * Provides test data for testProcess(). + * + * @return array + */ + public function providerTestProcess() { + $data = array(); + // Add a container with no set default_backend. + $container = new ContainerBuilder(); + $prefix = '\\' . __NAMESPACE__ . '\\'; + $container->setDefinition('service', (new Definition($prefix . 'ServiceClassDefault'))->addTag('backend_overridable')); + $container->setDefinition('mysql.service', new Definition($prefix . 'ServiceClassMysql')); + + $data[] = array($prefix . 'ServiceClassDefault', $container); + + // Set the default_backend so the mysql service should be used. + $container = clone $container; + $container->setParameter('default_backend', 'mysql'); + $data[] = array($prefix . 'ServiceClassMysql', $container); + + // Configure a manual alias for the service, so ensure that it is not + // overridden by the default backend. + $container = clone $container; + $container->setDefinition('mariadb.service', new Definition($prefix . 'ServiceClassMariaDb')); + $container->setAlias('service', new Alias('mariadb.service')); + $data[] = array($prefix . 'ServiceClassMariaDb', $container); + + return $data; + } + +} + +class ServiceClassDefault { +} + +class ServiceClassMysql extends ServiceClassDefault { +} + +class ServiceClassMariaDb extends ServiceClassMysql { +}