Skip to content

Commit

Permalink
Do not rely in init to set whether address parsing is on
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jun 2, 2022
1 parent 1a4443b commit 0fbb860
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
21 changes: 16 additions & 5 deletions CRM/Contact/Import/Parser/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser {

protected $_mapperKeys = [];
protected $_allExternalIdentifiers = [];
protected $_parseStreetAddress;

/**
* Array of successfully imported contact id's
Expand Down Expand Up @@ -88,6 +87,13 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Import_Parser {
*/
public $_dedupeRuleGroupID = NULL;

/**
* Addresses that failed to parse.
*
* @var array
*/
private $_unparsedStreetAddressContacts = [];

/**
* The initializer code, called before processing.
*/
Expand All @@ -96,8 +102,13 @@ public function init() {
foreach ($this->getImportableFieldsMetadata() as $name => $field) {
$this->addField($name, $field['title'], CRM_Utils_Array::value('type', $field), CRM_Utils_Array::value('headerPattern', $field), CRM_Utils_Array::value('dataPattern', $field), CRM_Utils_Array::value('hasLocationType', $field));
}
}

$this->_parseStreetAddress = CRM_Utils_Array::value('street_address_parsing', CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options'), FALSE);
/**
* Is street address parsing enabled for the site.
*/
protected function isParseStreetAddress() : bool {
return (bool) (CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'address_options')['street_address_parsing'] ?? FALSE);
}

/**
Expand Down Expand Up @@ -529,7 +540,7 @@ private function formatCommonData($params, &$formatted) {
}

// parse street address, CRM-5450
if ($this->_parseStreetAddress) {
if ($this->isParseStreetAddress()) {
if (array_key_exists('address', $formatted) && is_array($formatted['address'])) {
foreach ($formatted['address'] as $instance => & $address) {
$streetAddress = $address['street_address'] ?? NULL;
Expand Down Expand Up @@ -776,7 +787,7 @@ public function createContact(&$formatted, &$contactFields, $onDuplicate, $conta
$newContact = CRM_Contact_BAO_Contact::retrieve($contact, $defaults);

//get the id of the contact whose street address is not parsable, CRM-5886
if ($this->_parseStreetAddress && property_exists($newContact, 'address') && $newContact->address) {
if ($this->isParseStreetAddress() && property_exists($newContact, 'address') && $newContact->address) {
foreach ($newContact->address as $address) {
if (!empty($address['street_address']) && (empty($address['street_number']) || empty($address['street_name']))) {
$this->_unparsedStreetAddressContacts[] = [
Expand Down Expand Up @@ -2171,7 +2182,7 @@ private function checkStatesForCountry(int $countryID, array $possibleStates) {
*/
protected function getStatus($outcome): string {
if ($outcome === CRM_Import_Parser::VALID) {
return empty($this->_parseStreetAddress) ? 'IMPORTED' : 'warning_unparsed_address';
return empty($this->_unparsedStreetAddressContacts) ? 'IMPORTED' : 'warning_unparsed_address';
}
return [
CRM_Import_Parser::DUPLICATE => 'DUPLICATE',
Expand Down
1 change: 0 additions & 1 deletion CRM/Import/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -1542,7 +1542,6 @@ protected function getFieldMappings(): array {
return $mappedFields;
}


/**
* Check if an error in custom data.
*
Expand Down

0 comments on commit 0fbb860

Please sign in to comment.