Skip to content
Snippets Groups Projects
Commit d65080de authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #12069 TIME 1:10 delete empty tags after migration

parent a4f22a6c
No related branches found
No related tags found
No related merge requests found
......@@ -130,6 +130,56 @@ foreach ($customs as $custom) {
]);
}
// Get all empty tags
$emptyTags = TagModel::get([
'select' => ['id', 'links', 'parent_id'],
'where' => ["replace(label, ' ', '') = ''"],
'orderBy' => ['id desc']
]);
// Remove resources links + tag links
foreach ($emptyTags as $emptyTag) {
ResourceTagModel::delete([
'where' => ['tag_id = ?'],
'data' => [$emptyTag['id']]
]);
$links = json_decode($emptyTag['links'], true);
foreach ($links as $link) {
TagModel::update([
'postSet' => ['links' => "links - '{$emptyTag['id']}'"],
'where' => ['id = ?'],
'data' => [$link]
]);
TagModel::update([
'postSet' => ['links' => "links - '{$link}'"],
'where' => ['id = ?'],
'data' => [$emptyTag['id']]
]);
}
$parentId = TagModel::getById([
'select' => ['parent_id'],
'id' => $emptyTag['id']
]);
$parentId = $parentId['parent_id'];
TagModel::update([
'set' => ['parent_id' => $parentId],
'where' => ['parent_id = ?'],
'data' => [$emptyTag['id']]
]);
}
// Delete tags
$emptyTags = array_column($emptyTags, 'id');
$nbEmptyTags = count($emptyTags);
if (!empty($emptyTags)) {
TagModel::delete([
'where' => ['id in (?)'],
'data' => [$emptyTags]
]);
}
printf("Migration du thesaurus dans la table tags (CUSTOM {$custom}) : " . $migrated . " termes migrés. ($parentMigrated liens de parentés migrés, $parentNotMigrated non migrés, $linksMigrated associations migrés, $linksNotMigrated non migrés)\n");
printf("Migration du thesaurus dans la table tags (CUSTOM {$custom}) : " . $migrated . " termes migrés. ($parentMigrated liens de parentés migrés, $parentNotMigrated non migrés, $linksMigrated associations migrés, $linksNotMigrated non migrés, $nbEmptyTags tag(s) vide supprimé(s))\n");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment