-
-
Notifications
You must be signed in to change notification settings - Fork 261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
dbal connection hardcoded to default #140
Comments
Same problem here. |
As working workaround I could suggest to create a compiler pass like this:
Be sure to move |
Hi, namespace AppBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
* Override harcoded Doctrine configuration in SimpleThingsEntityAuditBundle.
*
* Be sure to add this pass in AppKernel::prepareContainer method,
* BEFORE calling parent::prepareContainer().
*
* @see https://github.com/simplethings/EntityAudit/issues/140
*
*/
class OverrideEntityAuditConfigurationCompilerPass implements CompilerPassInterface
{
const CONNECTION_NAME = 'your_connection_name';
const ENTITY_MANAGER_ID = 'doctrine.orm.your_entity_manager';
public function process(ContainerBuilder $container)
{
$this->overrideEntityManager($container);
$this->overrideDoctrineSubscribers($container);
}
private function overrideEntityManager(ContainerBuilder $container)
{
if ($container->hasDefinition('simplethings_entityaudit.reader')) {
$definition = $container->getDefinition('simplethings_entityaudit.reader');
$definition->replaceArgument(0, new Reference(self::ENTITY_MANAGER_ID));
}
}
private function overrideDoctrineSubscribers(ContainerBuilder $container)
{
$servicesToOverride = [
'simplethings_entityaudit.log_revisions_listener',
'simplethings_entityaudit.create_schema_listener',
];
foreach ($servicesToOverride as $serviceId) {
if (!$container->hasDefinition($serviceId)) {
continue;
}
$definition = $container->getDefinition($serviceId);
if ($definition->hasTag('doctrine.event_subscriber')) {
$tags = $definition->getTag('doctrine.event_subscriber');
$connectionTags = $tags[0];
if (isset($connectionTags['connection'])) {
unset($connectionTags['connection']);
}
$connectionTags['connection'] = self::CONNECTION_NAME;
$definition->clearTag('doctrine.event_subscriber');
$definition->addTag('doctrine.event_subscriber', $connectionTags);
}
}
}
} And then in app/AppKernel.php use Symfony\Component\DependencyInjection\ContainerBuilder;
use AppBundle\DependencyInjection\Compiler\OverrideEntityAuditConfigurationCompilerPass;
class AppKernel extends Kernel
{
// ...
/**
* Prepares the ContainerBuilder before it is compiled.
*
* @param ContainerBuilder $container A ContainerBuilder instance
*/
protected function prepareContainer(ContainerBuilder $container)
{
$container->addCompilerPass(new OverrideEntityAuditConfigurationCompilerPass());
parent::prepareContainer($container);
}
} |
@ju1ius did this solution also work for multiple connections? |
should be solved by #257 |
I have a problem with database conections. I have a sqlite database for development and a sqlserver database for other enviroments.
I have this config file
config.yml
parameters.yml.dev
parameters.yml.prod
In production enviroment the audit bundle does`t work. I think this is due to de bundle always use de hardcode "default" connection.
In fact, if i rename the "default" connection name to "sqlite" and change
It have this error during "composer install"
he Doctrine connection "default" referenced in service "simplethings_entityaudit.log_revisions_l│
istener" does not exist. Available connections names: sqlite, sqlserve
I see the service and in fact, it have hardcode the connection default
Any suggestion?
The text was updated successfully, but these errors were encountered: