From 681aed959e92499d9ef71b01e8159a4462fe4c2a Mon Sep 17 00:00:00 2001 From: Marc Michalsky forumZFD Date: Thu, 25 Feb 2021 17:40:28 +0100 Subject: [PATCH] Add user interface messages on creation fails during installation --- CRM/TwingleCampaign/BAO/CustomField.php | 19 +++++++++++++++++-- CRM/TwingleCampaign/BAO/CustomGroup.php | 10 ++++++++-- CRM/TwingleCampaign/BAO/OptionValue.php | 13 +++++++++++++ 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/CRM/TwingleCampaign/BAO/CustomField.php b/CRM/TwingleCampaign/BAO/CustomField.php index 7af8028..6eeb440 100644 --- a/CRM/TwingleCampaign/BAO/CustomField.php +++ b/CRM/TwingleCampaign/BAO/CustomField.php @@ -100,20 +100,35 @@ class CRM_TwingleCampaign_BAO_CustomField { } // If the field could not get created: log error else { - if ($this->label && $this->custom_group_id) { + if ($this->name && $this->custom_group_id) { Civi::log() ->error("$this->extensionName could not create new custom field - \"$this->label\" for group \"$this->custom_group_id\": + \"$this->name\" for group \"$this->custom_group_id\": $this->result['error_message']"); + CRM_Utils_System::setUFMessage(ts("Creation of custom field '%1' + failed. Find more information in the logs.", + $this->name)); } // If there is not enough information: log simple error message else { Civi::log() ->error("$this->extensionName could not create new custom field: $this->result['error_message']"); + CRM_Utils_System::setUFMessage(ts("Creation of custom field + failed. Find more information in the logs.")); } } } + else { + CRM_Utils_System::setUFMessage(ts("Creation of custom field '%1' + failed, because a custom field with that name already exists. + Find more information in the logs.", + $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."); + } } /** diff --git a/CRM/TwingleCampaign/BAO/CustomGroup.php b/CRM/TwingleCampaign/BAO/CustomGroup.php index 5bb1361..272a341 100644 --- a/CRM/TwingleCampaign/BAO/CustomGroup.php +++ b/CRM/TwingleCampaign/BAO/CustomGroup.php @@ -70,15 +70,21 @@ class CRM_TwingleCampaign_BAO_CustomGroup { ); } else { - if ($this->title) { + if ($this->name) { Civi::log()->error("$this->extensionName could not create new custom group - for \"$this->title\": $this->results['error_message']" + for \"$this->name\": $this->results['error_message']" ); + CRM_Utils_System::setUFMessage(ts("Creation of custom group '%1' + failed. Find more information in the logs.", + $this->name)); } else { Civi::log()->error("$this->extensionName could not create new custom group: $this->results['error_message']"); + CRM_Utils_System::setUFMessage(ts("Creation of custom group + failed. Find more information in the logs.")); } + } } } diff --git a/CRM/TwingleCampaign/BAO/OptionValue.php b/CRM/TwingleCampaign/BAO/OptionValue.php index f63a7d2..90d3fdf 100644 --- a/CRM/TwingleCampaign/BAO/OptionValue.php +++ b/CRM/TwingleCampaign/BAO/OptionValue.php @@ -79,6 +79,9 @@ class CRM_TwingleCampaign_BAO_OptionValue { } // If the option value could not get created: log error else { + CRM_Utils_System::setUFMessage(ts("Creation of custom value '%1' + failed. Find more information in the logs.", + $this->name)); if ($this->label && $this->option_group_id) { Civi::log() ->error("$this->extensionName could not create new option value @@ -93,6 +96,16 @@ class CRM_TwingleCampaign_BAO_OptionValue { } } } + else { + CRM_Utils_System::setUFMessage(ts("Creation of custom value '%1' + failed, because a custom value with that name already exists. + Find more information in the logs.", + $this->name)); + Civi::log() + ->error("$this->extensionName could not create new custom value + \"$this->name\" for group \"$this->option_group_id\" because a + value with that name already exists."); + } }