From 4a50b17ff4fc3d4a41974f874a5ae714947ca872 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 21 Dec 2020 20:54:20 +1300 Subject: [PATCH] [REF] Relocate another function from DeprecatedUtils to the calling class This is only called from one class so relocate to there --- CRM/Activity/Import/Parser/Activity.php | 66 ++++++++++++++++++++++++- CRM/Utils/DeprecatedUtils.php | 63 ----------------------- 2 files changed, 64 insertions(+), 65 deletions(-) diff --git a/CRM/Activity/Import/Parser/Activity.php b/CRM/Activity/Import/Parser/Activity.php index aa2239dc3d..cccd68e0db 100644 --- a/CRM/Activity/Import/Parser/Activity.php +++ b/CRM/Activity/Import/Parser/Activity.php @@ -271,8 +271,7 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser { } } // Date-Format part ends. - require_once 'CRM/Utils/DeprecatedUtils.php'; - $formatError = _civicrm_api3_deprecated_activity_formatted_param($params, $params, TRUE); + $formatError = $this->deprecated_activity_formatted_param($params, $params, TRUE); if ($formatError) { array_unshift($values, $formatError['error_message']); @@ -374,4 +373,67 @@ class CRM_Activity_Import_Parser_Activity extends CRM_Activity_Import_Parser { return CRM_Import_Parser::VALID; } + /** + * take the input parameter list as specified in the data model and + * convert it into the same format that we use in QF and BAO object + * + * @param array $params + * Associative array of property name/value. + * pairs to insert in new contact. + * @param array $values + * The reformatted properties that we can use internally. + * + * @param array|bool $create Is the formatted Values array going to + * be used for CRM_Activity_BAO_Activity::create() + * + * @return array|CRM_Error + */ + protected function deprecated_activity_formatted_param(&$params, &$values, $create = FALSE) { + // copy all the activity fields as is + $fields = CRM_Activity_DAO_Activity::fields(); + _civicrm_api3_store_values($fields, $params, $values); + + require_once 'CRM/Core/OptionGroup.php'; + $customFields = CRM_Core_BAO_CustomField::getFields('Activity'); + + foreach ($params as $key => $value) { + // ignore empty values or empty arrays etc + if (CRM_Utils_System::isNull($value)) { + continue; + } + + //Handling Custom Data + if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) { + $values[$key] = $value; + $type = $customFields[$customFieldID]['html_type']; + if (CRM_Core_BAO_CustomField::isSerialized($customFields[$customFieldID])) { + $values[$key] = CRM_Import_Parser::unserializeCustomValue($customFieldID, $value, $type); + } + elseif ($type == 'Select' || $type == 'Radio') { + $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE); + foreach ($customOption as $customFldID => $customValue) { + $val = $customValue['value'] ?? NULL; + $label = $customValue['label'] ?? NULL; + $label = strtolower($label); + $value = strtolower(trim($value)); + if (($value == $label) || ($value == strtolower($val))) { + $values[$key] = $val; + } + } + } + } + + if ($key == 'target_contact_id') { + if (!CRM_Utils_Rule::integer($value)) { + return civicrm_api3_create_error("contact_id not valid: $value"); + } + $contactID = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_contact WHERE id = $value"); + if (!$contactID) { + return civicrm_api3_create_error("Invalid Contact ID: There is no contact record with contact_id = $value."); + } + } + } + return NULL; + } + } diff --git a/CRM/Utils/DeprecatedUtils.php b/CRM/Utils/DeprecatedUtils.php index 8f8b27cf4c..1fe35cc8da 100644 --- a/CRM/Utils/DeprecatedUtils.php +++ b/CRM/Utils/DeprecatedUtils.php @@ -101,69 +101,6 @@ function _civicrm_api3_deprecated_check_contact_dedupe($params) { return _civicrm_api3_deprecated_duplicate_formatted_contact($contactFormatted); } -/** - * take the input parameter list as specified in the data model and - * convert it into the same format that we use in QF and BAO object - * - * @param array $params - * Associative array of property name/value. - * pairs to insert in new contact. - * @param array $values - * The reformatted properties that we can use internally. - * - * @param array|bool $create Is the formatted Values array going to - * be used for CRM_Activity_BAO_Activity::create() - * - * @return array|CRM_Error - */ -function _civicrm_api3_deprecated_activity_formatted_param(&$params, &$values, $create = FALSE) { - // copy all the activity fields as is - $fields = CRM_Activity_DAO_Activity::fields(); - _civicrm_api3_store_values($fields, $params, $values); - - require_once 'CRM/Core/OptionGroup.php'; - $customFields = CRM_Core_BAO_CustomField::getFields('Activity'); - - foreach ($params as $key => $value) { - // ignore empty values or empty arrays etc - if (CRM_Utils_System::isNull($value)) { - continue; - } - - //Handling Custom Data - if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($key)) { - $values[$key] = $value; - $type = $customFields[$customFieldID]['html_type']; - if (CRM_Core_BAO_CustomField::isSerialized($customFields[$customFieldID])) { - $values[$key] = CRM_Import_Parser::unserializeCustomValue($customFieldID, $value, $type); - } - elseif ($type == 'Select' || $type == 'Radio') { - $customOption = CRM_Core_BAO_CustomOption::getCustomOption($customFieldID, TRUE); - foreach ($customOption as $customFldID => $customValue) { - $val = $customValue['value'] ?? NULL; - $label = $customValue['label'] ?? NULL; - $label = strtolower($label); - $value = strtolower(trim($value)); - if (($value == $label) || ($value == strtolower($val))) { - $values[$key] = $val; - } - } - } - } - - if ($key == 'target_contact_id') { - if (!CRM_Utils_Rule::integer($value)) { - return civicrm_api3_create_error("contact_id not valid: $value"); - } - $contactID = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_contact WHERE id = $value"); - if (!$contactID) { - return civicrm_api3_create_error("Invalid Contact ID: There is no contact record with contact_id = $value."); - } - } - } - return NULL; -} - /** * This function adds the contact variable in $values to the * parameter list $params. For most cases, $values should have length 1. If -- 2.25.1