Skip to content
Snippets Groups Projects
Commit 0e6ed376 authored by catch's avatar catch
Browse files

Issue #3130973 by daffie, plach, Charlie ChX Negyesi: Make the backend...

Issue #3130973 by daffie, plach, Charlie ChX Negyesi: Make the backend overridable service discovery also check the database type for an overridden service
parent e85462dd
No related branches found
No related tags found
8 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!1012Issue #3226887: Hreflang on non-canonical content pages,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10,!596Issue #3046532: deleting an entity reference field, used in a contextual view, makes the whole site unrecoverable,!496Issue #2463967: Use .user.ini file for PHP settings,!144Issue #2666286: Clean up menu_ui to conform to Drupal coding standards,!16Draft: Resolve #2081585 "History storage",!13Resolve #2903456
......@@ -37,6 +37,7 @@ class BackendCompilerPass implements CompilerPassInterface {
* {@inheritdoc}
*/
public function process(ContainerBuilder $container) {
$driver_backend = NULL;
if ($container->hasParameter('default_backend')) {
$default_backend = $container->getParameter('default_backend');
// Opt out from the default backend.
......@@ -46,7 +47,8 @@ public function process(ContainerBuilder $container) {
}
else {
try {
$default_backend = $container->get('database')->driver();
$driver_backend = $container->get('database')->driver();
$default_backend = $container->get('database')->databaseType();
$container->set('database', NULL);
}
catch (\Exception $e) {
......@@ -62,7 +64,10 @@ public function process(ContainerBuilder $container) {
if ($container->hasAlias($id)) {
continue;
}
if ($container->hasDefinition("$default_backend.$id") || $container->hasAlias("$default_backend.$id")) {
if ($container->hasDefinition("$driver_backend.$id") || $container->hasAlias("$driver_backend.$id")) {
$container->setAlias($id, new Alias("$driver_backend.$id"));
}
elseif ($container->hasDefinition("$default_backend.$id") || $container->hasAlias("$default_backend.$id")) {
$container->setAlias($id, new Alias("$default_backend.$id"));
}
}
......
......@@ -87,6 +87,25 @@ public function providerTestProcess() {
$container->setParameter('default_backend', '');
$data[] = [$prefix . 'Default', $container];
// Set the mysql and the DrivertestMysql service, now the DrivertestMysql
// service, as it is the driver override, should be used.
$container = $this->getDrivertestMysqlContainer($service);
$container->setDefinition('mysql.service', new Definition(__NAMESPACE__ . '\\ServiceClassMysql'));
$container->setDefinition('DrivertestMysql.service', new Definition(__NAMESPACE__ . '\\ServiceClassDrivertestMysql'));
$data[] = [$prefix . 'DrivertestMysql', $container];
// Set the mysql service, now the mysql service, as it is the database_type
// override, should be used.
$container = $this->getDrivertestMysqlContainer($service);
$container->setDefinition('mysql.service', new Definition(__NAMESPACE__ . '\\ServiceClassMysql'));
$data[] = [$prefix . 'Mysql', $container];
// Set the DrivertestMysql service, now the DrivertestMysql service, as it
// is the driver override, should be used.
$container = $this->getDrivertestMysqlContainer($service);
$container->setDefinition('DrivertestMysql.service', new Definition(__NAMESPACE__ . '\\ServiceClassDrivertestMysql'));
$data[] = [$prefix . 'DrivertestMysql', $container];
return $data;
}
......@@ -126,6 +145,24 @@ protected function getMysqlContainer($service) {
return $container;
}
/**
* Creates a container with a DrivertestMysql database mock definition in it.
*
* This is necessary because the container clone does not clone the parameter
* bag so the setParameter() call effects the parent container as well.
*
* @param $service
*
* @return \Symfony\Component\DependencyInjection\ContainerBuilder
*/
protected function getDrivertestMysqlContainer($service) {
$container = new ContainerBuilder();
$container->setDefinition('service', $service);
$mock = $this->getMockBuilder('Drupal\driver_test\Driver\Database\DrivertestMysql\Connection')->setMethods(NULL)->disableOriginalConstructor()->getMock();
$container->set('database', $mock);
return $container;
}
}
class ServiceClassDefault {
......@@ -139,3 +176,6 @@ class ServiceClassMariaDb extends ServiceClassMysql {
class ServiceClassSqlite extends ServiceClassDefault {
}
class ServiceClassDrivertestMysql extends ServiceClassDefault {
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment