- if (!empty($newTagIds)) {
- // New tag ids can be inserted directly into the db table.
- $insertValues = array();
- foreach ($newTagIds as $tagId) {
- $insertValues[] = "( {$tagId}, {$entityId}, '{$entityTable}' ) ";
- }
- $insertSQL = 'INSERT INTO civicrm_entity_tag ( tag_id, entity_id, entity_table )
- VALUES ' . implode(', ', $insertValues) . ';';
- CRM_Core_DAO::executeQuery($insertSQL);
+ CRM_Core_DAO::executeQuery($deleteSQL);
+
+ if (!empty($newTagIds)) {
+ // New tag ids can be inserted directly into the db table.
+ $insertValues = array();
+ foreach ($newTagIds as $tagId) {
+ $insertValues[] = "( {$tagId}, {$entityId}, '{$entityTable}' ) ";