Merge pull request #17940 from eileenmcnaughton/abort
[civicrm-core.git] / CRM / Core / OptionGroup.php
index 97af275ded0507c7ef8446f881e92b116b46abf7..89018c1a21cf987980be1c6d255c55fc97aa13e9 100644 (file)
@@ -439,8 +439,6 @@ WHERE  v.option_group_id = g.id
 
   /**
    * Creates a new option group with the passed in values.
-   * @TODO: Should update the group if it already exists intelligently, so multi-lingual is
-   * not messed up. Currently deletes the old group
    *
    * @param string $groupName
    *   The name of the option group - make sure there is no conflict.
@@ -464,10 +462,10 @@ WHERE  v.option_group_id = g.id
    *   the option group ID
    */
   public static function createAssoc($groupName, &$values, &$defaultID, $groupTitle = NULL) {
-    self::deleteAssoc($groupName);
     if (!empty($values)) {
       $group = new CRM_Core_DAO_OptionGroup();
       $group->name = $groupName;
+      $group->find(TRUE);
       $group->title = empty($groupTitle) ? $groupName : $groupTitle;
       $group->is_reserved = 1;
       $group->is_active = 1;
@@ -476,13 +474,14 @@ WHERE  v.option_group_id = g.id
       foreach ($values as $v) {
         $value = new CRM_Core_DAO_OptionValue();
         $value->option_group_id = $group->id;
-        $value->label = $v['label'];
         $value->value = $v['value'];
-        $value->name = CRM_Utils_Array::value('name', $v);
-        $value->description = CRM_Utils_Array::value('description', $v);
-        $value->weight = CRM_Utils_Array::value('weight', $v);
-        $value->is_default = CRM_Utils_Array::value('is_default', $v);
-        $value->is_active = CRM_Utils_Array::value('is_active', $v);
+        $value->find(TRUE);
+        $value->label = $v['label'];
+        $value->name = $v['name'] ?? NULL;
+        $value->description = $v['description'] ?? NULL;
+        $value->weight = $v['weight'] ?? NULL;
+        $value->is_default = $v['is_default'] ?? NULL;
+        $value->is_active = $v['is_active'] ?? NULL;
         $value->save();
 
         if ($value->is_default) {
@@ -502,8 +501,11 @@ WHERE  v.option_group_id = g.id
    * @param $values
    * @param bool $flip
    * @param string $field
+   *
+   * @deprecated
    */
   public static function getAssoc($groupName, &$values, $flip = FALSE, $field = 'name') {
+    CRM_Core_Error::deprecatedFunctionWarning('unused function');
     $query = "
 SELECT v.id as amount_id, v.value, v.label, v.name, v.description, v.weight
   FROM civicrm_option_group g,
@@ -546,8 +548,11 @@ ORDER BY v.weight
   /**
    * @param string $groupName
    * @param string $operator
+   *
+   * @deprecated
    */
   public static function deleteAssoc($groupName, $operator = "=") {
+    CRM_Core_Error::deprecatedFunctionWarning('unused function');
     $query = "
 DELETE g, v
   FROM civicrm_option_group g,