1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Cdf\BiCoreBundle\Subscriber; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Event\LoadClassMetadataEventArgs; |
6
|
|
|
use Doctrine\ORM\Id\SequenceGenerator; |
7
|
|
|
|
8
|
|
|
class TableSchemaSubscriber implements \Doctrine\Common\EventSubscriber |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
private string $schemaprefix; |
12
|
|
|
|
13
|
42 |
|
public function __construct(string $schemaprefix) |
14
|
|
|
{ |
15
|
42 |
|
$this->schemaprefix = $schemaprefix; |
16
|
|
|
} |
17
|
|
|
|
18
|
42 |
|
public function getSubscribedEvents(): array |
19
|
|
|
{ |
20
|
42 |
|
return array('loadClassMetadata'); |
21
|
|
|
} |
22
|
|
|
|
23
|
40 |
|
public function loadClassMetadata(LoadClassMetadataEventArgs $args): void |
24
|
|
|
{ |
25
|
40 |
|
$classMetadata = $args->getClassMetadata(); |
26
|
40 |
|
if (!$this->schemaprefix || ($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity())) { |
27
|
40 |
|
return; |
28
|
|
|
} |
29
|
|
|
$classMetadata->setPrimaryTable(array('name' => $this->schemaprefix . '.' . $classMetadata->getTableName())); |
30
|
|
|
foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) { |
|
|
|
|
31
|
|
|
if (\Doctrine\ORM\Mapping\ClassMetadataInfo::MANY_TO_MANY == $mapping['type'] && |
32
|
|
|
isset($classMetadata->associationMappings[$fieldName]['joinTable']['name']) |
|
|
|
|
33
|
|
|
) { |
34
|
|
|
$mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name']; |
35
|
|
|
$classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->schemaprefix . '.' . $mappedTableName; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
if ($classMetadata->isIdGeneratorSequence()) { |
40
|
|
|
$newDefinition = $classMetadata->sequenceGeneratorDefinition; |
|
|
|
|
41
|
|
|
$newDefinition['sequenceName'] = $this->schemaprefix . '.' . $newDefinition['sequenceName']; |
42
|
|
|
|
43
|
|
|
$classMetadata->setSequenceGeneratorDefinition($newDefinition); |
44
|
|
|
$em = $args->getEntityManager(); |
45
|
|
|
/** @phpstan-ignore-next-line */ |
46
|
|
|
if (isset($classMetadata->idGenerator)) { |
|
|
|
|
47
|
|
|
$sequenceGenerator = new SequenceGenerator( |
48
|
|
|
$em->getConfiguration()->getQuoteStrategy()->getSequenceName( |
49
|
|
|
$newDefinition, |
50
|
|
|
$classMetadata, |
51
|
|
|
$em->getConnection()->getDatabasePlatform() |
52
|
|
|
), |
53
|
|
|
(int)$newDefinition['allocationSize'] |
54
|
|
|
); |
55
|
|
|
$classMetadata->setIdGenerator($sequenceGenerator); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.