Merge remote-tracking branch 'upstream/4.3' into 4.3-4.4-2013-10-28-14-52-15
[civicrm-core.git] / CRM / Case / XMLProcessor / Process.php
index 8a4c8b673aa0225925ddaec45e96d779f654ea2f..2dda1d36dfb79767ecd7d2bb1e78baf95fedbebc 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.3                                                |
+ | CiviCRM version 4.4                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2013                                |
  +--------------------------------------------------------------------+
@@ -120,7 +120,8 @@ class CRM_Case_XMLProcessor_Process extends CRM_Case_XMLProcessor {
   }
 
   function processStandardTimeline($activitySetXML, &$params) {
-    if ('Change Case Type' == CRM_Utils_Array::value('activityTypeName', $params)) {
+    if ('Change Case Type' == CRM_Utils_Array::value('activityTypeName', $params)
+      && CRM_Utils_Array::value('resetTimeline', $params, TRUE)) {
       // delete all existing activities which are non-empty
       $this->deleteEmptyActivity($params);
     }
@@ -253,12 +254,15 @@ class CRM_Case_XMLProcessor_Process extends CRM_Case_XMLProcessor {
   }
 
   function deleteEmptyActivity(&$params) {
+    $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
+    $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
+
     $query = "
 DELETE a
 FROM   civicrm_activity a
 INNER JOIN civicrm_activity_contact t ON t.activity_id = a.id
 WHERE  t.contact_id = %1
-AND    t.record_type = 'Target'
+AND    t.record_type_id = $targetID
 AND    a.is_auto = 1
 AND    a.is_current_revision = 1
 ";