-- CRM-12845 CRM_Utils_Migrate - Handle CustomGroup subtypes
[civicrm-core.git] / CRM / Utils / Migrate / Import.php
index b43c38a6d55efa39be72f86aea06582bfc72c9b3..384c20ab7b718c3ccde6e772b4d49537cbc101e9 100644 (file)
@@ -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;