From 0f2ea47db020284c7e0f46419aae26287a46d6cc Mon Sep 17 00:00:00 2001 From: Ravish Nair Date: Mon, 12 Aug 2013 15:42:27 +0530 Subject: [PATCH] -- CRM-12845 CRM_Utils_Migrate - Handle CustomGroup subtypes ---------------------------------------- * CRM-12845: CRM_Utils_Migrate - Handle CustomGroup subtypes http://issues.civicrm.org/jira/browse/CRM-12845 --- CRM/Utils/Migrate/Export.php | 13 +++++++++-- CRM/Utils/Migrate/Import.php | 45 +++++++++++++++++++++--------------- 2 files changed, 38 insertions(+), 20 deletions(-) diff --git a/CRM/Utils/Migrate/Export.php b/CRM/Utils/Migrate/Export.php index aeac4e693d..2a354e151b 100644 --- a/CRM/Utils/Migrate/Export.php +++ b/CRM/Utils/Migrate/Export.php @@ -478,10 +478,19 @@ class CRM_Utils_Migrate_Export { $types = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($object->$name, 1, -1)); $values = array(); foreach ($types as $type) { - $values[] = $this->_xml['optionValue']['idNameMap']["$key.{$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; + } } $value = implode(',', $values); - $keyValues['extends_entity_column_value_option_value'] = $value; + $object->extends_entity_column_value = $value; } else { echo "This extension: {$object->extends} is not yet handled"; diff --git a/CRM/Utils/Migrate/Import.php b/CRM/Utils/Migrate/Import.php index b43c38a6d5..384c20ab7b 100644 --- a/CRM/Utils/Migrate/Import.php +++ b/CRM/Utils/Migrate/Import.php @@ -194,36 +194,45 @@ 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_option_value) - ) { - $optValues = explode(",", $customGroupXML->extends_entity_column_value_option_value); - $optValues = implode("','", $optValues); + isset($customGroupXML->extends_entity_column_value) + ) { + $optionValues = explode(",", $customGroupXML->extends_entity_column_value); + $optValues = implode("','", $optionValues); if (trim($customGroup->extends) != 'Participant') { - $sql = " + if ($customGroup->extends == 'Relationship') { + foreach ($optionValues as $key => $value) { + $relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_BAO_RelationshipType', $value, 'id', 'name_a_b'); + $valueIDs[] = $relTypeId; + } + } + else { + $sql = " SELECT v.value FROM civicrm_option_value v INNER JOIN civicrm_option_group g ON g.id = v.option_group_id WHERE g.name = %1 -AND v.name IN (%2) +AND v.name IN ('$optValues') "; - $params = array( - 1 => array( - (string ) $customGroupXML->extends_entity_column_value_option_group, - 'String', - ), - 2 => array((string ) $optValues, 'String'), - ); - $dao = & CRM_Core_DAO::executeQuery($sql, $params); - - $valueIDs = array(); - while ($dao->fetch()) { - $valueIDs[] = $dao->value; + $params = array( + 1 => array( + (string ) $customGroupXML->extends_entity_column_value_option_group, + 'String', + ), + ); + $dao = & CRM_Core_DAO::executeQuery($sql, $params); + + $valueIDs = array(); + while ($dao->fetch()) { + $valueIDs[] = $dao->value; + } } if (!empty($valueIDs)) { $customGroup->extends_entity_column_value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $valueIDs ) . CRM_Core_DAO::VALUE_SEPARATOR; + unset($valueIDs); + // Note: No need to set extends_entity_column_id here. $saveAgain = TRUE; -- 2.25.1