From 9d1c4909fb4c03e64c0f2267b8a5b8d0b326eb02 Mon Sep 17 00:00:00 2001 From: Ravish Nair Date: Mon, 12 Aug 2013 18:17:01 +0530 Subject: [PATCH] -- CRM-12845 handled Individual, Organization and household subTypes for import & export ---------------------------------------- * CRM-12845: CRM_Utils_Migrate - Handle CustomGroup subtypes http://issues.civicrm.org/jira/browse/CRM-12845 --- CRM/Utils/Migrate/Export.php | 33 ++++++++++++++++++--------------- CRM/Utils/Migrate/Import.php | 8 +++++--- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/CRM/Utils/Migrate/Export.php b/CRM/Utils/Migrate/Export.php index 2a354e151b..d7d8661958 100644 --- a/CRM/Utils/Migrate/Export.php +++ b/CRM/Utils/Migrate/Export.php @@ -461,10 +461,7 @@ class CRM_Utils_Migrate_Export { if (isset($object->$name) && $object->$name !== NULL) { // hack for extends_entity_column_value if ($name == 'extends_entity_column_value') { - if ($object->extends == 'Event' || - $object->extends == 'Activity' || - $object->extends == 'Relationship' - ) { + if (in_array($object->extends, array('Event', 'Activity', 'Relationship', 'Individual', 'Organization', 'Household'))) { if ($object->extends == 'Event') { $key = 'event_type'; } @@ -474,21 +471,27 @@ class CRM_Utils_Migrate_Export { elseif ($object->extends == 'Relationship') { $key = 'relationship_type'; } - $keyValues['extends_entity_column_value_option_group'] = $key; $types = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($object->$name, 1, -1)); $values = array(); - foreach ($types as $type) { - if (in_array($key, array('activity_type', 'event_type'))) { - $ogID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $key, 'id', 'name'); - $ovParams = array('option_group_id' => $ogID, 'value' => $type); - CRM_Core_BAO_OptionValue::retrieve($ovParams, $oValue); - $values[] = $oValue['name']; - } - else { - $relTypeName = CRM_Core_DAO::getFieldValue('CRM_Contact_BAO_RelationshipType', $type, 'name_a_b', 'id'); - $values[] = $relTypeName; + if (in_array($object->extends, array('Individual', 'Organization', 'Household'))) { + $key = 'contact_type'; + $values = $types; + } + else { + foreach ($types as $type) { + if (in_array($key, array('activity_type', 'event_type'))) { + $ogID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $key, 'id', 'name'); + $ovParams = array('option_group_id' => $ogID, 'value' => $type); + CRM_Core_BAO_OptionValue::retrieve($ovParams, $oValue); + $values[] = $oValue['name']; + } + else { + $relTypeName = CRM_Core_DAO::getFieldValue('CRM_Contact_BAO_RelationshipType', $type, 'name_a_b', 'id'); + $values[] = $relTypeName; + } } } + $keyValues['extends_entity_column_value_option_group'] = $key; $value = implode(',', $values); $object->extends_entity_column_value = $value; } diff --git a/CRM/Utils/Migrate/Import.php b/CRM/Utils/Migrate/Import.php index 384c20ab7b..38c1776c00 100644 --- a/CRM/Utils/Migrate/Import.php +++ b/CRM/Utils/Migrate/Import.php @@ -194,8 +194,8 @@ WHERE v.option_group_id = %1 // fix extends stuff if it exists if (isset($customGroupXML->extends_entity_column_value_option_group) && - isset($customGroupXML->extends_entity_column_value) - ) { + isset($customGroupXML->extends_entity_column_value)) { + $valueIDs = array(); $optionValues = explode(",", $customGroupXML->extends_entity_column_value); $optValues = implode("','", $optionValues); if (trim($customGroup->extends) != 'Participant') { @@ -205,6 +205,9 @@ WHERE v.option_group_id = %1 $valueIDs[] = $relTypeId; } } + elseif (in_array($customGroup->extends, array('Individual', 'Organization', 'Household'))) { + $valueIDs = $optionValues; + } else { $sql = " SELECT v.value @@ -221,7 +224,6 @@ AND v.name IN ('$optValues') ); $dao = & CRM_Core_DAO::executeQuery($sql, $params); - $valueIDs = array(); while ($dao->fetch()) { $valueIDs[] = $dao->value; } -- 2.25.1