diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Wallabag/CoreBundle/Command/InstallCommand.php | 5 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php | 75 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Config.php | 2 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Entry.php | 4 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/Tag.php | 2 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Entity/User.php | 2 | ||||
-rw-r--r-- | src/Wallabag/CoreBundle/Resources/config/services.yml | 4 |
7 files changed, 87 insertions, 7 deletions
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php index bba2607d..493842f7 100644 --- a/src/Wallabag/CoreBundle/Command/InstallCommand.php +++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php | |||
@@ -299,7 +299,8 @@ class InstallCommand extends ContainerAwareCommand | |||
299 | } | 299 | } |
300 | 300 | ||
301 | /** | 301 | /** |
302 | * Check if the schema is already created | 302 | * Check if the schema is already created. |
303 | * If we found at least oen table, it means the schema exists | ||
303 | * | 304 | * |
304 | * @return boolean | 305 | * @return boolean |
305 | */ | 306 | */ |
@@ -307,6 +308,6 @@ class InstallCommand extends ContainerAwareCommand | |||
307 | { | 308 | { |
308 | $schemaManager = $this->getContainer()->get('doctrine')->getManager()->getConnection()->getSchemaManager(); | 309 | $schemaManager = $this->getContainer()->get('doctrine')->getManager()->getConnection()->getSchemaManager(); |
309 | 310 | ||
310 | return $schemaManager->tablesExist(array('entry')); | 311 | return count($schemaManager->listTableNames()) > 0 ? true : false; |
311 | } | 312 | } |
312 | } | 313 | } |
diff --git a/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php b/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php new file mode 100644 index 00000000..861a60ea --- /dev/null +++ b/src/Wallabag/CoreBundle/Doctrine/Mapping/PrefixedNamingStrategy.php | |||
@@ -0,0 +1,75 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Doctrine\Mapping; | ||
4 | |||
5 | use Doctrine\ORM\Mapping\NamingStrategy; | ||
6 | |||
7 | /** | ||
8 | * Puts a prefix to each table. | ||
9 | * | ||
10 | * Solution from : | ||
11 | * - http://stackoverflow.com/a/23860613/569101 | ||
12 | * - http://doctrine-orm.readthedocs.org/en/latest/reference/namingstrategy.html | ||
13 | */ | ||
14 | class PrefixedNamingStrategy implements NamingStrategy | ||
15 | { | ||
16 | protected $prefix = ''; | ||
17 | |||
18 | public function __construct($prefix) | ||
19 | { | ||
20 | $this->prefix = (string) $prefix; | ||
21 | } | ||
22 | |||
23 | /** | ||
24 | * {@inheritdoc} | ||
25 | */ | ||
26 | public function classToTableName($className) | ||
27 | { | ||
28 | return strtolower($this->prefix . substr($className, strrpos($className, '\\') + 1)); | ||
29 | } | ||
30 | |||
31 | /** | ||
32 | * {@inheritdoc} | ||
33 | */ | ||
34 | public function propertyToColumnName($propertyName, $className = null) | ||
35 | { | ||
36 | return $propertyName; | ||
37 | } | ||
38 | |||
39 | /** | ||
40 | * {@inheritdoc} | ||
41 | */ | ||
42 | public function referenceColumnName() | ||
43 | { | ||
44 | return 'id'; | ||
45 | } | ||
46 | |||
47 | /** | ||
48 | * {@inheritdoc} | ||
49 | */ | ||
50 | public function joinColumnName($propertyName) | ||
51 | { | ||
52 | return $propertyName . '_' . $this->referenceColumnName(); | ||
53 | } | ||
54 | |||
55 | /** | ||
56 | * {@inheritdoc} | ||
57 | */ | ||
58 | public function joinTableName($sourceEntity, $targetEntity, $propertyName = null) | ||
59 | { | ||
60 | // for join table we don't want to have both table concatenated AND prefixed | ||
61 | // we just want the whole table to prefixed once | ||
62 | // ie: not "wallabag_entry_wallabag_tag" but "wallabag_entry_tag" | ||
63 | $target = substr($targetEntity, strrpos($targetEntity, '\\') + 1); | ||
64 | |||
65 | return strtolower($this->classToTableName($sourceEntity) . '_' .$target); | ||
66 | } | ||
67 | |||
68 | /** | ||
69 | * {@inheritdoc} | ||
70 | */ | ||
71 | public function joinKeyColumnName($entityName, $referencedColumnName = null) | ||
72 | { | ||
73 | return strtolower($this->classToTableName($entityName) . '_' .($referencedColumnName ?: $this->referenceColumnName())); | ||
74 | } | ||
75 | } | ||
diff --git a/src/Wallabag/CoreBundle/Entity/Config.php b/src/Wallabag/CoreBundle/Entity/Config.php index 9f079656..62ea637e 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; | |||
9 | * Config | 9 | * Config |
10 | * | 10 | * |
11 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\ConfigRepository") | 11 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\ConfigRepository") |
12 | * @ORM\Table(name="config") | 12 | * @ORM\Table |
13 | * @ORM\Entity | 13 | * @ORM\Entity |
14 | */ | 14 | */ |
15 | class Config | 15 | class Config |
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php index 75aeae84..15af105d 100644 --- a/src/Wallabag/CoreBundle/Entity/Entry.php +++ b/src/Wallabag/CoreBundle/Entity/Entry.php | |||
@@ -13,7 +13,7 @@ use JMS\Serializer\Annotation\XmlRoot; | |||
13 | * | 13 | * |
14 | * @XmlRoot("entry") | 14 | * @XmlRoot("entry") |
15 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository") | 15 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\EntryRepository") |
16 | * @ORM\Table(name="entry") | 16 | * @ORM\Table |
17 | * @ORM\HasLifecycleCallbacks() | 17 | * @ORM\HasLifecycleCallbacks() |
18 | * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())") | 18 | * @Hateoas\Relation("self", href = "expr('/api/entries/' ~ object.getId())") |
19 | */ | 19 | */ |
@@ -121,7 +121,7 @@ class Entry | |||
121 | 121 | ||
122 | /** | 122 | /** |
123 | * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"}) | 123 | * @ORM\ManyToMany(targetEntity="Tag", inversedBy="entries", cascade={"persist"}) |
124 | * @ORM\JoinTable(name="entry_tags") | 124 | * @ORM\JoinTable |
125 | */ | 125 | */ |
126 | private $tags; | 126 | private $tags; |
127 | 127 | ||
diff --git a/src/Wallabag/CoreBundle/Entity/Tag.php b/src/Wallabag/CoreBundle/Entity/Tag.php index 9ae5867c..9d3c7a32 100644 --- a/src/Wallabag/CoreBundle/Entity/Tag.php +++ b/src/Wallabag/CoreBundle/Entity/Tag.php | |||
@@ -12,7 +12,7 @@ use Doctrine\Common\Collections\ArrayCollection; | |||
12 | * Tag | 12 | * Tag |
13 | * | 13 | * |
14 | * @XmlRoot("tag") | 14 | * @XmlRoot("tag") |
15 | * @ORM\Table(name="tag") | 15 | * @ORM\Table |
16 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository") | 16 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\TagRepository") |
17 | * @ExclusionPolicy("all") | 17 | * @ExclusionPolicy("all") |
18 | */ | 18 | */ |
diff --git a/src/Wallabag/CoreBundle/Entity/User.php b/src/Wallabag/CoreBundle/Entity/User.php index e75e3a83..1652170f 100644 --- a/src/Wallabag/CoreBundle/Entity/User.php +++ b/src/Wallabag/CoreBundle/Entity/User.php | |||
@@ -13,8 +13,8 @@ use JMS\Serializer\Annotation\Expose; | |||
13 | /** | 13 | /** |
14 | * User | 14 | * User |
15 | * | 15 | * |
16 | * @ORM\Table(name="user") | ||
17 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository") | 16 | * @ORM\Entity(repositoryClass="Wallabag\CoreBundle\Repository\UserRepository") |
17 | * @ORM\Table | ||
18 | * @ORM\HasLifecycleCallbacks() | 18 | * @ORM\HasLifecycleCallbacks() |
19 | * @ExclusionPolicy("all") | 19 | * @ExclusionPolicy("all") |
20 | */ | 20 | */ |
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml index 0f4db94e..cea6c0df 100644 --- a/src/Wallabag/CoreBundle/Resources/config/services.yml +++ b/src/Wallabag/CoreBundle/Resources/config/services.yml | |||
@@ -43,3 +43,7 @@ services: | |||
43 | - { name: request.param_converter, converter: username_rsstoken_converter } | 43 | - { name: request.param_converter, converter: username_rsstoken_converter } |
44 | arguments: | 44 | arguments: |
45 | - @doctrine | 45 | - @doctrine |
46 | |||
47 | wallabag_core.doctrine.prefixed_naming_strategy: | ||
48 | class: Wallabag\CoreBundle\Doctrine\Mapping\PrefixedNamingStrategy | ||
49 | arguments: [%database_table_prefix%] | ||