From b3caa3a765d5140e9ccb360fac809040fee1bf8b Mon Sep 17 00:00:00 2001 From: kurund Date: Mon, 6 Jan 2014 14:59:34 -0800 Subject: [PATCH] worked on #2 fixes, CRM-14052 ---------------------------------------- * CRM-14052: Tagset fixes http://issues.civicrm.org/jira/browse/CRM-14052 --- CRM/Admin/Page/AJAX.php | 2 +- CRM/Core/Form/Tag.php | 10 ++++++++++ templates/CRM/common/Tag.tpl | 4 +++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CRM/Admin/Page/AJAX.php b/CRM/Admin/Page/AJAX.php index 0f0427c164..a2ac9986ed 100644 --- a/CRM/Admin/Page/AJAX.php +++ b/CRM/Admin/Page/AJAX.php @@ -404,7 +404,7 @@ LIMIT $limit"; if (!is_numeric($tagID)) { $tagID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Tag', $tagID, 'id', 'name'); } - if ($entityId) { + if (!$skipEntityAction && $entityId) { // delete this tag entry for the entity $params = array( 'entity_table' => $entityTable, diff --git a/CRM/Core/Form/Tag.php b/CRM/Core/Form/Tag.php index 5a59581b5a..6e1057cab1 100644 --- a/CRM/Core/Form/Tag.php +++ b/CRM/Core/Form/Tag.php @@ -236,6 +236,7 @@ class CRM_Core_Form_Tag { * */ static function postProcess(&$params, $entityId, $entityTable = 'civicrm_contact', &$form) { + $allTagIds = array(); foreach ($params as $parentId => $value) { if (!$value) { continue; @@ -260,6 +261,7 @@ class CRM_Core_Form_Tag { } } + $allTagIds[] = $tagId; if ($form && $form->_action != CRM_Core_Action::UPDATE) { $insertValues[] = "( {$tagId}, {$entityId}, '{$entityTable}' ) "; } @@ -274,6 +276,14 @@ class CRM_Core_Form_Tag { } } } + + // delete tags that are missing + if (!empty($allTagIds)) { + $validTagIds = implode(',', $allTagIds); + $deleteSQL = "DELETE FROM civicrm_entity_tag WHERE entity_id={$entityId} AND entity_table='{$entityTable}' + AND tag_id NOT IN ({$validTagIds})"; + CRM_Core_DAO::executeQuery($deleteSQL); + } } } diff --git a/templates/CRM/common/Tag.tpl b/templates/CRM/common/Tag.tpl index f16417a6be..3f7427b5a7 100644 --- a/templates/CRM/common/Tag.tpl +++ b/templates/CRM/common/Tag.tpl @@ -63,7 +63,9 @@ setVal[x] = valArray[x]; } } - CRM.alert('', '{/literal}{ts escape='js'}Removed{/ts}{literal}', 'success'); + if (!skipEntityAction) { + CRM.alert('', '{/literal}{ts escape='js'}Removed{/ts}{literal}', 'success'); + } } else { CRM.alert('', '{/literal}{ts escape='js'}Saved{/ts}{literal}', 'success'); -- 2.25.1