+ }
+
+ // Any existing entity tags from this tagset missing from the $params should be deleted
+ $deleteSQL = "DELETE FROM civicrm_entity_tag
+ USING civicrm_entity_tag, civicrm_tag
+ WHERE civicrm_tag.id=civicrm_entity_tag.tag_id
+ AND civicrm_entity_tag.entity_table='{$entityTable}'
+ AND entity_id={$entityId} AND parent_id={$parentId}";
+ if (!empty($realTagIds)) {
+ $deleteSQL .= " AND tag_id NOT IN (" . implode(', ', $realTagIds) . ");";
+ }
+
+ CRM_Core_DAO::executeQuery($deleteSQL);