Skip to content
Snippets Groups Projects
Commit 3302658e authored by totten's avatar totten
Browse files

CRM-12647 - CRM_Utils_Migrate - Autoformat

----------------------------------------
* CRM-12647: Customization export/import crashes on "&"
  http://issues.civicrm.org/jira/browse/CRM-12647
parent cf5c22ba
No related branches found
No related tags found
No related merge requests found
......@@ -34,9 +34,12 @@
*/
class CRM_Utils_Migrate_Export {
protected $_xml; function __construct() {
protected $_xml;
function __construct() {
$this->_xml = array(
'customGroup' => array('data' => NULL,
'customGroup' => array(
'data' => NULL,
'name' => 'CustomGroup',
'scope' => 'CustomGroups',
'required' => FALSE,
......@@ -227,7 +230,8 @@ AND cg.is_active = 1
'CRM_Core_DAO_CustomField',
$sql,
array('id', 'column_name'),
array(array('optionGroup', 'option_group_id', 'option_group_name'),
array(
array('optionGroup', 'option_group_id', 'option_group_name'),
array('customGroup', 'custom_group_id', 'custom_group_name'),
)
);
......@@ -270,7 +274,8 @@ AND entity_id IS NULL
'CRM_Core_DAO_MappingField',
NULL,
NULL,
array(array('mappingGroup', 'mapping_id', 'mapping_group_name'),
array(
array('mappingGroup', 'mapping_id', 'mapping_group_name'),
array('locationType', 'location_type_id', 'location_type_name'),
array('relationshipType', 'relationship_type_id', 'relationship_type_name'),
)
......@@ -333,7 +338,7 @@ AND entity_id IS NULL
}
function exportDAO($object, $objectName, $additional = NULL) {
$dbFields = &$object->fields();
$dbFields = & $object->fields();
$xml = " <$objectName>";
foreach ($dbFields as $name => $dontCare) {
......
......@@ -47,7 +47,9 @@ class CRM_Utils_Migrate_ExportJSON {
protected $_renameTags = 1;
protected $_sitePrefix = 'Site 1'; function __construct(&$params) {
protected $_sitePrefix = 'Site 1';
function __construct(&$params) {
foreach ($params as $name => $value) {
$varName = '_' . $name;
$this->$varName = $value;
......@@ -60,10 +62,10 @@ class CRM_Utils_Migrate_ExportJSON {
function &splitContactIDs(&$contactIDs) {
// contactIDs could be a real large array, so we split it up into
// smaller chunks and then general xml for each chunk
$chunks = array();
$current = 0;
$chunks = array();
$current = 0;
$chunks[$current] = array();
$count = 0;
$count = 0;
foreach ($contactIDs as $k => $v) {
$chunks[$current][$k] = $v;
......@@ -133,7 +135,7 @@ class CRM_Utils_Migrate_ExportJSON {
function auxTable($tables) {
foreach ($tables as $tableName => $daoName) {
$fields = &$this->dbFields($daoName, TRUE);
$fields = & $this->dbFields($daoName, TRUE);
$sql = "SELECT * from $tableName";
$this->sql($sql, $tableName, $fields);
......@@ -153,7 +155,7 @@ SELECT *
FROM civicrm_option_group
WHERE name IN ( $nameString )
";
$fields = &$this->dbFields('CRM_Core_DAO_OptionGroup', TRUE);
$fields = & $this->dbFields('CRM_Core_DAO_OptionGroup', TRUE);
$this->sql($sql, 'civicrm_option_group', $fields);
$sql = "
......@@ -162,15 +164,15 @@ FROM civicrm_option_value v
INNER JOIN civicrm_option_group g ON v.option_group_id = g.id
WHERE g.name IN ( $nameString )
";
$fields = &$this->dbFields('CRM_Core_DAO_OptionValue', TRUE);
$fields = & $this->dbFields('CRM_Core_DAO_OptionValue', TRUE);
$this->sql($sql, 'civicrm_option_value', $fields);
}
function table(&$ids,
$tableName,
&$fields,
$whereField,
$additionalWhereCond = NULL
$tableName,
&$fields,
$whereField,
$additionalWhereCond = NULL
) {
if (empty($ids)) {
return;
......@@ -192,7 +194,7 @@ SELECT *
}
function sql($sql, $tableName, &$fields) {
$dao = &CRM_Core_DAO::executeQuery($sql);
$dao = & CRM_Core_DAO::executeQuery($sql);
while ($dao->fetch()) {
$value = array();
......@@ -210,42 +212,42 @@ SELECT *
}
function contact(&$contactIDs) {
$fields = &$this->dbFields('CRM_Contact_DAO_Contact', TRUE);
$fields = & $this->dbFields('CRM_Contact_DAO_Contact', TRUE);
$this->table($contactIDs, 'civicrm_contact', $fields, 'id', NULL);
}
function note(&$contactIDs) {
$fields = &$this->dbFields('CRM_Core_DAO_Note', TRUE);
$fields = & $this->dbFields('CRM_Core_DAO_Note', TRUE);
$this->table($contactIDs, 'civicrm_note', $fields, 'entity_id', "entity_table = 'civicrm_contact'");
}
function phone(&$contactIDs) {
$fields = &$this->dbFields('CRM_Core_DAO_Phone', TRUE);
$fields = & $this->dbFields('CRM_Core_DAO_Phone', TRUE);
$this->table($contactIDs, 'civicrm_phone', $fields, 'contact_id', NULL);
}
function email(&$contactIDs) {
$fields = &$this->dbFields('CRM_Core_DAO_Email', TRUE);
$fields = & $this->dbFields('CRM_Core_DAO_Email', TRUE);
$this->table($contactIDs, 'civicrm_email', $fields, 'contact_id', NULL);
}
function im(&$contactIDs) {
$fields = &$this->dbFields('CRM_Core_DAO_IM', TRUE);
$fields = & $this->dbFields('CRM_Core_DAO_IM', TRUE);
$this->table($contactIDs, 'civicrm_im', $fields, 'contact_id', NULL);
}
function website(&$contactIDs) {
$fields = &$this->dbFields('CRM_Core_DAO_Website', TRUE);
$fields = & $this->dbFields('CRM_Core_DAO_Website', TRUE);
$this->table($contactIDs, 'civicrm_website', $fields, 'contact_id', NULL);
}
function address(&$contactIDs) {
$fields = &$this->dbFields('CRM_Core_DAO_Email', TRUE);
$fields = & $this->dbFields('CRM_Core_DAO_Email', TRUE);
$this->table($contactIDs, 'civicrm_address', $fields, 'contact_id', NULL);
}
function groupContact(&$contactIDs) {
$fields = &$this->dbFields('CRM_Contact_DAO_GroupContact', TRUE);
$fields = & $this->dbFields('CRM_Contact_DAO_GroupContact', TRUE);
$this->table($contactIDs, 'civicrm_group_contact', $fields, 'contact_id', NULL);
}
......@@ -271,7 +273,7 @@ WHERE contact_id IN ( $ids )
}
}
$fields = &$this->dbFields('CRM_Contact_DAO_Group', TRUE);
$fields = & $this->dbFields('CRM_Contact_DAO_Group', TRUE);
$this->table($groupIDs, 'civicrm_group', $fields, 'id');
$this->savedSearch($groupIDs);
......@@ -291,12 +293,12 @@ INNER JOIN civicrm_group g on g.saved_search_id = s.id
WHERE g.id IN ( $idString )
";
$fields = &$this->dbFields('CRM_Contact_DAO_SavedSearch', TRUE);
$fields = & $this->dbFields('CRM_Contact_DAO_SavedSearch', TRUE);
$this->sql($sql, 'civicrm_saved_search', $fields);
}
function entityTag(&$contactIDs) {
$fields = &$this->dbFields('CRM_Core_DAO_EntityTag', TRUE);
$fields = & $this->dbFields('CRM_Core_DAO_EntityTag', TRUE);
$this->table($contactIDs, 'civicrm_entity_tag', $fields, 'entity_id', "entity_table = 'civicrm_contact'");
}
......@@ -321,7 +323,7 @@ AND entity_table = 'civicrm_contact'
}
}
$fields = &$this->dbFields('CRM_Core_DAO_Tag', TRUE);
$fields = & $this->dbFields('CRM_Core_DAO_Tag', TRUE);
$this->table($tagIDs, 'civicrm_tag', $fields, 'id');
}
......@@ -343,7 +345,7 @@ AND entity_table = 'civicrm_contact'
";
$fields = $this->dbFields('CRM_Contact_DAO_Relationship', TRUE);
$dao = &CRM_Core_DAO::executeQuery($sql);
$dao = & CRM_Core_DAO::executeQuery($sql);
while ($dao->fetch()) {
if (isset($_relationshipsHandled[$dao->id])) {
continue;
......@@ -362,7 +364,7 @@ AND entity_table = 'civicrm_contact'
$this->appendValue($dao->id, 'civicrm_relationship', $relationship);
$this->addAdditionalContacts(array(
$dao->contact_id_a,
$dao->contact_id_a,
$dao->contact_id_b,
),
$additionalContacts
......@@ -391,10 +393,10 @@ AND entity_table = 'civicrm_contact'
)
";
$fields = &$this->dbFields('CRM_Activity_DAO_Activity', TRUE);
$fields = & $this->dbFields('CRM_Activity_DAO_Activity', TRUE);
$activityIDs = array();
$dao = &CRM_Core_DAO::executeQuery($sql);
$dao = & CRM_Core_DAO::executeQuery($sql);
while ($dao->fetch()) {
if (isset($_activitiesHandled[$dao->id])) {
continue;
......@@ -426,8 +428,8 @@ AND entity_table = 'civicrm_contact'
$activityIDString = implode(",", $activityIDs);
// now get all assignee contact ids and target contact ids for this activity
$sql = "SELECT * FROM civicrm_activity_assignment WHERE activity_id IN ($activityIDString)";
$aaDAO = &CRM_Core_DAO::executeQuery($sql);
$sql = "SELECT * FROM civicrm_activity_assignment WHERE activity_id IN ($activityIDString)";
$aaDAO = & CRM_Core_DAO::executeQuery($sql);
$activityContacts = array();
while ($aaDAO->fetch()) {
$activityAssignee = array(
......@@ -441,7 +443,7 @@ AND entity_table = 'civicrm_contact'
$aaDAO->free();
$sql = "SELECT * FROM civicrm_activity_target WHERE activity_id IN ($activityIDString)";
$atDAO = &CRM_Core_DAO::executeQuery($sql);
$atDAO = & CRM_Core_DAO::executeQuery($sql);
while ($atDAO->fetch()) {
$activityTarget = array(
'id' => $atDAO->id,
......@@ -479,7 +481,7 @@ AND entity_table = 'civicrm_contact'
) . '.php';
include_once ($daoFile);
$daoFields = &$daoName::fields();
$daoFields = & $daoName::fields();
foreach ($daoFields as $key => & $value) {
$_fieldsRetrieved[$daoName][$value['name']] = array(
......@@ -514,7 +516,7 @@ AND entity_table = 'civicrm_contact'
}
function export(&$contactIDs) {
$chunks = &$this->splitContactIDs($contactIDs);
$chunks = & $this->splitContactIDs($contactIDs);
$additionalContactIDs = array();
......@@ -529,8 +531,8 @@ AND entity_table = 'civicrm_contact'
}
function run($fileName,
$lastExportTime = NULL,
$discoverContacts = FALSE
$lastExportTime = NULL,
$discoverContacts = FALSE
) {
$this->_discoverContacts = $discoverContacts;
......@@ -555,7 +557,7 @@ WHERE date >= $lastExportTime
}
$dao = &CRM_Core_DAO::executeQuery($sql);
$dao = & CRM_Core_DAO::executeQuery($sql);
$contactIDs = array();
while ($dao->fetch()) {
......
......@@ -33,7 +33,8 @@
*
*/
class CRM_Utils_Migrate_Import {
function __construct() {}
function __construct() {
}
function run($file) {
......@@ -42,7 +43,8 @@ class CRM_Utils_Migrate_Import {
$dom->xinclude();
$xml = simplexml_import_dom($dom);
$idMap = array('custom_group' => array(),
$idMap = array(
'custom_group' => array(),
'option_group' => array(),
);
......@@ -75,18 +77,18 @@ class CRM_Utils_Migrate_Import {
$dao->$keyName = (string ) $xml->$keyName;
if ($dao->find(TRUE)) {
CRM_Core_Session::setStatus(ts("Found %1, %2, %3",
array(
1 => $keyName,
2 => $dao->$keyName,
3 => $dao->__table
)
), '', 'info');
array(
1 => $keyName,
2 => $dao->$keyName,
3 => $dao->__table
)
), '', 'info');
return FALSE;
}
}
}
$fields = &$dao->fields();
$fields = & $dao->fields();
foreach ($fields as $name => $dontCare) {
if (isset($xml->$name)) {
$value = (string ) $xml->$name;
......@@ -147,7 +149,7 @@ WHERE v.option_group_id = %1
foreach ($xml->ContributionTypes as $contributionTypesXML) {
foreach ($contributionTypesXML->ContributionType as $contributionTypeXML) {
$contributionType = new CRM_Financial_DAO_FinancialType( );
$contributionType = new CRM_Financial_DAO_FinancialType();
$this->copyData($contributionType, $contributionTypeXML, TRUE, 'name');
}
}
......@@ -187,12 +189,13 @@ WHERE g.name = %1
AND v.name IN (%2)
";
$params = array(
1 => array((string ) $customGroupXML->extends_entity_column_value_option_group,
1 => array(
(string ) $customGroupXML->extends_entity_column_value_option_group,
'String',
),
2 => array((string ) $optValues, 'String'),
);
$dao = &CRM_Core_DAO::executeQuery($sql, $params);
$dao = & CRM_Core_DAO::executeQuery($sql, $params);
$valueIDs = array();
while ($dao->fetch()) {
......@@ -218,9 +221,11 @@ WHERE g.name = 'custom_data_type'
AND v.name = %1
";
$params = array(
1 => array((string ) $customGroupXML->extends_entity_column_value_option_group,
1 => array(
(string ) $customGroupXML->extends_entity_column_value_option_group,
'String',
));
)
);
$valueID = (int ) CRM_Core_DAO::singleValueQuery($sql, $params);
if ($valueID) {
$customGroup->extends_entity_column_id = $valueID;
......@@ -280,10 +285,10 @@ AND v.name = %1
$fields_indexed_by_group_id[$id][] = $customFieldXML;
}
}
while(list($group_id, $fields) = each($fields_indexed_by_group_id)) {
while (list($group_id, $fields) = each($fields_indexed_by_group_id)) {
$total = count($fields);
$count = 0;
while(list(,$customFieldXML) = each($fields)) {
while (list(, $customFieldXML) = each($fields)) {
$count++;
$customField = new CRM_Core_DAO_CustomField();
$customField->custom_group_id = $group_id;
......@@ -305,9 +310,9 @@ AND v.name = %1
// Only rebuild the table's trigger on the last field added to avoid un-necessary
// and slow rebuilds when adding many fields at the same time.
$triggerRebuild = FALSE;
if($count == $total) {
if ($count == $total) {
$triggerRebuild = TRUE;
}
}
$indexExist = FALSE;
CRM_Core_BAO_CustomField::createField($customField, 'add', $indexExist, $triggerRebuild);
}
......@@ -355,18 +360,19 @@ INNER JOIN civicrm_custom_group g ON f.custom_group_id = g.id
WHERE g.table_name = %1
AND f.column_name = %2
";
$params = array(1 => array($tableName, 'String'),
$params = array(
1 => array($tableName, 'String'),
2 => array($columnName, 'String'),
);
$cfID = CRM_Core_DAO::singleValueQuery($sql, $params);
if (!$cfID) {
CRM_Core_Error::fatal(ts("Could not find custom field for %1, %2, %3",
array(
1 => $profileField->field_name,
2 => $tableName,
3 => $columnName
)
) . "<br />");
array(
1 => $profileField->field_name,
2 => $tableName,
3 => $columnName
)
) . "<br />");
}
$profileField->field_name = "custom_{$cfID}";
}
......
......@@ -37,6 +37,7 @@ class CRM_Utils_Migrate_ImportJSON {
protected $_lookupCache;
protected $_saveMapping;
function __construct() {
$this->_lookupCache = array();
$this->_saveMapping = array();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment