worked on #2 fixes, CRM-14052
authorkurund <kurund@civicrm.org>
Mon, 6 Jan 2014 22:59:34 +0000 (14:59 -0800)
committerkurund <kurund@civicrm.org>
Mon, 6 Jan 2014 23:02:23 +0000 (15:02 -0800)
----------------------------------------
* CRM-14052: Tagset fixes
  http://issues.civicrm.org/jira/browse/CRM-14052

CRM/Admin/Page/AJAX.php
CRM/Core/Form/Tag.php
templates/CRM/common/Tag.tpl

index 0f0427c164f634a7d77204934b953fc359a60686..a2ac9986ed4c6f4d293f987f41255cb42fa04f5d 100644 (file)
@@ -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,
index 5a59581b5af3dabd04c1216abd75405686274d72..6e1057cab1770e9bdba01de14ad82e8f39e568de 100644 (file)
@@ -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);
+    }
   }
 }
 
index f16417a6bed3435b0b34db0ca86393e6945b4806..3f7427b5a705bd3d8ac9ebd9869c99f6dc253835 100644 (file)
@@ -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');