<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013 |
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
* $Id$
*
*/
class CRM_Utils_Migrate_Import {
+ /**
+ *
+ */
function __construct() {
}
+ /**
+ * Import custom-data from an XML file
+ *
+ * @param string $file path to an XML file
+ * @throws CRM_Core_Exception
+ * @return void;
+ */
function run($file) {
-
// read xml file
- $dom = DomDocument::load($file);
+ $dom = new DomDocument();
+ if (! $dom->load($file)) {
+ throw new CRM_Core_Exception("Failed to parse XML file \"$file\"");
+ }
$dom->xinclude();
$xml = simplexml_import_dom($dom);
+ return $this->runXmlElement($xml);
+ }
+ /**
+ * Import custom-data from an XML element
+ *
+ * @param SimpleXMLElement $xml
+ * @return void
+ */
+ function runXmlElement($xml) {
$idMap = array(
'custom_group' => array(),
'option_group' => array(),
CRM_Core_Config::clearDBCache();
}
+ /**
+ * @param $dao
+ * @param $xml
+ * @param bool $save
+ * @param null $keyName
+ *
+ * @return bool
+ */
function copyData(&$dao, &$xml, $save = FALSE, $keyName = NULL) {
if ($keyName) {
if (isset($xml->$keyName)) {
foreach ($fields as $name => $dontCare) {
if (isset($xml->$name)) {
$value = (string ) $xml->$name;
- $value = str_replace(":;:;:;",
+ $value = str_replace(CRM_Utils_Migrate_Export::XML_VALUE_SEPARATOR,
CRM_Core_DAO::VALUE_SEPARATOR,
$value
);
return TRUE;
}
+ /**
+ * @param $xml
+ * @param $idMap
+ */
function optionGroups(&$xml, &$idMap) {
foreach ($xml->OptionGroups as $optionGroupsXML) {
foreach ($optionGroupsXML->OptionGroup as $optionGroupXML) {
}
}
+ /**
+ * @param $xml
+ * @param $idMap
+ */
function optionValues(&$xml, &$idMap) {
foreach ($xml->OptionValues as $optionValuesXML) {
foreach ($optionValuesXML->OptionValue as $optionValueXML) {
}
}
+ /**
+ * @param $xml
+ */
function relationshipTypes(&$xml) {
foreach ($xml->RelationshipTypes as $relationshipTypesXML) {
}
}
+ /**
+ * @param $xml
+ */
function contributionTypes(&$xml) {
foreach ($xml->ContributionTypes as $contributionTypesXML) {
}
}
+ /**
+ * @param $xml
+ * @param $idMap
+ */
function customGroups(&$xml, &$idMap) {
foreach ($xml->CustomGroups as $customGroupsXML) {
foreach ($customGroupsXML->CustomGroup as $customGroupXML) {
// 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)) {
+ $valueIDs = array();
+ $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;
+ }
+ }
+ elseif (in_array($customGroup->extends, array('Individual', 'Organization', 'Household'))) {
+ $valueIDs = $optionValues;
+ }
+ 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);
+
+ 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;
}
}
+ /**
+ * @param $xml
+ * @param $idMap
+ */
function customFields(&$xml, &$idMap) {
// Re-index by group id so we can build out the custom fields one table
// at a time, and then rebuild the table triggers at the end, rather than
}
}
+ /**
+ * @param $xml
+ * @param $idMap
+ */
function dbTemplateString(&$xml, &$idMap) {
foreach ($xml->Persistent as $persistentXML) {
foreach ($persistentXML->Persistent as $persistent) {
}
}
+ /**
+ * @param $xml
+ * @param $idMap
+ */
function profileGroups(&$xml, &$idMap) {
foreach ($xml->ProfileGroups as $profileGroupsXML) {
foreach ($profileGroupsXML->ProfileGroup as $profileGroupXML) {
}
}
+ /**
+ * @param $xml
+ * @param $idMap
+ *
+ * @throws Exception
+ */
function profileFields(&$xml, &$idMap) {
foreach ($xml->ProfileFields as $profileFieldsXML) {
foreach ($profileFieldsXML->ProfileField as $profileFieldXML) {
}
}
+ /**
+ * @param $xml
+ * @param $idMap
+ */
function profileJoins(&$xml, &$idMap) {
foreach ($xml->ProfileJoins as $profileJoinsXML) {
foreach ($profileJoinsXML->ProfileJoin as $profileJoinXML) {