From 6c5904ba7fd0e3e62aebebfa07185dba73f68d6b Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Mon, 27 Nov 2017 22:48:17 +0100 Subject: Replace raw query with named parameter Fix possible issue with special chars on #3139 Signed-off-by: Kevin Decherf --- app/DoctrineMigrations/Version20170719231144.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/DoctrineMigrations/Version20170719231144.php b/app/DoctrineMigrations/Version20170719231144.php index 0c749150..265b539a 100644 --- a/app/DoctrineMigrations/Version20170719231144.php +++ b/app/DoctrineMigrations/Version20170719231144.php @@ -42,12 +42,13 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI $label = $duplicates['LOWER(label)']; // Retrieve all duplicate tags for a given tag - $tags = $this->connection->query(' + $tags = $this->connection->createQuery(' SELECT id FROM ' . $this->getTable('tag') . " - WHERE LOWER(label) = '" . $label . "' + WHERE LOWER(label) = :label ORDER BY id ASC" ); + $tags->setParameter('label', $label); $tags->execute(); $first = true; -- cgit v1.2.3 From 40a63c8b116e32335eded6df98fe8f4d8aa899b6 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 10 Dec 2017 19:31:30 +0100 Subject: migrations: fix duplicate violation during lowercase tag migration Signed-off-by: Kevin Decherf --- app/DoctrineMigrations/Version20170719231144.php | 28 +++++++++++++++++------- 1 file 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 // Find tags which need to be merged $dupTags = $this->connection->query(' - SELECT LOWER(label) + SELECT LOWER(label) AS lower_label FROM ' . $this->getTable('tag') . ' GROUP BY LOWER(label) HAVING COUNT(*) > 1' @@ -39,17 +39,18 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI $dupTags->execute(); foreach ($dupTags->fetchAll() as $duplicates) { - $label = $duplicates['LOWER(label)']; + $label = $duplicates['lower_label']; // Retrieve all duplicate tags for a given tag - $tags = $this->connection->createQuery(' + $tags = $this->connection->executeQuery(' SELECT id - FROM ' . $this->getTable('tag') . " + FROM ' . $this->getTable('tag') . ' WHERE LOWER(label) = :label - ORDER BY id ASC" + ORDER BY id ASC', + [ + 'label' => $label, + ] ); - $tags->setParameter('label', $label); - $tags->execute(); $first = true; $newId = null; @@ -71,7 +72,18 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI $this->addSql(' UPDATE ' . $this->getTable('entry_tag') . ' SET tag_id = ' . $newId . ' - WHERE tag_id IN (' . implode(',', $ids) . ')' + WHERE tag_id IN (' . implode(',', $ids) . ') + AND entry_id NOT IN ( + SELECT entry_id + FROM ' . $this->getTable('entry_tag') . ' + WHERE tag_id = ' . $newId . ' + )' + ); + + // Delete links to unused tags + $this->addSql(' + DELETE FROM ' . $this->getTable('entry_tag') . ' + WHERE tag_id IN (' . implode(',', $ids) . ')' ); // Delete unused tags -- cgit v1.2.3