From fc30268659af43e264bf2171ac3f03748b069940 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 21 Dec 2020 18:31:22 +1300 Subject: [PATCH] [REF] Relocate function from DeprecatedUtils to the class that actually calls it --- CRM/Contact/Import/Parser/Contact.php | 54 ++++++++++++++++++++++++++- CRM/Utils/DeprecatedUtils.php | 52 -------------------------- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/CRM/Contact/Import/Parser/Contact.php b/CRM/Contact/Import/Parser/Contact.php index 6908aadc2f..20334b7f92 100644 --- a/CRM/Contact/Import/Parser/Contact.php +++ b/CRM/Contact/Import/Parser/Contact.php @@ -1565,7 +1565,7 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser { if ($error) { return $error; } - _civicrm_api3_deprecated_validate_formatted_contact($formatted); + $this->deprecated_validate_formatted_contact($formatted); } catch (CRM_Core_Exception $e) { return ['error_message' => $e->getMessage(), 'is_error' => 1, 'code' => $e->getCode()]; @@ -2070,4 +2070,56 @@ class CRM_Contact_Import_Parser_Contact extends CRM_Contact_Import_Parser { return $this->processMessage($values, $statusFieldName, CRM_Import_Parser::VALID); } + /** + * Validate a formatted contact parameter list. + * + * @param array $params + * Structured parameter list (as in crm_format_params). + * + * @throw CRM_Core_Error + */ + public function deprecated_validate_formatted_contact(&$params): void { + // Look for offending email addresses + + if (array_key_exists('email', $params)) { + foreach ($params['email'] as $count => $values) { + if (!is_array($values)) { + continue; + } + if ($email = CRM_Utils_Array::value('email', $values)) { + // validate each email + if (!CRM_Utils_Rule::email($email)) { + throw new CRM_Core_Exception('No valid email address'); + } + + // check for loc type id. + if (empty($values['location_type_id'])) { + throw new CRM_Core_Exception('Location Type Id missing.'); + } + } + } + } + + // Validate custom data fields + if (array_key_exists('custom', $params) && is_array($params['custom'])) { + foreach ($params['custom'] as $key => $custom) { + if (is_array($custom)) { + foreach ($custom as $fieldId => $value) { + $valid = CRM_Core_BAO_CustomValue::typecheck(CRM_Utils_Array::value('type', $value), + CRM_Utils_Array::value('value', $value) + ); + if (!$valid && $value['is_required']) { + throw new CRM_Core_Exception('Invalid value for custom field \'' . + $custom['name'] . '\'' + ); + } + if (CRM_Utils_Array::value('type', $custom) == 'Date') { + $params['custom'][$key][$fieldId]['value'] = str_replace('-', '', $params['custom'][$key][$fieldId]['value']); + } + } + } + } + } + } + } diff --git a/CRM/Utils/DeprecatedUtils.php b/CRM/Utils/DeprecatedUtils.php index c9345e39ad..8f8b27cf4c 100644 --- a/CRM/Utils/DeprecatedUtils.php +++ b/CRM/Utils/DeprecatedUtils.php @@ -551,58 +551,6 @@ function _civicrm_api3_deprecated_duplicate_formatted_contact($params) { return civicrm_api3_create_success(TRUE); } -/** - * Validate a formatted contact parameter list. - * - * @param array $params - * Structured parameter list (as in crm_format_params). - * - * @throw CRM_Core_Error - */ -function _civicrm_api3_deprecated_validate_formatted_contact(&$params): void { - // Look for offending email addresses - - if (array_key_exists('email', $params)) { - foreach ($params['email'] as $count => $values) { - if (!is_array($values)) { - continue; - } - if ($email = CRM_Utils_Array::value('email', $values)) { - // validate each email - if (!CRM_Utils_Rule::email($email)) { - throw new CRM_Core_Exception('No valid email address'); - } - - // check for loc type id. - if (empty($values['location_type_id'])) { - throw new CRM_Core_Exception('Location Type Id missing.'); - } - } - } - } - - // Validate custom data fields - if (array_key_exists('custom', $params) && is_array($params['custom'])) { - foreach ($params['custom'] as $key => $custom) { - if (is_array($custom)) { - foreach ($custom as $fieldId => $value) { - $valid = CRM_Core_BAO_CustomValue::typecheck(CRM_Utils_Array::value('type', $value), - CRM_Utils_Array::value('value', $value) - ); - if (!$valid && $value['is_required']) { - throw new CRM_Core_Exception('Invalid value for custom field \'' . - $custom['name'] . '\'' - ); - } - if (CRM_Utils_Array::value('type', $custom) == 'Date') { - $params['custom'][$key][$fieldId]['value'] = str_replace('-', '', $params['custom'][$key][$fieldId]['value']); - } - } - } - } - } -} - /** * @deprecated - this is part of the import parser not the API & needs to be moved on out * -- 2.25.1