aboutsummaryrefslogtreecommitdiffhomepage
path: root/app
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2017-12-11 19:38:46 +0100
committerGitHub <noreply@github.com>2017-12-11 19:38:46 +0100
commit98869090f6d113fa47dc80f9941749840c1442e8 (patch)
tree560f0e0bfc510f5780f59f405cdc3fb44e74ff27 /app
parentc31daf4725312e94102daece14b299ab62f878d1 (diff)
parent40a63c8b116e32335eded6df98fe8f4d8aa899b6 (diff)
downloadwallabag-98869090f6d113fa47dc80f9941749840c1442e8.tar.gz
wallabag-98869090f6d113fa47dc80f9941749840c1442e8.tar.zst
wallabag-98869090f6d113fa47dc80f9941749840c1442e8.zip
Merge pull request #3468 from wallabag/fix-migration-3139
Fix migration from #3139
Diffstat (limited to 'app')
-rw-r--r--app/DoctrineMigrations/Version20170719231144.php29
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