X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=app%2FDoctrineMigrations%2FVersion20170719231144.php;fp=app%2FDoctrineMigrations%2FVersion20170719231144.php;h=9a6f3e938a0f751144715245ad0eca4f89e88f7c;hb=98869090f6d113fa47dc80f9941749840c1442e8;hp=0c749150789378417fecfbb91638b7fe49026df0;hpb=c31daf4725312e94102daece14b299ab62f878d1;p=github%2Fwallabag%2Fwallabag.git 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 // 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,16 +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->query(' + $tags = $this->connection->executeQuery(' SELECT id - FROM ' . $this->getTable('tag') . " - WHERE LOWER(label) = '" . $label . "' - ORDER BY id ASC" + FROM ' . $this->getTable('tag') . ' + WHERE LOWER(label) = :label + ORDER BY id ASC', + [ + 'label' => $label, + ] ); - $tags->execute(); $first = true; $newId = null; @@ -70,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