From 5be259c76011723ac69da79c655b28f6a51f9ed6 Mon Sep 17 00:00:00 2001 From: David Reedy Jr Date: Fri, 24 Jun 2016 18:54:13 -0500 Subject: [PATCH] CRM-19007 Optionally disable USPS address... ...validation during contact import. --- CRM/Contact/Import/Form/DataSource.php | 6 ++++++ CRM/Contact/Import/Form/Preview.php | 10 ++++++++++ CRM/Utils/Address/USPS.php | 19 +++++++++++++++++++ .../CRM/Contact/Import/Form/DataSource.tpl | 8 ++++++++ 4 files changed, 43 insertions(+) diff --git a/CRM/Contact/Import/Form/DataSource.php b/CRM/Contact/Import/Form/DataSource.php index d30df0ad53..b18665b776 100644 --- a/CRM/Contact/Import/Form/DataSource.php +++ b/CRM/Contact/Import/Form/DataSource.php @@ -217,6 +217,11 @@ class CRM_Contact_Import_Form_DataSource extends CRM_Core_Form { $this->addElement('text', 'fieldSeparator', ts('Import Field Separator'), array('size' => 2)); + if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::ADDRESS_STANDARDIZATION_PREFERENCES_NAME, + 'address_standardization_provider') == 'USPS') { + $this->addElement('checkbox', 'disableUSPS', ts('Disable USPS address validation during import?')); + } + $this->addButtons(array( array( 'type' => 'upload', @@ -320,6 +325,7 @@ class CRM_Contact_Import_Form_DataSource extends CRM_Core_Form { $$storeName = $this->exportValue($storeValueName); $this->set($storeName, $$storeName); } + $this->set('disableUSPS', !empty($this->_params['disableUSPS'])); $this->set('dataSource', $this->_params['dataSource']); $this->set('skipColumnHeader', CRM_Utils_Array::value('skipColumnHeader', $this->_params)); diff --git a/CRM/Contact/Import/Form/Preview.php b/CRM/Contact/Import/Form/Preview.php index fd8ba0bba0..a3c5faa899 100644 --- a/CRM/Contact/Import/Form/Preview.php +++ b/CRM/Contact/Import/Form/Preview.php @@ -39,6 +39,13 @@ */ class CRM_Contact_Import_Form_Preview extends CRM_Import_Form_Preview { + /** + * Whether USPS validation should be disabled during import. + * + * @var bool + */ + protected $_disableUSPS; + /** * Set variables up before form is built. * @@ -52,6 +59,7 @@ class CRM_Contact_Import_Form_Preview extends CRM_Import_Form_Preview { $conflictRowCount = $this->get('conflictRowCount'); $mismatchCount = $this->get('unMatchCount'); $columnNames = $this->get('columnNames'); + $this->_disableUSPS = $this->get('disableUSPS'); //assign column names $this->assign('columnNames', $columnNames); @@ -292,6 +300,8 @@ class CRM_Contact_Import_Form_Preview extends CRM_Import_Form_Preview { CRM_ACL_BAO_Cache::updateEntry($userID); } + CRM_Utils_Address_USPS::disable($this->_disableUSPS); + // run the import $importJob->runImport($this); diff --git a/CRM/Utils/Address/USPS.php b/CRM/Utils/Address/USPS.php index a23df1eb71..301ea92d48 100644 --- a/CRM/Utils/Address/USPS.php +++ b/CRM/Utils/Address/USPS.php @@ -38,12 +38,31 @@ */ class CRM_Utils_Address_USPS { + /** + * Whether USPS validation should be disabled during import. + * + * @var bool + */ + protected static $_disabled = FALSE; + + /** + * @param $disabled + * + * @return void + */ + public static function disable($disable = TRUE) { + self::$_disabled = $disable; + } + /** * @param $values * * @return bool */ public static function checkAddress(&$values) { + if (self::$_disabled) { + return; + } if (!isset($values['street_address']) || (!isset($values['city']) && !isset($values['state_province']) && diff --git a/templates/CRM/Contact/Import/Form/DataSource.tpl b/templates/CRM/Contact/Import/Form/DataSource.tpl index 2ec370e8a3..754170bce6 100644 --- a/templates/CRM/Contact/Import/Form/DataSource.tpl +++ b/templates/CRM/Contact/Import/Form/DataSource.tpl @@ -98,6 +98,14 @@    {ts}Select Saved Mapping or Leave blank to create a new One.{/ts} { /if} + + {if $form.disableUSPS} + + + {$form.disableUSPS.html} + + + {/if} -- 2.25.1