From 8bd862834d6b8dacb4fa06b1873fca8c92024b15 Mon Sep 17 00:00:00 2001 From: Dave Greenberg Date: Fri, 19 Jul 2013 12:51:28 -0700 Subject: [PATCH] CRM-11662 Add missing logic to copy case custom fields in CRM_Case_BAO_Case::mergeCases. ---------------------------------------- * CRM-11662: http://issues.civicrm.org/jira/browse/CRM-11662 --- CRM/Case/BAO/Case.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 85eb833c5a..8e7f197e1d 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -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(); -- 2.25.1