mirror of
https://github.com/wallabag/wallabag.git
synced 2024-11-29 12:31:02 +00:00
Merge pull request #3468 from wallabag/fix-migration-3139
Fix migration from #3139
This commit is contained in:
commit
98869090f6
1 changed files with 21 additions and 8 deletions
|
@ -31,7 +31,7 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI
|
||||||
|
|
||||||
// Find tags which need to be merged
|
// Find tags which need to be merged
|
||||||
$dupTags = $this->connection->query('
|
$dupTags = $this->connection->query('
|
||||||
SELECT LOWER(label)
|
SELECT LOWER(label) AS lower_label
|
||||||
FROM ' . $this->getTable('tag') . '
|
FROM ' . $this->getTable('tag') . '
|
||||||
GROUP BY LOWER(label)
|
GROUP BY LOWER(label)
|
||||||
HAVING COUNT(*) > 1'
|
HAVING COUNT(*) > 1'
|
||||||
|
@ -39,16 +39,18 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI
|
||||||
$dupTags->execute();
|
$dupTags->execute();
|
||||||
|
|
||||||
foreach ($dupTags->fetchAll() as $duplicates) {
|
foreach ($dupTags->fetchAll() as $duplicates) {
|
||||||
$label = $duplicates['LOWER(label)'];
|
$label = $duplicates['lower_label'];
|
||||||
|
|
||||||
// Retrieve all duplicate tags for a given tag
|
// Retrieve all duplicate tags for a given tag
|
||||||
$tags = $this->connection->query('
|
$tags = $this->connection->executeQuery('
|
||||||
SELECT id
|
SELECT id
|
||||||
FROM ' . $this->getTable('tag') . "
|
FROM ' . $this->getTable('tag') . '
|
||||||
WHERE LOWER(label) = '" . $label . "'
|
WHERE LOWER(label) = :label
|
||||||
ORDER BY id ASC"
|
ORDER BY id ASC',
|
||||||
|
[
|
||||||
|
'label' => $label,
|
||||||
|
]
|
||||||
);
|
);
|
||||||
$tags->execute();
|
|
||||||
|
|
||||||
$first = true;
|
$first = true;
|
||||||
$newId = null;
|
$newId = null;
|
||||||
|
@ -70,6 +72,17 @@ class Version20170719231144 extends AbstractMigration implements ContainerAwareI
|
||||||
$this->addSql('
|
$this->addSql('
|
||||||
UPDATE ' . $this->getTable('entry_tag') . '
|
UPDATE ' . $this->getTable('entry_tag') . '
|
||||||
SET tag_id = ' . $newId . '
|
SET tag_id = ' . $newId . '
|
||||||
|
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) . ')'
|
WHERE tag_id IN (' . implode(',', $ids) . ')'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue