Ejegg has submitted this change and it was merged.

Change subject: CRM-17951 (merged into 4.7) Add function to safe-add option 
values in upgrade
......................................................................


CRM-17951 (merged into 4.7) Add function to safe-add option values in upgrade

THis allows us to pre-add option values without hitting problems on upgrade.

THe primary gain is that the upstream script uses it but I prefer us to use the 
same functions

Bug: T124979

Change-Id: I7043c9d57733b3ebe2180cedbf513316456faf47
---
M CRM/Core/BAO/OptionValue.php
1 file changed, 18 insertions(+), 0 deletions(-)

Approvals:
  Ejegg: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/CRM/Core/BAO/OptionValue.php b/CRM/Core/BAO/OptionValue.php
index 116bcbc..a33c795 100644
--- a/CRM/Core/BAO/OptionValue.php
+++ b/CRM/Core/BAO/OptionValue.php
@@ -518,4 +518,22 @@
     return $options;
   }
 
+  /**
+   * Ensure an option value exists.
+   *
+   * This function is intended to be called from the upgrade script to ensure
+   * that an option value exists, without hitting an error if it already 
exists.
+   *
+   * This is sympathetic to sites who might pre-add it.
+   */
+  public static function ensureOptionValueExists($params) {
+    $existingValues = civicrm_api3('OptionValue', 'get', array(
+      'option_group_name' => $params['option_group_id'],
+      'name' => $params['name'],
+    ));
+    if (!$existingValues['count']) {
+      civicrm_api3('OptionValue', 'create', $params);
+    }
+  }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/268448
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7043c9d57733b3ebe2180cedbf513316456faf47
Gerrit-PatchSet: 2
Gerrit-Project: wikimedia/fundraising/crm/civicrm
Gerrit-Branch: master
Gerrit-Owner: Eileen <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to