Fix event template cache not updating. Replace some deprecated functions with API4
authorMatthew Wire <mjw@mjwconsult.co.uk>
Mon, 31 Oct 2022 13:34:09 +0000 (13:34 +0000)
committerMatthew Wire <mjw@mjwconsult.co.uk>
Mon, 31 Oct 2022 17:00:33 +0000 (17:00 +0000)
CRM/Event/Form/ManageEvent.php
CRM/Event/Form/ManageEvent/EventInfo.php
CRM/Event/PseudoConstant.php
CRM/Member/BAO/Membership.php
Civi/ActionSchedule/Mapping.php

index 4f2030fd849865a2bc8e52fd083a42ef8874a0a0..1de4476ef31ada8d578c8d35b7ebd990acbcf0a5 100644 (file)
@@ -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']);
index 3a649b8d43228407b9465a597c50caddc4854a99..b2580895302298c2af258f2f72de537943e1021b 100644 (file)
@@ -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 <a href="%1">Event Templates</a> feature to streamline your workflow.', [1 => $url]), ts('Tip'), 'info');
index 1543f86709eb1f5b95bab197945e41765d673ab8..ca1ad28386c2acadcdc307bafead5e4ba651b2a4 100644 (file)
@@ -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',
index 0ad479b80166a3b5aaf690c69999953ac804765e..608619ec19fef87c410c2ef493381af1934dddfe 100644 (file)
@@ -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;
index fc0e667b4d85ebe92e3ff710c4e04dc934c95fd6..2c092ddcea2e1f22619be7db95f8e6af456920f5 100644 (file)
@@ -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();