From: Matthew Wire Date: Mon, 31 Oct 2022 13:34:09 +0000 (+0000) Subject: Fix event template cache not updating. Replace some deprecated functions with API4 X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=ce053785e026e1d49e32dbc54cab9b0f2ba7d1df;p=civicrm-core.git Fix event template cache not updating. Replace some deprecated functions with API4 --- diff --git a/CRM/Event/Form/ManageEvent.php b/CRM/Event/Form/ManageEvent.php index 4f2030fd84..1de4476ef3 100644 --- a/CRM/Event/Form/ManageEvent.php +++ b/CRM/Event/Form/ManageEvent.php @@ -104,8 +104,10 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form { } $this->_single = TRUE; - $params = ['id' => $this->_id]; - CRM_Event_BAO_Event::retrieve($params, $eventInfo); + $eventInfo = \Civi\Api4\Event::get(FALSE) + ->addWhere('id', '=', $this->_id) + ->execute() + ->first(); // its an update mode, do a permission check if (!CRM_Event_BAO_Event::checkPermission($this->_id, CRM_Core_Permission::EDIT)) { @@ -228,15 +230,15 @@ class CRM_Event_Form_ManageEvent extends CRM_Core_Form { */ public function setDefaultValues() { $defaults = []; + $event = \Civi\Api4\Event::get(FALSE); if (isset($this->_id)) { - $params = ['id' => $this->_id]; - CRM_Event_BAO_Event::retrieve($params, $defaults); - + $event->addWhere('id', '=', $this->_id); + $defaults = $event->execute()->first(); $this->_campaignID = $defaults['campaign_id'] ?? NULL; } elseif ($this->_templateId) { - $params = ['id' => $this->_templateId]; - CRM_Event_BAO_Event::retrieve($params, $defaults); + $event->addWhere('id', '=', $this->_templateId); + $defaults = $event->execute()->first(); $defaults['is_template'] = $this->_isTemplate; $defaults['template_id'] = $defaults['id']; unset($defaults['id']); diff --git a/CRM/Event/Form/ManageEvent/EventInfo.php b/CRM/Event/Form/ManageEvent/EventInfo.php index 3a649b8d43..b258089530 100644 --- a/CRM/Event/Form/ManageEvent/EventInfo.php +++ b/CRM/Event/Form/ManageEvent/EventInfo.php @@ -123,7 +123,12 @@ class CRM_Event_Form_ManageEvent_EventInfo extends CRM_Event_Form_ManageEvent { } if ($this->_action & CRM_Core_Action::ADD) { - $eventTemplates = CRM_Event_PseudoConstant::eventTemplates(); + $eventTemplates = \Civi\Api4\Event::get(FALSE) + ->addWhere('is_template', '=', TRUE) + ->addWhere('is_active', '=', TRUE) + ->execute() + ->indexBy('id') + ->column('template_title'); if (CRM_Utils_System::isNull($eventTemplates) && !$this->_isTemplate) { $url = CRM_Utils_System::url('civicrm/admin/eventTemplate', ['reset' => 1]); CRM_Core_Session::setStatus(ts('If you find that you are creating multiple events with similar settings, you may want to use the Event Templates feature to streamline your workflow.', [1 => $url]), ts('Tip'), 'info'); diff --git a/CRM/Event/PseudoConstant.php b/CRM/Event/PseudoConstant.php index 1543f86709..ca1ad28386 100644 --- a/CRM/Event/PseudoConstant.php +++ b/CRM/Event/PseudoConstant.php @@ -254,8 +254,11 @@ class CRM_Event_PseudoConstant extends CRM_Core_PseudoConstant { * * @return array * Array of event id → template title pairs + * + * @deprecated Use the API instead */ public static function &eventTemplates($id = NULL) { + CRM_Core_Error::deprecatedFunctionWarning('Use the api'); if (!self::$eventTemplates) { CRM_Core_PseudoConstant::populate(self::$eventTemplates, 'CRM_Event_DAO_Event', diff --git a/CRM/Member/BAO/Membership.php b/CRM/Member/BAO/Membership.php index 0ad479b801..608619ec19 100644 --- a/CRM/Member/BAO/Membership.php +++ b/CRM/Member/BAO/Membership.php @@ -1129,7 +1129,7 @@ AND civicrm_membership.is_test = %2"; * @param \CRM_Contribute_BAO_Contribution|\CRM_Contribute_DAO_Contribution $contribution */ public static function updateRecurMembership(CRM_Member_DAO_Membership $membership, CRM_Contribute_BAO_Contribution $contribution) { - CRM_Core_Error::deprecatedFunctionWarning('Use the API instead'); + CRM_Core_Error::deprecatedFunctionWarning('Use the api'); if (empty($contribution->contribution_recur_id)) { return; diff --git a/Civi/ActionSchedule/Mapping.php b/Civi/ActionSchedule/Mapping.php index fc0e667b4d..2c092ddcea 100644 --- a/Civi/ActionSchedule/Mapping.php +++ b/Civi/ActionSchedule/Mapping.php @@ -278,7 +278,12 @@ abstract class Mapping implements MappingInterface { $valueLabelMap['event_type'] = \CRM_Event_PseudoConstant::eventType(); $valueLabelMap['civicrm_event'] = \CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )"); $valueLabelMap['civicrm_participant_status_type'] = \CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label'); - $valueLabelMap['event_template'] = \CRM_Event_PseudoConstant::eventTemplates(); + $valueLabelMap['event_template'] = \Civi\Api4\Event::get(FALSE) + ->addWhere('is_template', '=', TRUE) + ->addWhere('is_active', '=', TRUE) + ->execute() + ->indexBy('id') + ->column('template_title'); $valueLabelMap['auto_renew_options'] = \CRM_Core_OptionGroup::values('auto_renew_options'); $valueLabelMap['contact_date_reminder_options'] = \CRM_Core_OptionGroup::values('contact_date_reminder_options'); $valueLabelMap['civicrm_membership_type'] = \CRM_Member_PseudoConstant::membershipType();