From fc076fe3fbe3fd15336c3cf32427f8d88c858f95 Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 17 Feb 2020 21:04:00 +1300 Subject: [PATCH] Fix theoretical regression This PR https://github.com/civicrm/civicrm-core/pull/16363/commits/44237a295dc5eab4f6110fb0556b1af742364f6e (merged to 5.23) calls self::::getDefaultRoleID() in a way that was always flawed but definitely woudl not work now. I think it is never reached but better to put this fix into 5.23 & maybe reemove the line in master later since it assumes participant_status_id is optional - which is not true of the backoffice form --- CRM/Event/BAO/Participant.php | 15 +++++++++++++++ CRM/Event/Form/Participant.php | 3 ++- CRM/Event/Form/Registration.php | 17 +---------------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/CRM/Event/BAO/Participant.php b/CRM/Event/BAO/Participant.php index bb64e18477..f134201cc4 100644 --- a/CRM/Event/BAO/Participant.php +++ b/CRM/Event/BAO/Participant.php @@ -969,6 +969,21 @@ WHERE civicrm_participant.id = {$participantId} } } + /** + * Get the ID of the default (first) participant role + * + * @return int + * @throws \CiviCRM_API3_Exception + */ + public static function getDefaultRoleID() { + return (int) civicrm_api3('OptionValue', 'getvalue', [ + 'return' => 'value', + 'option_group_id' => 'participant_role', + 'is_active' => 1, + 'options' => ['limit' => 1, 'sort' => 'is_default DESC'], + ]); + } + /** * Get the additional participant ids. * diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 1da70c725f..d1d5a95861 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -2102,6 +2102,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment * * @return \CRM_Event_BAO_Participant * @throws \CRM_Core_Exception + * @throws \CiviCRM_API3_Exception */ protected function addParticipant(&$form, $params, $contactID) { $transaction = new CRM_Core_Transaction(); @@ -2114,7 +2115,7 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment 'status_id' => CRM_Utils_Array::value('participant_status', $params, 1 ), - 'role_id' => CRM_Utils_Array::value('participant_role_id', $params) ?: self::getDefaultRoleID(), + 'role_id' => CRM_Utils_Array::value('participant_role_id', $params) ?: CRM_Event_BAO_Participant::getDefaultRoleID(), 'register_date' => $params['register_date'], 'source' => CRM_Utils_String::ellipsify( isset($params['participant_source']) ? CRM_Utils_Array::value('participant_source', $params) : CRM_Utils_Array::value('description', $params), diff --git a/CRM/Event/Form/Registration.php b/CRM/Event/Form/Registration.php index dd9635767c..f6a19f5d86 100644 --- a/CRM/Event/Form/Registration.php +++ b/CRM/Event/Form/Registration.php @@ -806,7 +806,7 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { 'status_id' => CRM_Utils_Array::value('participant_status', $params, 1 ), - 'role_id' => CRM_Utils_Array::value('participant_role_id', $params) ?: self::getDefaultRoleID(), + 'role_id' => CRM_Utils_Array::value('participant_role_id', $params) ?: CRM_Event_BAO_Participant::getDefaultRoleID(), 'register_date' => ($registerDate) ? $registerDate : date('YmdHis'), 'source' => CRM_Utils_String::ellipsify( isset($params['participant_source']) ? CRM_Utils_Array::value('participant_source', $params) : CRM_Utils_Array::value('description', $params), @@ -858,21 +858,6 @@ class CRM_Event_Form_Registration extends CRM_Core_Form { return $participant; } - /** - * Get the ID of the default (first) participant role - * - * @return int - * @throws \CiviCRM_API3_Exception - */ - private static function getDefaultRoleID() { - return (int) civicrm_api3('OptionValue', 'getvalue', [ - 'return' => "value", - 'option_group_id' => "participant_role", - 'is_active' => 1, - 'options' => ['limit' => 1, 'sort' => "is_default DESC"], - ]); - } - /** * Calculate the total participant count as per params. * -- 2.25.1