diff --git a/app/config/config.yml b/app/config/config.yml
index 367aa2763..0807b06ab 100644
--- a/app/config/config.yml
+++ b/app/config/config.yml
@@ -75,7 +75,10 @@ doctrine:
orm:
auto_generate_proxy_classes: "%kernel.debug%"
- auto_mapping: true
+ entity_managers:
+ default:
+ naming_strategy: wallabag_core.doctrine.prefixed_naming_strategy
+ auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
diff --git a/app/config/parameters.yml.dist b/app/config/parameters.yml.dist
index 733180133..f80f65ad8 100644
--- a/app/config/parameters.yml.dist
+++ b/app/config/parameters.yml.dist
@@ -7,6 +7,7 @@ parameters:
database_user: root
database_password: ~
database_path: "%kernel.root_dir%/../data/db/wallabag.sqlite"
+ database_table_prefix: wallabag_
mailer_transport: smtp
mailer_host: 127.0.0.1
diff --git a/build.xml b/build.xml
index cd2dfa3c8..30ed2fa1d 100644
--- a/build.xml
+++ b/build.xml
@@ -40,4 +40,11 @@
+
+
+
+
+
+
+
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
index bba2607d0..493842f79 100644
--- a/src/Wallabag/CoreBundle/Command/InstallCommand.php
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -299,7 +299,8 @@ class InstallCommand extends ContainerAwareCommand
}
/**
- * 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
*/
@@ -307,6 +308,6 @@ class InstallCommand extends ContainerAwareCommand
{
$schemaManager = $this->getContainer()->get('doctrine')->getManager()->getConnection()->getSchemaManager();
- return $schemaManager->tablesExist(array('entry'));
+ return count($schemaManager->listTableNames()) > 0 ? true : false;
}
}
diff --git a/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php b/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php
new file mode 100644
index 000000000..861a60ea4
--- /dev/null
+++ b/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php
@@ -0,0 +1,75 @@
+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()));
+ }
+}
diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php
index 9f079656e..62ea637ea 100644
--- a/src/Wallabag/CoreBundle/Entity/Config.php
+++ b/src/Wallabag/CoreBundle/Entity/Config.php
@@ -9,7 +9,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* Config
*
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\ConfigRepository")
- * @ORM\Table(name="config")
+ * @ORM\Table
* @ORM\Entity
*/
class Config
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 75aeae84b..15af105d2 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -13,7 +13,7 @@ use JMS\Serializer\Annotation\XmlRoot;
*
* @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())")
*/
@@ -121,7 +121,7 @@ class Entry
/**
* @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"})
- * @ORM\JoinTable(name="entry_tags")
+ * @ORM\JoinTable
*/
private $tags;
diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php
index 9ae5867c6..9d3c7a321 100644
--- a/src/Wallabag/CoreBundle/Entity/Tag.php
+++ b/src/Wallabag/CoreBundle/Entity/Tag.php
@@ -12,7 +12,7 @@ use Doctrine\Common\Collections\ArrayCollection;
* Tag
*
* @XmlRoot("tag")
- * @ORM\Table(name="tag")
+ * @ORM\Table
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository")
* @ExclusionPolicy("all")
*/
diff --git a/src/Wallabag/CoreBundle/Entity/User.php b/src/Wallabag/CoreBundle/Entity/User.php
index e75e3a837..1652170f7 100644
--- a/src/Wallabag/CoreBundle/Entity/User.php
+++ b/src/Wallabag/CoreBundle/Entity/User.php
@@ -13,8 +13,8 @@ use JMS\Serializer\Annotation\Expose;
/**
* User
*
- * @ORM\Table(name="user")
* @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository")
+ * @ORM\Table
* @ORM\HasLifecycleCallbacks()
* @ExclusionPolicy("all")
*/
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index 0f4db94e7..cea6c0df1 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -43,3 +43,7 @@ services:
- { name: request.param_converter, converter: username_rsstoken_converter }
arguments:
- @doctrine
+
+ wallabag_core.doctrine.prefixed_naming_strategy:
+ class: Wallabag\CoreBundle\Doctrine\Mapping\PrefixedNamingStrategy
+ arguments: [%database_table_prefix%]