From 971e67cf86efeeb98d1e145614d5e10a14b0743d Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 26 Apr 2022 08:18:37 +1200 Subject: [PATCH] [REF] [Import] [Trivial] Extract duplicate match options As part of moving from passing variables from form to form & getting using 'get' we are retrieving onDuplicate via getSubmittedValue(), also extracting to allow code blocks to clarify better --- CRM/Contact/Import/Form/MapField.php | 38 +++++++++++++++++++--------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/CRM/Contact/Import/Form/MapField.php b/CRM/Contact/Import/Form/MapField.php index a0c13cc5c1..55904eec95 100644 --- a/CRM/Contact/Import/Form/MapField.php +++ b/CRM/Contact/Import/Form/MapField.php @@ -30,13 +30,6 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { */ protected $_formattedFieldNames; - /** - * On duplicate. - * - * @var int - */ - public $_onDuplicate; - protected $_dedupeFields; protected static $customFields; @@ -83,7 +76,6 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { public function preProcess() { $this->_mapperFields = $this->get('fields'); $this->_importTableName = $this->get('importTableName'); - $this->_onDuplicate = $this->get('onDuplicate'); $this->_contactSubType = $this->get('contactSubType'); $highlightedFields = []; $highlightedFields[] = 'email'; @@ -105,14 +97,14 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { break; } $this->_contactType = $contactType; - if ($this->_onDuplicate == CRM_Import_Parser::DUPLICATE_SKIP) { + if ($this->isSkipDuplicates()) { unset($this->_mapperFields['id']); } else { $highlightedFields[] = 'id'; } - if ($this->_onDuplicate != CRM_Import_Parser::DUPLICATE_NOCHECK) { + if ($this->isIgnoreDuplicates()) { //Mark Dedupe Rule Fields as required, since it's used in matching contact foreach (CRM_Contact_BAO_ContactType::basicTypes() as $cType) { $ruleParams = [ @@ -267,7 +259,7 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { //Modified the Relationship fields if the fields are //present in dedupe rule - if ($this->_onDuplicate != CRM_Import_Parser::DUPLICATE_NOCHECK && !empty($this->_dedupeFields[$cType]) && + if ($this->isIgnoreDuplicates() && !empty($this->_dedupeFields[$cType]) && is_array($this->_dedupeFields[$cType]) ) { static $cTypeArray = []; @@ -493,6 +485,7 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { * * @return \CRM_Contact_Import_Parser_Contact * @throws \CiviCRM_API3_Exception + * @throws \CRM_Core_Exception */ public function submit($params, $mapperKeys) { $mapper = $mapperKeysMain = $locations = []; @@ -680,7 +673,7 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { $this->get('contactType'), '_id', '_status', - $this->_onDuplicate, + (int) $this->getSubmittedValue('onDuplicate'), NULL, NULL, FALSE, CRM_Contact_Import_Parser_Contact::DEFAULT_TIMEOUT, $this->get('contactSubType'), @@ -751,4 +744,25 @@ class CRM_Contact_Import_Form_MapField extends CRM_Import_Form_MapField { return $saveMappingFields->mapping_id; } + /** + * Did the user specify duplicates matching should not be attempted. + * + * @return bool + * @throws \CRM_Core_Exception + */ + private function isIgnoreDuplicates(): bool { + return ((int) $this->getSubmittedValue('onDuplicate')) === CRM_Import_Parser::DUPLICATE_NOCHECK; + } + + /** + * Did the user specify duplicates should be skipped and not imported. + * + * @return bool + * + * @throws \CRM_Core_Exception + */ + private function isSkipDuplicates(): bool { + return ((int) $this->getSubmittedValue('onDuplicate')) === CRM_Import_Parser::DUPLICATE_SKIP; + } + } -- 2.25.1