Commit 8e5557e0 authored by Bernhard Schussek's avatar Bernhard Schussek

Made connections configurable

parent e9f8e296
......@@ -15,6 +15,7 @@ namespace Cwd\DataDoctrineORMBundle;
use Cwd\DataBundle\DependencyInjection\Compiler\AutoDiscoverRepositoryImplementationsPass;
use Cwd\DataBundle\DependencyInjection\Compiler\GenerateRepositoryClassesPass;
use Cwd\DataDoctrineORMBundle\DependencyInjection\Compiler\InjectConnectionsPass;
use Cwd\DataDoctrineORMBundle\DependencyInjection\Compiler\RegisterFunctionsPass;
use Cwd\DataDoctrineORMBundle\DependencyInjection\Compiler\RegisterTypesPass;
use Cwd\DataDoctrineORMBundle\DependencyInjection\CwdDataDoctrineORMExtension;
......@@ -41,5 +42,6 @@ class CwdDataDoctrineORMBundle extends Bundle
));
$container->addCompilerPass(new RegisterTypesPass());
$container->addCompilerPass(new RegisterFunctionsPass());
$container->addCompilerPass(new InjectConnectionsPass());
}
}
<?php
/*
* This file is part of neos-crm
*
* (c) 2017 Ludwig Ruderstaller <lr@cwd.at>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Cwd\DataDoctrineORMBundle\DependencyInjection\Compiler;
use Cwd\DataDoctrineORMBundle\Auditing\ORMChangeTimeRecorder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
class InjectConnectionsPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $containerBuilder): void
{
if (!$containerBuilder->hasParameter('cwd_data_doctrine_orm.connection')) {
return;
}
$changeTimeRecorder = $containerBuilder->getDefinition(ORMChangeTimeRecorder::class);
$connectionName = $containerBuilder->getParameter('cwd_data_doctrine_orm.connection');
$tags = $changeTimeRecorder->getTags();
if (!isset($tags['doctrine.event_listener'])) {
return;
}
foreach ($tags['doctrine.event_listener'] as $key => $payload) {
$payload['connection'] = $connectionName;
}
$changeTimeRecorder->setTags($tags);
}
}
......@@ -37,6 +37,9 @@ class Configuration implements ConfigurationInterface
->booleanNode('enabled')
->defaultFalse()
->end()
->scalarNode('connection')
->defaultValue('default')
->end()
->scalarNode('entity_manager')
->defaultValue('default')
->end()
......
......@@ -46,6 +46,11 @@ class CwdDataDoctrineORMExtension extends ConfigurableExtension
return;
}
$container->setParameter(
'cwd_data_doctrine_orm.connection',
$mergedConfig['connection']
);
$container->setParameter(
'cwd_data_doctrine_orm.entity_manager',
$mergedConfig['entity_manager']
......
......@@ -8,8 +8,8 @@ services:
Cwd\DataDoctrineORMBundle\Auditing\ORMChangeTimeRecorder:
class: Cwd\DataDoctrineORMBundle\Auditing\ORMChangeTimeRecorder
tags:
- { name: doctrine.event_listener, event: prePersist, connection: default }
- { name: doctrine.event_listener, event: preUpdate, connection: default }
- { name: doctrine.event_listener, event: prePersist }
- { name: doctrine.event_listener, event: preUpdate }
Cwd\DataDoctrineORMBundle\Schema\ReferencesOption:
class: Cwd\DataDoctrineORMBundle\Schema\ReferencesOption
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment