1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\BiCoreBundle\Subscriber; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Event\LoadClassMetadataEventArgs; |
6
|
|
|
use Doctrine\ORM\Mapping\ClassMetadataInfo; |
7
|
|
|
use Doctrine\ORM\Id\SequenceGenerator; |
8
|
|
|
|
9
|
|
|
class TableSchemaSubscriber implements \Doctrine\Common\EventSubscriber |
10
|
|
|
{ |
11
|
|
|
public $container; |
12
|
|
|
|
13
|
43 |
|
public function getSubscribedEvents() |
14
|
|
|
{ |
15
|
43 |
|
return array('loadClassMetadata'); |
16
|
|
|
} |
17
|
|
|
|
18
|
30 |
|
public function loadClassMetadata(LoadClassMetadataEventArgs $args) |
19
|
|
|
{ |
20
|
30 |
|
$tableschema = $this->container->getParameter('bi_core.table_schema'); |
21
|
30 |
|
if ($tableschema != '') { |
22
|
|
|
$classMetadata = $args->getClassMetadata(); |
23
|
|
|
|
24
|
|
|
$classMetadata->setPrimaryTable(array('name' => $tableschema.'.'.$classMetadata->getTableName())); |
25
|
|
|
foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) { |
26
|
|
|
$jointablename = $classMetadata->associationMappings[$fieldName]['joinTable']['name']; |
27
|
|
|
if ($mapping['type'] == ClassMetadataInfo::MANY_TO_MANY && isset($jointablename)) { |
28
|
|
|
$mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name']; |
|
|
|
|
29
|
|
|
$classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $tableschema.'.'.$mappedTableName; |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
if ($classMetadata->isIdGeneratorSequence()) { |
33
|
|
|
$newDefinition = $classMetadata->sequenceGeneratorDefinition; |
|
|
|
|
34
|
|
|
$newDefinition['sequenceName'] = $tableschema.'.'.$newDefinition['sequenceName']; |
35
|
|
|
|
36
|
|
|
$classMetadata->setSequenceGeneratorDefinition($newDefinition); |
37
|
|
|
$em = $args->getEntityManager(); |
38
|
|
|
if (isset($classMetadata->idGenerator)) { |
39
|
|
|
$sequncename = $em->getConfiguration()->getQuoteStrategy() |
|
|
|
|
40
|
|
|
->getSequenceName($newDefinition, $classMetadata, $em->getConnection()->getDatabasePlatform()); |
41
|
|
|
$allocationSize = $newDefinition['allocationSize']; |
|
|
|
|
42
|
|
|
$sequenceGenerator = new SequenceGenerator($sequncename, $allocationSize); |
43
|
|
|
$classMetadata->setIdGenerator($sequenceGenerator); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
30 |
|
} |
48
|
|
|
} |
49
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.