diff options
author | Jeremy Benoist <jeremy.benoist@gmail.com> | 2015-10-25 15:55:19 +0100 |
---|---|---|
committer | Jeremy Benoist <jeremy.benoist@gmail.com> | 2015-11-07 14:15:33 +0100 |
commit | 735068d1814a4b7a688e1d19cd17b13e8c5da3eb (patch) | |
tree | 2f97dd9e9e11fa481c80273827f953b02c76b888 /src/Wallabag/CoreBundle/Subscriber | |
parent | bd0f3d32c9ccb8f7a1409edb960b909a5e6a096d (diff) | |
download | wallabag-735068d1814a4b7a688e1d19cd17b13e8c5da3eb.tar.gz wallabag-735068d1814a4b7a688e1d19cd17b13e8c5da3eb.tar.zst wallabag-735068d1814a4b7a688e1d19cd17b13e8c5da3eb.zip |
Add tests on TablePrefixSubscriber
Diffstat (limited to 'src/Wallabag/CoreBundle/Subscriber')
-rw-r--r-- | src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php b/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php index 8ec85e64..0019eead 100644 --- a/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php +++ b/src/Wallabag/CoreBundle/Subscriber/TablePrefixSubscriber.php | |||
@@ -8,6 +8,9 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; | |||
8 | 8 | ||
9 | /** | 9 | /** |
10 | * Puts a prefix to each table. | 10 | * Puts a prefix to each table. |
11 | * This way were used instead of using the built-in strategy from Doctrine, using `naming_strategy` | ||
12 | * Because it conflicts with the DefaultQuoteStrategy (that espace table name, like user for Postgres) | ||
13 | * see #1498 for more detail. | ||
11 | * | 14 | * |
12 | * Solution from : | 15 | * Solution from : |
13 | * - http://stackoverflow.com/a/23860613/569101 | 16 | * - http://stackoverflow.com/a/23860613/569101 |
@@ -30,17 +33,18 @@ class TablePrefixSubscriber implements EventSubscriber | |||
30 | public function loadClassMetadata(LoadClassMetadataEventArgs $args) | 33 | public function loadClassMetadata(LoadClassMetadataEventArgs $args) |
31 | { | 34 | { |
32 | $classMetadata = $args->getClassMetadata(); | 35 | $classMetadata = $args->getClassMetadata(); |
36 | |||
33 | // if we are in an inheritance hierarchy, only apply this once | 37 | // if we are in an inheritance hierarchy, only apply this once |
34 | if ($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity()) { | 38 | if ($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity()) { |
35 | return; | 39 | return; |
36 | } | 40 | } |
37 | 41 | ||
38 | $classMetadata->setTableName($this->prefix . $classMetadata->getTableName()); | 42 | $classMetadata->setTableName($this->prefix.$classMetadata->getTableName()); |
39 | 43 | ||
40 | foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) { | 44 | foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) { |
41 | if ($mapping['type'] === ClassMetadataInfo::MANY_TO_MANY && isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])) { | 45 | if ($mapping['type'] === ClassMetadataInfo::MANY_TO_MANY && isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])) { |
42 | $mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name']; | 46 | $mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name']; |
43 | $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix . $mappedTableName; | 47 | $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix.$mappedTableName; |
44 | } | 48 | } |
45 | } | 49 | } |
46 | } | 50 | } |