aboutsummaryrefslogtreecommitdiffhomepage
path: root/app/DoctrineMigrations
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2017-08-27 16:59:02 +0200
committerKevin Decherf <kevin@kdecherf.com>2017-08-27 16:59:02 +0200
commit7b4f66881d694c948aca9372da6362b8873de6bb (patch)
treeacde81a3c55cf25c4ddd3eca16e57c61aa8dee96 /app/DoctrineMigrations
parente437ad810bc0b40b6501b69d1bf81978d9c29032 (diff)
downloadwallabag-7b4f66881d694c948aca9372da6362b8873de6bb.tar.gz
wallabag-7b4f66881d694c948aca9372da6362b8873de6bb.tar.zst
wallabag-7b4f66881d694c948aca9372da6362b8873de6bb.zip
php-cs-fixer on DoctrineMigrations/Version20170719231144
Signed-off-by: Kevin Decherf <kevin@kdecherf.com>
Diffstat (limited to 'app/DoctrineMigrations')
-rw-r--r--app/DoctrineMigrations/Version20170719231144.php48
1 files changed, 24 insertions, 24 deletions
diff --git a/app/DoctrineMigrations/Version20170719231144.php b/app/DoctrineMigrations/Version20170719231144.php
index 691eae51..0f5fa75a 100644
--- a/app/DoctrineMigrations/Version20170719231144.php
+++ b/app/DoctrineMigrations/Version20170719231144.php
@@ -8,7 +8,7 @@ use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8use Symfony\Component\DependencyInjection\ContainerInterface; 8use Symfony\Component\DependencyInjection\ContainerInterface;
9 9
10/** 10/**
11 * Changed tags to lowercase 11 * Changed tags to lowercase.
12 */ 12 */
13class Version20170719231144 extends AbstractMigration implements ContainerAwareInterface 13class Version20170719231144 extends AbstractMigration implements ContainerAwareInterface
14{ 14{
@@ -22,24 +22,19 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI
22 $this->container = $container; 22 $this->container = $container;
23 } 23 }
24 24
25 private function getTable($tableName)
26 {
27 return $this->container->getParameter('database_table_prefix').$tableName;
28 }
29
30 /** 25 /**
31 * @param Schema $schema 26 * @param Schema $schema
32 */ 27 */
33 public function up(Schema $schema) 28 public function up(Schema $schema)
34 { 29 {
35 $this->skipIf($this->connection->getDatabasePlatform()->getName() == 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.'); 30 $this->skipIf($this->connection->getDatabasePlatform()->getName() === 'sqlite', 'Migration can only be executed safely on \'mysql\' or \'postgresql\'.');
36 31
37 // Find tags which need to be merged 32 // Find tags which need to be merged
38 $dupTags = $this->connection->query(" 33 $dupTags = $this->connection->query('
39 SELECT LOWER(label) 34 SELECT LOWER(label)
40 FROM ".$this->getTable('tag')." 35 FROM ' . $this->getTable('tag') . '
41 GROUP BY LOWER(label) 36 GROUP BY LOWER(label)
42 HAVING COUNT(*) > 1" 37 HAVING COUNT(*) > 1'
43 ); 38 );
44 $dupTags->execute(); 39 $dupTags->execute();
45 40
@@ -47,10 +42,10 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI
47 $label = $duplicates['LOWER(label)']; 42 $label = $duplicates['LOWER(label)'];
48 43
49 // Retrieve all duplicate tags for a given tag 44 // Retrieve all duplicate tags for a given tag
50 $tags = $this->connection->query(" 45 $tags = $this->connection->query('
51 SELECT id 46 SELECT id
52 FROM ".$this->getTable('tag')." 47 FROM ' . $this->getTable('tag') . "
53 WHERE LOWER(label) = '".$label."' 48 WHERE LOWER(label) = '" . $label . "'
54 ORDER BY id ASC" 49 ORDER BY id ASC"
55 ); 50 );
56 $tags->execute(); 51 $tags->execute();
@@ -72,24 +67,24 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI
72 // Just in case... 67 // Just in case...
73 if (count($ids) > 0) { 68 if (count($ids) > 0) {
74 // Merge tags 69 // Merge tags
75 $this->addSql(" 70 $this->addSql('
76 UPDATE ".$this->getTable('entry_tag')." 71 UPDATE ' . $this->getTable('entry_tag') . '
77 SET tag_id = ".$newId." 72 SET tag_id = ' . $newId . '
78 WHERE tag_id IN (".implode(',', $ids).")" 73 WHERE tag_id IN (' . implode(',', $ids) . ')'
79 ); 74 );
80 75
81 // Delete unused tags 76 // Delete unused tags
82 $this->addSql(" 77 $this->addSql('
83 DELETE FROM ".$this->getTable('tag')." 78 DELETE FROM ' . $this->getTable('tag') . '
84 WHERE id IN (".implode(',', $ids).")" 79 WHERE id IN (' . implode(',', $ids) . ')'
85 ); 80 );
86 } 81 }
87 } 82 }
88 83
89 // Iterate over all tags to lowercase them 84 // Iterate over all tags to lowercase them
90 $this->addSql(" 85 $this->addSql('
91 UPDATE ".$this->getTable('tag')." 86 UPDATE ' . $this->getTable('tag') . '
92 SET label = LOWER(label)" 87 SET label = LOWER(label)'
93 ); 88 );
94 } 89 }
95 90
@@ -100,4 +95,9 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI
100 { 95 {
101 throw new SkipMigrationException('Too complex ...'); 96 throw new SkipMigrationException('Too complex ...');
102 } 97 }
98
99 private function getTable($tableName)
100 {
101 return $this->container->getParameter('database_table_prefix') . $tableName;
102 }
103} 103}