🐛 Fix bug #5: Error when altering any case type

This commit is contained in:
Marc Michalsky 2021-12-17 09:05:51 +01:00
parent 0a93756e03
commit 482b8e2d0d

View file

@ -205,6 +205,19 @@ class CRM_TwingleCampaign_BAO_CustomField {
try {
foreach ($options as $key => $value) {
$option_value_exists = civicrm_api3(
'OptionValue',
'get',
[
'sequential' => 1,
'option_group_id' => $option_group_id,
'value' => $key,
]
);
// If the option value does not yet exist, create it
if ($option_value_exists['count'] == 0) {
$result[] = civicrm_api3(
'OptionValue',
'create',
@ -215,6 +228,18 @@ class CRM_TwingleCampaign_BAO_CustomField {
]
);
}
// If the option value already exist, update it
else {
$result[] = civicrm_api3(
'OptionValue',
'create',
[
'id' => $option_value_exists['values'][0]['id'],
'label' => $value,
]
);
}
}
} catch (CiviCRM_API3_Exception $e) {
$errorMessage = $e->getMessage();
Civi::log()