}
/**
- * Check if the schema is already created
+ * Check if the schema is already created.
+ * If we found at least oen table, it means the schema exists
*
* @return boolean
*/
{
$schemaManager = $this->getContainer()->get('doctrine')->getManager()->getConnection()->getSchemaManager();
- return $schemaManager->tablesExist(array('entry'));
+ return count($schemaManager->listTableNames()) > 0 ? true : false;
}
}
--- /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()));
+ }
+}
*
* @XmlRoot("entry")
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository")
- * @ORM\Table(name="entry")
+ * @ORM\Table
* @ORM\HasLifecycleCallbacks()
* @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())")
*/
/**
* @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
- * @ORM\JoinTable(name="entry_tags")
+ * @ORM\JoinTable
*/
private $tags;