Skip to content
Snippets Groups Projects
Commit 0f2ea47d authored by Ravish Nair's avatar Ravish Nair
Browse files

-- CRM-12845 CRM_Utils_Migrate - Handle CustomGroup subtypes

----------------------------------------
* CRM-12845: CRM_Utils_Migrate - Handle CustomGroup subtypes
  http://issues.civicrm.org/jira/browse/CRM-12845
parent 2ab405f8
Branches
Tags
No related merge requests found
......@@ -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";
......
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment