✨️ implement upgrade function to create new custom fields
This commit is contained in:
parent
4dc3644bb3
commit
ab8c16fac2
4 changed files with 65 additions and 11 deletions
|
@ -29,7 +29,7 @@ class CRM_TwingleCampaign_BAO_CampaignType {
|
|||
/**
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*/
|
||||
public function create() {
|
||||
public function create(bool $upgrade = false) {
|
||||
|
||||
$field = civicrm_api3(
|
||||
'OptionValue',
|
||||
|
@ -59,7 +59,7 @@ class CRM_TwingleCampaign_BAO_CampaignType {
|
|||
for \"$this->label\": $error_message");
|
||||
}
|
||||
}
|
||||
else {
|
||||
elseif (!$upgrade) {
|
||||
$campaignType = self::fetch($this->name);
|
||||
foreach ($this as $var => $value) {
|
||||
if (array_key_exists($var, $campaignType->getSetAttributes())) {
|
||||
|
@ -67,6 +67,9 @@ class CRM_TwingleCampaign_BAO_CampaignType {
|
|||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->value = $field['values'][0]['value'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -65,9 +65,12 @@ class CRM_TwingleCampaign_BAO_CustomField {
|
|||
/**
|
||||
* Creates a CustomField by calling CiviCRM API v.3
|
||||
*
|
||||
* @param bool $upgrade
|
||||
* If true: Does not show UF message if custom field already exists
|
||||
*
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*/
|
||||
public function create() {
|
||||
public function create(bool $upgrade = false) {
|
||||
|
||||
// Check if the field already exists
|
||||
$field = civicrm_api3(
|
||||
|
@ -118,14 +121,10 @@ class CRM_TwingleCampaign_BAO_CustomField {
|
|||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
CRM_Utils_System::setUFMessage("Creation of custom field '$this->name'
|
||||
failed, because a custom field with that name already exists.
|
||||
Find more information in the logs.");
|
||||
elseif (!$upgrade) {
|
||||
CRM_Utils_System::setUFMessage(E::ts('Creation of custom field \'%1\' failed, because a custom field with that name already exists. Find more information in the logs.', [1 => $this->name]));
|
||||
Civi::log()
|
||||
->error("$this->extensionName could not create new custom field
|
||||
\"$this->name\" for group \"$this->custom_group_id\" because a
|
||||
field with that name already exists.");
|
||||
->error("$this->extensionName could not create new custom field \"$this->name\" for group \"$this->custom_group_id\" because a field with that name already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,9 +41,12 @@ class CRM_TwingleCampaign_BAO_CustomGroup {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param bool $upgrade
|
||||
* If true: Does not show UF message if custom group already exists
|
||||
*
|
||||
* @throws \CiviCRM_API3_Exception
|
||||
*/
|
||||
public function create() {
|
||||
public function create(bool $upgrade = false) {
|
||||
|
||||
$field = civicrm_api3(
|
||||
'CustomGroup',
|
||||
|
@ -86,6 +89,11 @@ class CRM_TwingleCampaign_BAO_CustomGroup {
|
|||
|
||||
}
|
||||
}
|
||||
elseif (!$upgrade) {
|
||||
CRM_Utils_System::setUFMessage(E::ts('Creation of custom group \'%1\' failed, because a custom group with that name already exists. Find more information in the logs.', [1 => $this->name]));
|
||||
Civi::log()
|
||||
->error("$this->extensionName could not create new custom group \"$this->name\" because a group with that name already exists.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue