🐛 Fix bug #5: Error when altering any case type
This commit is contained in:
parent
0a93756e03
commit
482b8e2d0d
1 changed files with 28 additions and 3 deletions
|
@ -205,15 +205,40 @@ class CRM_TwingleCampaign_BAO_CustomField {
|
|||
|
||||
try {
|
||||
foreach ($options as $key => $value) {
|
||||
$result[] = civicrm_api3(
|
||||
|
||||
$option_value_exists = civicrm_api3(
|
||||
'OptionValue',
|
||||
'create',
|
||||
'get',
|
||||
[
|
||||
'sequential' => 1,
|
||||
'option_group_id' => $option_group_id,
|
||||
'value' => $key,
|
||||
'label' => $value,
|
||||
]
|
||||
);
|
||||
|
||||
// If the option value does not yet exist, create it
|
||||
if ($option_value_exists['count'] == 0) {
|
||||
$result[] = civicrm_api3(
|
||||
'OptionValue',
|
||||
'create',
|
||||
[
|
||||
'option_group_id' => $option_group_id,
|
||||
'value' => $key,
|
||||
'label' => $value,
|
||||
]
|
||||
);
|
||||
}
|
||||
// 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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue