// get all merge queries together
$sqls = array(
// 1. update entity tag entries
- "UPDATE civicrm_entity_tag SET tag_id = %1 WHERE tag_id = %2",
+ "UPDATE IGNORE civicrm_entity_tag SET tag_id = %1 WHERE tag_id = %2",
// 2. update used_for info for tag B
"UPDATE civicrm_tag SET used_for = '{$usedFor}' WHERE id = %1",
// 3. remove tag A, if tag A is getting merged into B
"DELETE FROM civicrm_tag WHERE id = %2",
// 4. remove duplicate entity tag records
"DELETE et2.* from civicrm_entity_tag et1 INNER JOIN civicrm_entity_tag et2 ON et1.entity_table = et2.entity_table AND et1.entity_id = et2.entity_id AND et1.tag_id = et2.tag_id WHERE et1.id < et2.id",
+ // 5. remove orphaned entity_tags
+ "DELETE FROM civicrm_entity_tag WHERE tag_id = %2",
);
$tables = array('civicrm_entity_tag', 'civicrm_tag');