diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/DoctrineMigrations/Version20170719231144.php | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/app/DoctrineMigrations/Version20170719231144.php b/app/DoctrineMigrations/Version20170719231144.php index 0c749150..9a6f3e93 100644 --- a/app/DoctrineMigrations/Version20170719231144.php +++ b/app/DoctrineMigrations/Version20170719231144.php | |||
@@ -31,7 +31,7 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI | |||
31 | 31 | ||
32 | // Find tags which need to be merged | 32 | // Find tags which need to be merged |
33 | $dupTags = $this->connection->query(' | 33 | $dupTags = $this->connection->query(' |
34 | SELECT LOWER(label) | 34 | SELECT LOWER(label) AS lower_label |
35 | FROM ' . $this->getTable('tag') . ' | 35 | FROM ' . $this->getTable('tag') . ' |
36 | GROUP BY LOWER(label) | 36 | GROUP BY LOWER(label) |
37 | HAVING COUNT(*) > 1' | 37 | HAVING COUNT(*) > 1' |
@@ -39,16 +39,18 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI | |||
39 | $dupTags->execute(); | 39 | $dupTags->execute(); |
40 | 40 | ||
41 | foreach ($dupTags->fetchAll() as $duplicates) { | 41 | foreach ($dupTags->fetchAll() as $duplicates) { |
42 | $label = $duplicates['LOWER(label)']; | 42 | $label = $duplicates['lower_label']; |
43 | 43 | ||
44 | // Retrieve all duplicate tags for a given tag | 44 | // Retrieve all duplicate tags for a given tag |
45 | $tags = $this->connection->query(' | 45 | $tags = $this->connection->executeQuery(' |
46 | SELECT id | 46 | SELECT id |
47 | FROM ' . $this->getTable('tag') . " | 47 | FROM ' . $this->getTable('tag') . ' |
48 | WHERE LOWER(label) = '" . $label . "' | 48 | WHERE LOWER(label) = :label |
49 | ORDER BY id ASC" | 49 | ORDER BY id ASC', |
50 | [ | ||
51 | 'label' => $label, | ||
52 | ] | ||
50 | ); | 53 | ); |
51 | $tags->execute(); | ||
52 | 54 | ||
53 | $first = true; | 55 | $first = true; |
54 | $newId = null; | 56 | $newId = null; |
@@ -70,7 +72,18 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI | |||
70 | $this->addSql(' | 72 | $this->addSql(' |
71 | UPDATE ' . $this->getTable('entry_tag') . ' | 73 | UPDATE ' . $this->getTable('entry_tag') . ' |
72 | SET tag_id = ' . $newId . ' | 74 | SET tag_id = ' . $newId . ' |
73 | WHERE tag_id IN (' . implode(',', $ids) . ')' | 75 | WHERE tag_id IN (' . implode(',', $ids) . ') |
76 | AND entry_id NOT IN ( | ||
77 | SELECT entry_id | ||
78 | FROM ' . $this->getTable('entry_tag') . ' | ||
79 | WHERE tag_id = ' . $newId . ' | ||
80 | )' | ||
81 | ); | ||
82 | |||
83 | // Delete links to unused tags | ||
84 | $this->addSql(' | ||
85 | DELETE FROM ' . $this->getTable('entry_tag') . ' | ||
86 | WHERE tag_id IN (' . implode(',', $ids) . ')' | ||
74 | ); | 87 | ); |
75 | 88 | ||
76 | // Delete unused tags | 89 | // Delete unused tags |