-- CRM-12845 handled Individual, Organization and household subTypes for import ...
authorRavish Nair <ravish.nair@webaccess.co.in>
Mon, 12 Aug 2013 12:47:01 +0000 (18:17 +0530)
committerRavish Nair <ravish.nair@webaccess.co.in>
Mon, 12 Aug 2013 12:47:01 +0000 (18:17 +0530)
----------------------------------------
* CRM-12845: CRM_Utils_Migrate - Handle CustomGroup subtypes
  http://issues.civicrm.org/jira/browse/CRM-12845

CRM/Utils/Migrate/Export.php
CRM/Utils/Migrate/Import.php

index 2a354e151b89b73411b933b85aef7b814970d119..d7d86619580bbf4485f392a8f4b517823b845dd8 100644 (file)
@@ -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;
           }
index 384c20ab7b718c3ccde6e772b4d49537cbc101e9..38c1776c00f10be54b2bcb093ce2958fbc9477ac 100644 (file)
@@ -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;
               }