auto_generate_proxy_classes: "%kernel.debug%"
entity_managers:
default:
- naming_strategy: wallabag_core.doctrine.prefixed_naming_strategy
auto_mapping: true
# Swiftmailer Configuration
+++ /dev/null
-<?php
-
-namespace Wallabag\CoreBundle\Doctrine\Mapping;
-
-use Doctrine\ORM\Mapping\NamingStrategy;
-
-/**
- * Puts a prefix to each table.
- *
- * Solution from :
- * - http://stackoverflow.com/a/23860613/569101
- * - http://doctrine-orm.readthedocs.org/en/latest/reference/namingstrategy.html
- */
-class PrefixedNamingStrategy implements NamingStrategy
-{
- protected $prefix = '';
-
- public function __construct($prefix)
- {
- $this->prefix = (string) $prefix;
- }
-
- /**
- * {@inheritdoc}
- */
- public function classToTableName($className)
- {
- return strtolower($this->prefix.substr($className, strrpos($className, '\\') + 1));
- }
-
- /**
- * {@inheritdoc}
- */
- public function propertyToColumnName($propertyName, $className = null)
- {
- return $propertyName;
- }
-
- /**
- * {@inheritdoc}
- */
- public function referenceColumnName()
- {
- return 'id';
- }
-
- /**
- * {@inheritdoc}
- */
- public function joinColumnName($propertyName)
- {
- return $propertyName.'_'.$this->referenceColumnName();
- }
-
- /**
- * {@inheritdoc}
- */
- public function joinTableName($sourceEntity, $targetEntity, $propertyName = null)
- {
- // for join table we don't want to have both table concatenated AND prefixed
- // we just want the whole table to prefixed once
- // ie: not "wallabag_entry_wallabag_tag" but "wallabag_entry_tag"
- $target = substr($targetEntity, strrpos($targetEntity, '\\') + 1);
-
- return strtolower($this->classToTableName($sourceEntity).'_'.$target);
- }
-
- /**
- * {@inheritdoc}
- */
- public function joinKeyColumnName($entityName, $referencedColumnName = null)
- {
- return strtolower($this->classToTableName($entityName).'_'.($referencedColumnName ?: $this->referenceColumnName()));
- }
-
- /**
- * {@inheritdoc}
- */
- public function embeddedFieldToColumnName($propertyName, $embeddedColumnName, $className = null, $embeddedClassName = null)
- {
- return $propertyName.'_'.$embeddedColumnName;
- }
-}
* Config.
*
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\ConfigRepository")
- * @ORM\Table
+ * @ORM\Table(name="`config`")
* @ORM\Entity
*/
class Config
*
* @XmlRoot("entry")
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
- * @ORM\Table
+ * @ORM\Table(name="`entry`")
* @ORM\HasLifecycleCallbacks()
* @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
*/
* Tag.
*
* @XmlRoot("tag")
- * @ORM\Table
+ * @ORM\Table(name="`tag`")
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository")
* @ExclusionPolicy("all")
*/
arguments:
- @doctrine
- wallabag_core.doctrine.prefixed_naming_strategy:
- class: Wallabag\CoreBundle\Doctrine\Mapping\PrefixedNamingStrategy
+ wallabag_core.table_prefix_subscriber:
+ class: Wallabag\CoreBundle\Subscriber\TablePrefixSubscriber
arguments:
- %database_table_prefix%
+ tags:
+ - { name: doctrine.event_subscriber }
wallabag_core.graby:
class: Graby\Graby
--- /dev/null
+<?php
+
+namespace Wallabag\CoreBundle\Subscriber;
+
+use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
+use Doctrine\Common\EventSubscriber;
+use Doctrine\ORM\Mapping\ClassMetadataInfo;
+
+/**
+ * Puts a prefix to each table.
+ *
+ * Solution from :
+ * - http://stackoverflow.com/a/23860613/569101
+ * - http://doctrine-orm.readthedocs.org/en/latest/reference/namingstrategy.html
+ */
+class TablePrefixSubscriber implements EventSubscriber
+{
+ protected $prefix = '';
+
+ public function __construct($prefix)
+ {
+ $this->prefix = (string) $prefix;
+ }
+
+ public function getSubscribedEvents()
+ {
+ return array('loadClassMetadata');
+ }
+
+ public function loadClassMetadata(LoadClassMetadataEventArgs $args)
+ {
+ $classMetadata = $args->getClassMetadata();
+ // if we are in an inheritance hierarchy, only apply this once
+ if ($classMetadata->isInheritanceTypeSingleTable() && !$classMetadata->isRootEntity()) {
+ return;
+ }
+
+ $classMetadata->setTableName($this->prefix . $classMetadata->getTableName());
+
+ foreach ($classMetadata->getAssociationMappings() as $fieldName => $mapping) {
+ if ($mapping['type'] === ClassMetadataInfo::MANY_TO_MANY && isset($classMetadata->associationMappings[$fieldName]['joinTable']['name'])) {
+ $mappedTableName = $classMetadata->associationMappings[$fieldName]['joinTable']['name'];
+ $classMetadata->associationMappings[$fieldName]['joinTable']['name'] = $this->prefix . $mappedTableName;
+ }
+ }
+ }
+}
* User.
*
* @ORM\Entity(repositoryClass="Wallabag\UserBundle\Repository\UserRepository")
- * @ORM\Table
+ * @ORM\Table(name="`user`")
* @ORM\HasLifecycleCallbacks()
* @ExclusionPolicy("all")
*