Merge pull request #21554 from eileenmcnaughton/loop
[civicrm-core.git] / CRM / Upgrade / Incremental / Base.php
index 940fb3b0d1bb5034857b92f92517287414a13c38..355dbcb3def33df199928dcf0e823adc7d22b0e9 100644 (file)
@@ -220,6 +220,26 @@ class CRM_Upgrade_Incremental_Base {
     return TRUE;
   }
 
+  /**
+   * Add the specified option group, gracefully if it already exists.
+   *
+   * @param CRM_Queue_TaskContext $ctx
+   * @param array $params
+   * @param array $options
+   *
+   * @return bool
+   */
+  public static function addOptionGroup(CRM_Queue_TaskContext $ctx, $params, $options): bool {
+    $defaults = ['is_active' => 1];
+    $optionDefaults = ['is_active' => 1];
+    $optionDefaults['option_group_id'] = \CRM_Core_BAO_OptionGroup::ensureOptionGroupExists(array_merge($defaults, $params));
+
+    foreach ($options as $option) {
+      \CRM_Core_BAO_OptionValue::ensureOptionValueExists(array_merge($optionDefaults, $option));
+    }
+    return TRUE;
+  }
+
   /**
    * Do any relevant message template updates.
    *
@@ -249,7 +269,7 @@ class CRM_Upgrade_Incremental_Base {
   }
 
   /**
-   * Updated a message token within a template.
+   * Updated a message token within a scheduled reminder.
    *
    * @param CRM_Queue_TaskContext $ctx
    * @param string $old
@@ -264,6 +284,22 @@ class CRM_Upgrade_Incremental_Base {
     return TRUE;
   }
 
+  /**
+   * Updated a message token within a template.
+   *
+   * @param CRM_Queue_TaskContext $ctx
+   * @param string $old
+   * @param string $new
+   * @param $version
+   *
+   * @return bool
+   */
+  public static function updatePrintLabelToken($ctx, string $old, string $new, $version):bool {
+    $messageObj = new CRM_Upgrade_Incremental_MessageTemplates($version);
+    $messageObj->replaceTokenInPrintLabel($old, $new);
+    return TRUE;
+  }
+
   /**
    * Re-save any valid values from contribute settings into the normal setting
    * format.