Closed alejgr closed 2 years ago
@alejgarciarodriguez and @schmittjoh, I have the same doubt. Have you found a solution?
My company have others database patterns. I need choose a database schema and override the table fields.
No, sorry. I am using only one connection/em now. Still interested in this option though. Any ideas?
https://github.com/schmittjoh/JMSJobQueueBundle/blob/master/Command/ScheduleCommand.php#L33
I'm thinking of overwriting the ClassMetadataFactory class (injecting schema).
See: https://symfony.com/doc/3.3/reference/configuration/doctrine.html#shortened-configuration-syntax
Custom Mapping in Bundle: https://symfony.com/doc/3.3/reference/configuration/doctrine.html#custom-mapping-entities-in-a-bundle
It worked, But only table overwritten.
How to exchange one class for another?
Look:
services:
AppBundle\EventListener\ClassMetadataListener:
tags:
- { name: doctrine.event_listener, event: loadClassMetadata }
<?php
namespace AppBundle\EventListener;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use JMS\JobQueueBundle\Entity\CronJob;
use JMS\JobQueueBundle\Entity\Job;
/**
* Class ExceptionListener
*
* @package AppBundle\EventListener
* @see http://symfony.com/doc/current/event_dispatcher.html
*/
class ClassMetadataListener
{
/**
* Run when Doctrine ORM metadata is loaded.
* If class is Job or CronJob, override table and schema names
*
* @param LoadClassMetadataEventArgs $eventArgs
*/
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
{
$classMetadata = $eventArgs->getClassMetadata();
if ($classMetadata->name === Job::class) {
$classMetadata->setPrimaryTable([
'name' => 'TB_JOB',
'schema' => 'OID'
]);
} else if ($classMetadata->name === CronJob::class) {
$classMetadata->setPrimaryTable([
'name' => 'TB_CRON_JOB',
'schema' => 'OID'
]);
}
}
}
Changing the column name:
https://gist.github.com/ichbinbarbosa/04f1f6052456d2267ce524aff06b4d7b
My solution is a workaround.
Maybe the best solution is similar to FOSUserBundle:
https://symfony.com/doc/master/bundles/FOSUserBundle/index.html#step-5-configure-the-fosuserbundle
Another problem occurred,
Only when i run composer install
inside of Dockerfile, i receiver a database timeout exception:
...
Script Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::clearCache handling the symfony-scripts event terminated with an exception
[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command:
PHP Fatal error: Uncaught PDOException: SQLSTATE[HYT00]: [unixODBC][Microsoft][ODBC Driver 17 for SQL Server]Login timeout expired in /var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:46
...
But I maked other workaround to fix this problem =). Look:
I canceled the attempt and created a new connection.
I had to fix a BUG in Application. Look:
https://gist.github.com/ichbinbarbosa/9688f6da91339697b873c1ace7e204fd
serialize($ex ? FlattenException::create($ex) : null)
$ex ? serialize(FlattenException::create($ex)) : null
Is there any way to use a different connection or entity manager for this bundle?