From 1a5d4d8afffcc7827baec1f0d5cbfcf31de8d722 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 12 Jan 2021 15:20:39 +1300 Subject: [PATCH] Move another deprecated utils function Function is only called from one class, relocate there --- CRM/Event/Import/Parser/Participant.php | 62 ++++++++++++++++++++++++- CRM/Utils/DeprecatedUtils.php | 58 ----------------------- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/CRM/Event/Import/Parser/Participant.php b/CRM/Event/Import/Parser/Participant.php index 3bb21269c1..7d12aa44cf 100644 --- a/CRM/Event/Import/Parser/Participant.php +++ b/CRM/Event/Import/Parser/Participant.php @@ -353,7 +353,7 @@ class CRM_Event_Import_Parser_Participant extends CRM_Event_Import_Parser { ]; $participantValues = []; //@todo calling api functions directly is not supported - $newParticipant = _civicrm_api3_deprecated_participant_check_params($formatted, $participantValues, FALSE); + $newParticipant = $this->deprecated_participant_check_params($formatted, $participantValues, FALSE); if ($newParticipant['error_message']) { array_unshift($values, $newParticipant['error_message']); return CRM_Import_Parser::ERROR; @@ -637,7 +637,7 @@ class CRM_Event_Import_Parser_Participant extends CRM_Event_Import_Parser { protected function deprecated_create_participant_formatted($params, $onDuplicate) { if ($onDuplicate != CRM_Import_Parser::DUPLICATE_NOCHECK) { CRM_Core_Error::reset(); - $error = _civicrm_api3_deprecated_participant_check_params($params, TRUE); + $error = $this->deprecated_participant_check_params($params, TRUE); if (civicrm_error($error)) { return $error; } @@ -645,4 +645,62 @@ class CRM_Event_Import_Parser_Participant extends CRM_Event_Import_Parser { return civicrm_api3_participant_create($params); } + /** + * Formatting that was written a long time ago and may not make sense now. + * + * @param array $params + * + * @param bool $checkDuplicate + * + * @return array|bool + */ + protected function deprecated_participant_check_params($params, $checkDuplicate = FALSE) { + + // check if participant id is valid or not + if (!empty($params['id'])) { + $participant = new CRM_Event_BAO_Participant(); + $participant->id = $params['id']; + if (!$participant->find(TRUE)) { + return civicrm_api3_create_error(ts('Participant id is not valid')); + } + } + + // check if contact id is valid or not + if (!empty($params['contact_id'])) { + $contact = new CRM_Contact_BAO_Contact(); + $contact->id = $params['contact_id']; + if (!$contact->find(TRUE)) { + return civicrm_api3_create_error(ts('Contact id is not valid')); + } + } + + // check that event id is not an template + if (!empty($params['event_id'])) { + $isTemplate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'is_template'); + if (!empty($isTemplate)) { + return civicrm_api3_create_error(ts('Event templates are not meant to be registered.')); + } + } + + $result = []; + if ($checkDuplicate) { + if (CRM_Event_BAO_Participant::checkDuplicate($params, $result)) { + $participantID = array_pop($result); + + $error = CRM_Core_Error::createError("Found matching participant record.", + CRM_Core_Error::DUPLICATE_PARTICIPANT, + 'Fatal', $participantID + ); + + return civicrm_api3_create_error($error->pop(), + [ + 'contactID' => $params['contact_id'], + 'participantID' => $participantID, + ] + ); + } + } + return TRUE; + } + } diff --git a/CRM/Utils/DeprecatedUtils.php b/CRM/Utils/DeprecatedUtils.php index d0103127ad..d7e4fcbce7 100644 --- a/CRM/Utils/DeprecatedUtils.php +++ b/CRM/Utils/DeprecatedUtils.php @@ -410,61 +410,3 @@ function _civicrm_api3_deprecated_duplicate_formatted_contact($params) { } return civicrm_api3_create_success(TRUE); } - -/** - * - * @param array $params - * - * @param bool $checkDuplicate - * - * @return array|bool - * - */ -function _civicrm_api3_deprecated_participant_check_params($params, $checkDuplicate = FALSE) { - - // check if participant id is valid or not - if (!empty($params['id'])) { - $participant = new CRM_Event_BAO_Participant(); - $participant->id = $params['id']; - if (!$participant->find(TRUE)) { - return civicrm_api3_create_error(ts('Participant id is not valid')); - } - } - require_once 'CRM/Contact/BAO/Contact.php'; - // check if contact id is valid or not - if (!empty($params['contact_id'])) { - $contact = new CRM_Contact_BAO_Contact(); - $contact->id = $params['contact_id']; - if (!$contact->find(TRUE)) { - return civicrm_api3_create_error(ts('Contact id is not valid')); - } - } - - // check that event id is not an template - if (!empty($params['event_id'])) { - $isTemplate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $params['event_id'], 'is_template'); - if (!empty($isTemplate)) { - return civicrm_api3_create_error(ts('Event templates are not meant to be registered.')); - } - } - - $result = []; - if ($checkDuplicate) { - if (CRM_Event_BAO_Participant::checkDuplicate($params, $result)) { - $participantID = array_pop($result); - - $error = CRM_Core_Error::createError("Found matching participant record.", - CRM_Core_Error::DUPLICATE_PARTICIPANT, - 'Fatal', $participantID - ); - - return civicrm_api3_create_error($error->pop(), - [ - 'contactID' => $params['contact_id'], - 'participantID' => $participantID, - ] - ); - } - } - return TRUE; -} -- 2.25.1