aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--app/DoctrineMigrations/Version20170719231144.php28
1 files changed, 20 insertions, 8 deletions
diff --git a/app/DoctrineMigrations/Version20170719231144.php b/app/DoctrineMigrations/Version20170719231144.php
index 265b539a..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,17 +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->createQuery(' 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->setParameter('label', $label);
52 $tags->execute();
53 54
54 $first = true; 55 $first = true;
55 $newId = null; 56 $newId = null;
@@ -71,7 +72,18 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI
71 $this->addSql(' 72 $this->addSql('
72 UPDATE ' . $this->getTable('entry_tag') . ' 73 UPDATE ' . $this->getTable('entry_tag') . '
73 SET tag_id = ' . $newId . ' 74 SET tag_id = ' . $newId . '
74 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) . ')'
75 ); 87 );
76 88
77 // Delete unused tags 89 // Delete unused tags