From: Franky Van Liedekerke Date: Thu, 1 Sep 2016 21:36:24 +0000 (+0200) Subject: allow external id for custom fields import X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=22a82042b86d09e8d11db6cb3950d8970ae5abad;p=civicrm-core.git allow external id for custom fields import --- diff --git a/CRM/Custom/Import/Form/MapField.php b/CRM/Custom/Import/Form/MapField.php index 51d1faedbf..3f5b0298b1 100644 --- a/CRM/Custom/Import/Form/MapField.php +++ b/CRM/Custom/Import/Form/MapField.php @@ -6,7 +6,7 @@ class CRM_Custom_Import_Form_MapField extends CRM_Contact_Import_Form_MapField { protected $_parser = 'CRM_Custom_Import_Parser_Api'; protected $_mappingType = 'Import Multi value custom data'; - protected $_highlightedFields = array(); +// protected $_highlightedFields = array(); /** * Entity being imported to. * @var string @@ -24,6 +24,9 @@ class CRM_Custom_Import_Form_MapField extends CRM_Contact_Import_Form_MapField { $this->_columnCount = $this->get('columnCount'); $this->assign('columnCount', $this->_columnCount); $this->_dataValues = $this->get('dataValues'); + $highlightedFields = array(); + $highlightedFields[] = 'contact_id'; + $highlightedFields[] = 'external_identifier'; //Separate column names from actual values. $columnNames = $this->_dataValues[0]; @@ -42,7 +45,7 @@ class CRM_Custom_Import_Form_MapField extends CRM_Contact_Import_Form_MapField { $this->_columnHeaders = $this->_dataValues[0]; } $this->assign('rowDisplayCount', 2); - $this->assign('highlightedFields', $this->_highlightedFields); + $this->assign('highlightedFields', $highlightedFields); } /** @@ -72,16 +75,13 @@ class CRM_Custom_Import_Form_MapField extends CRM_Contact_Import_Form_MapField { foreach ($fields['mapper'] as $mapperPart) { $importKeys[] = $mapperPart[0]; } - $requiredFields = array( - 'contact_id' => ts('Contact ID'), - ); - foreach ($requiredFields as $field => $title) { - if (!in_array($field, $importKeys)) { - if (!isset($errors['_qf_default'])) { - $errors['_qf_default'] = ''; - } - $errors['_qf_default'] .= ts('Missing required field: %1', array(1 => $title)); + + // check either contact id or external identifier + if (!in_array('contact_id', $importKeys) && !in_array('external_identifier', $importKeys)) { + if (!isset($errors['_qf_default'])) { + $errors['_qf_default'] = ''; } + $errors['_qf_default'] .= ts('Missing required field: %1', array(1 => ts('Contact ID'))); } } diff --git a/CRM/Custom/Import/Parser/Api.php b/CRM/Custom/Import/Parser/Api.php index 3a2b7777a3..ccb307b7c9 100644 --- a/CRM/Custom/Import/Parser/Api.php +++ b/CRM/Custom/Import/Parser/Api.php @@ -35,6 +35,7 @@ class CRM_Custom_Import_Parser_Api extends CRM_Custom_Import_Parser { $this->_fields = array_merge(array( 'do_not_import' => array('title' => ts('- do not import -')), 'contact_id' => array('title' => ts('Contact ID')), + 'external_identifier' => array('title' => ts('External Identifier')), ), $importableFields); } @@ -164,7 +165,14 @@ class CRM_Custom_Import_Parser_Api extends CRM_Custom_Import_Parser { $session = CRM_Core_Session::singleton(); $dateType = $session->get('dateTypes'); - $formatted['id'] = $this->_params['contact_id']; + if (isset($this->_params['external_identifier']) && !isset($this->_params['contact_id'])) { + $checkCid = new CRM_Contact_DAO_Contact(); + $checkCid->external_identifier = $this->_params['external_identifier']; + $checkCid->find(TRUE); + $formatted['id'] = $checkCid->id; + } else { + $formatted['id'] = $this->_params['contact_id']; + } $setDateFields = array_intersect_key($this->_params, array_flip($this->_dateFields)); CRM_Contact_Import_Parser_Contact::formatCommonData($this->_params, $formatted, $formatted);