CRM-11662 Add missing logic to copy case custom fields in CRM_Case_BAO_Case::mergeCases.
authorDave Greenberg <dave@civicrm.org>
Fri, 19 Jul 2013 19:51:28 +0000 (12:51 -0700)
committerDave Greenberg <dave@civicrm.org>
Fri, 19 Jul 2013 19:51:28 +0000 (12:51 -0700)
----------------------------------------
* CRM-11662:
  http://issues.civicrm.org/jira/browse/CRM-11662

CRM/Case/BAO/Case.php

index 85eb833c5a329148337aee64f1ef30ca97490ff3..8e7f197e1d3a4d4db2fdf491083c2edd79ee3e1b 100644 (file)
@@ -2286,7 +2286,31 @@ INNER JOIN  civicrm_case_contact ON ( civicrm_case.id = civicrm_case_contact.cas
         if (!$mainCaseId) {
           continue;
         }
+
+        // CRM-11662 Copy Case custom data
+        $extends = array('case');
+        $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends);
+        if ($groupTree) {
+          foreach ($groupTree as $groupID => $group) {
+            $table[$groupTree[$groupID]['table_name']] = array('entity_id');
+            foreach ($group['fields'] as $fieldID => $field) {
+              $table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name'];
+            }
+          }
+
+          foreach ($table as $tableName => $tableColumns) {
+            $insert          = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') ';
+            $tableColumns[0] = $mainCaseId;
+            $select          = 'SELECT ' . implode(', ', $tableColumns);
+            $from            = ' FROM ' . $tableName;
+            $where           = " WHERE {$tableName}.entity_id = {$otherCaseId}";
+            $query           = $insert . $select . $from . $where;
+            $dao             = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
+          }
+        }
+        
         $mainCase->free();
+        
         $mainCaseIds[] = $mainCaseId;
         //insert record for case contact.
         $otherCaseContact = new CRM_Case_DAO_CaseContact();