From d9e51c67f6f50aa8a3825bb9496e4e4fd04ee70c Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Thu, 3 Aug 2023 15:06:27 +0200 Subject: [PATCH 01/10] use the id instead of the name to look up profiles --- CRM/Twingle/Form/Profile.php | 54 ++++---- CRM/Twingle/Page/Profiles.php | 7 +- CRM/Twingle/Profile.php | 164 +++++++++++++++++------- templates/CRM/Twingle/Page/Profiles.tpl | 9 +- 4 files changed, 157 insertions(+), 77 deletions(-) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index efffdce..d7fe333 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -32,6 +32,12 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { */ protected $profile; + /** + * The ID of this profile. + * @var int|NULL + */ + protected $profile_id = NULL; + /** * @var string * @@ -142,10 +148,11 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { $this->_op = 'create'; } - // Verify that a profile with the given name exists. - $profile_name = CRM_Utils_Request::retrieve('name', 'String', $this); - if (!$this->profile = CRM_Twingle_Profile::getProfile($profile_name)) { - $profile_name = NULL; + // Verify that a profile with the given id exists. + + if ($this->_op != 'copy') { + $this->profile_id = CRM_Utils_Request::retrieve('id', 'Int', $this); + $this->profile = CRM_Twingle_Profile::getProfile($this->profile_id); } // Set redirect destination. @@ -153,12 +160,12 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { switch ($this->_op) { case 'delete': - if ($profile_name) { - CRM_Utils_System::setTitle(E::ts('Delete Twingle API profile %1', [1 => $profile_name])); + if ($this->profile_id) { + CRM_Utils_System::setTitle(E::ts('Delete Twingle API profile %1', [1 => $this->profile->getName()])); $this->addButtons([ [ 'type' => 'submit', - 'name' => ($profile_name == 'default' ? E::ts('Reset') : E::ts('Delete')), + 'name' => ($this->profile->getName() == 'default' ? E::ts('Reset') : E::ts('Delete')), 'isDefault' => TRUE, ], ]); @@ -166,40 +173,37 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { parent::buildQuickForm(); return; - case 'edit': - // When editing without a valid profile name, edit the default profile. - if (!$profile_name) { - $profile_name = 'default'; - $this->profile = CRM_Twingle_Profile::getProfile($profile_name); - } - CRM_Utils_System::setTitle(E::ts('Edit Twingle API profile %1', [1 => $this->profile->getName()])); - break; - case 'copy': // Retrieve the source profile name. - $profile_name = CRM_Utils_Request::retrieve('source_name', 'String', $this); - // When copying without a valid profile name, copy the default profile. - if (!$profile_name) { - $profile_name = 'default'; + $source_id = CRM_Utils_Request::retrieve('source_id', 'Int', $this); + // When copying without a valid profile id, copy the default profile. + if (!$source_id) { + $this->profile = CRM_Twingle_Profile::createDefaultProfile(); + } else { + $source_profile = CRM_Twingle_Profile::getProfile($source_id); + $this->profile = $source_profile->copy(); } - $this->profile = clone CRM_Twingle_Profile::getProfile($profile_name); - // Propose a new name for this profile. - $profile_name = $profile_name . '_copy'; + $profile_name = $this->profile->getName() . '_copy'; $this->profile->setName($profile_name); CRM_Utils_System::setTitle(E::ts('New Twingle API profile')); break; + case 'edit': + CRM_Utils_System::setTitle(E::ts('Edit Twingle API profile %1', [1 => $this->profile->getName()])); + break; + case 'create': // Load factory default profile values. - $this->profile = CRM_Twingle_Profile::createDefaultProfile($profile_name); + $this->profile = CRM_Twingle_Profile::createDefaultProfile(E::ts('New Profile')); CRM_Utils_System::setTitle(E::ts('New Twingle API profile')); break; } // Assign template variables. $this->assign('op', $this->_op); - $this->assign('profile_name', $profile_name); + $this->assign('profile_name', $this->profile->getName()); + $this->assign('is_default', $this->profile->is_default()); // Add form elements. $is_default = $profile_name == 'default'; diff --git a/CRM/Twingle/Page/Profiles.php b/CRM/Twingle/Page/Profiles.php index e8f014b..919965d 100644 --- a/CRM/Twingle/Page/Profiles.php +++ b/CRM/Twingle/Page/Profiles.php @@ -22,10 +22,11 @@ class CRM_Twingle_Page_Profiles extends CRM_Core_Page { public function run() { CRM_Utils_System::setTitle(E::ts('Twingle API Profiles')); $profiles = []; - foreach (CRM_Twingle_Profile::getProfiles() as $profile_name => $profile) { - $profiles[$profile_name]['name'] = $profile_name; + foreach (CRM_Twingle_Profile::getProfiles() as $profile_id => $profile) { + $profiles[$profile_id]['id'] = $profile_id; + $profiles[$profile_id]['name'] = $profile->getName(); foreach (CRM_Twingle_Profile::allowedAttributes() as $attribute) { - $profiles[$profile_name][$attribute] = $profile->getAttribute($attribute); + $profiles[$profile_id][$attribute] = $profile->getAttribute($attribute); } } $this->assign('profiles', $profiles); diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index a78f576..ae62782 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -25,7 +25,13 @@ use Civi\Twingle\Exceptions\ProfileException as ProfileException; class CRM_Twingle_Profile { /** - * @var string + * @var int $id + * The id of the profile. + */ + protected $id = NULL; + + /** + * @var string $name * The name of the profile. */ protected $name = NULL; @@ -43,8 +49,10 @@ class CRM_Twingle_Profile { * The name of the profile. * @param array $data * The properties of the profile + * @param int|NULL $id */ - public function __construct($name, $data) { + public function __construct($name, $data, $id = NULL) { + $this->id = $id; $this->name = $name; $allowed_attributes = self::allowedAttributes(); $this->data = $data + array_combine( @@ -65,6 +73,18 @@ class CRM_Twingle_Profile { WHERE name = %1', [1 => [$this->name, 'String']]); } + /** + * Copy this profile by returning a clone with all unique information removed. + * + * @return CRM_Twingle_Profile + */ + public function copy() { + $copy = clone $this; + $copy->id = NULL; + $copy->data['selector'] = NULL; + return $copy; + } + /** * Checks whether the profile's selector matches the given project ID. * @@ -107,6 +127,24 @@ class CRM_Twingle_Profile { return $this->data; } + /** + * Retrieves the profile id. + * + * @return int + */ + public function getId() { + return $this->id; + } + + /** + * Set the profile id. + * + * @param int $id + */ + public function setId(int $id) { + $this->id = $id; + } + /** * Retrieves the profile name. * @@ -119,9 +157,9 @@ class CRM_Twingle_Profile { /** * Sets the profile name. * - * @param $name + * @param string $name */ - public function setName($name) { + public function setName(string $name) { $this->name = $name; } @@ -193,37 +231,76 @@ class CRM_Twingle_Profile { // make sure it's valid $this->verifyProfile(); - // check if the profile exists - $profile_id = CRM_Core_DAO::singleValueQuery( - 'SELECT id FROM civicrm_twingle_profile WHERE name = %1', [1 => [$this->name, 'String']]); - if ($profile_id) { - // existing profile -> just update the config - CRM_Core_DAO::executeQuery( - 'UPDATE civicrm_twingle_profile SET config = %2 WHERE name = %1', - [ - 1 => [$this->name, 'String'], - 2 => [json_encode($this->data), 'String'], - ]); + try { + if ($this->id !== NULL) { + // existing profile -> just update the config + CRM_Core_DAO::executeQuery( + "UPDATE civicrm_twingle_profile SET config = %2 WHERE id = %1", + [ + 1 => [$this->id, 'String'], + 2 => [json_encode($this->data), 'String'], + ]); + } + else { + // new profile -> add new entry to the DB + CRM_Core_DAO::executeQuery( + "INSERT IGNORE INTO civicrm_twingle_profile(name,config,last_access,access_counter) VALUES (%1, %2, null, 0)", + [ + 1 => [$this->name, 'String'], + 2 => [json_encode($this->data), 'String'], + ]); + } } - else { - // new profile -> add new entry to the DB - CRM_Core_DAO::executeQuery( - 'INSERT IGNORE INTO civicrm_twingle_profile(name,config,last_access,access_counter) VALUES (%1, %2, null, 0)', - [ - 1 => [$this->name, 'String'], - 2 => [json_encode($this->data), 'String'], - ]); + catch (Exception $e) { + throw new ProfileException( + E::ts("Could not save/update profile: %1", [1 => $e->getMessage()]), + ProfileException::ERROR_CODE_COULD_NOT_SAVE_PROFILE + ); } } /** * Deletes the profile from the database + * + * @throws \CRM_Twingle_Exceptions_ProfileException */ public function deleteProfile() { - CRM_Core_DAO::executeQuery( - 'DELETE FROM civicrm_twingle_profile WHERE name = %1', - [1 => [$this->name, 'String']] - ); + // Do only reset default profile + if ($this->getName() == 'default') { + try { + $default_profile = CRM_Twingle_Profile::createDefaultProfile(); + $default_profile->setId($this->getId()); + $default_profile->saveProfile(); + + // Reset counter + CRM_Core_DAO::executeQuery("UPDATE civicrm_twingle_profile SET access_counter = 0, last_access = NULL WHERE id = %1", [ + 1 => [ + $this->id, + 'Integer' + ] + ]); + } catch (Exception $e) { + throw new ProfileException( + E::ts("Could not reset default profile: %1", [1 => $e->getMessage()]), + ProfileException::ERROR_CODE_COULD_NOT_RESET_PROFILE + ); + } + } + else { + try { + CRM_Core_DAO::executeQuery("DELETE FROM civicrm_twingle_profile WHERE id = %1", [ + 1 => [ + $this->id, + 'Integer' + ] + ]); + } catch (Exception $e) { + throw new ProfileException( + E::ts("Could not delete profile: %1", [1 => $e->getMessage()]), + ProfileException::ERROR_CODE_COULD_NOT_RESET_PROFILE + ); + } + } } /** @@ -305,9 +382,9 @@ class CRM_Twingle_Profile { */ public static function createDefaultProfile($name = 'default') { return new CRM_Twingle_Profile($name, [ - 'selector' => '', - 'xcm_profile' => '', - 'location_type_id' => CRM_Twingle_Submission::LOCATION_TYPE_ID_WORK, + 'selector' => NULL, + 'xcm_profile' => '', + 'location_type_id' => CRM_Twingle_Submission::LOCATION_TYPE_ID_WORK, 'location_type_id_organisation' => CRM_Twingle_Submission::LOCATION_TYPE_ID_WORK, // "Donation" 'financial_type_id' => 1, @@ -391,20 +468,19 @@ class CRM_Twingle_Profile { } /** - * Retrieves the profile with the given name. + * Retrieves the profile with the given ID. * - * @param string $name + * @param int|NULL $id * * @return CRM_Twingle_Profile | NULL + * @throws \Civi\Core\Exception\DBQueryException */ - public static function getProfile($name) { - if (!empty($name)) { - $profile_data = CRM_Core_DAO::singleValueQuery( - 'SELECT config FROM civicrm_twingle_profile WHERE name = %1', - [1 => [$name, 'String']] - ); - if ($profile_data) { - return new CRM_Twingle_Profile($name, json_decode($profile_data, 1)); + public static function getProfile(int $id = NULL) { + if (!empty($id)) { + $profile_data = CRM_Core_DAO::executeQuery("SELECT id, name, config FROM civicrm_twingle_profile WHERE id = %1", + [1 => [$id, 'Integer']]); + if ($profile_data->fetch()) { + return new CRM_Twingle_Profile($profile_data->name, json_decode($profile_data->config, 1), (int) $profile_data->id); } } return NULL; @@ -416,16 +492,14 @@ class CRM_Twingle_Profile { * * @return array * profile_name => CRM_Twingle_Profile + * @throws \Civi\Core\Exception\DBQueryException */ public static function getProfiles() { // todo: cache? $profiles = []; - $profile_data = CRM_Core_DAO::executeQuery('SELECT name, config FROM civicrm_twingle_profile'); + $profile_data = CRM_Core_DAO::executeQuery("SELECT id, name, config FROM civicrm_twingle_profile"); while ($profile_data->fetch()) { - $profiles[$profile_data->name] = new CRM_Twingle_Profile( - $profile_data->name, - json_decode($profile_data->config, 1) - ); + $profiles[$profile_data->id] = new CRM_Twingle_Profile($profile_data->name, json_decode($profile_data->config, 1), (int) $profile_data->id); } return $profiles; } diff --git a/templates/CRM/Twingle/Page/Profiles.tpl b/templates/CRM/Twingle/Page/Profiles.tpl index b5b869e..cf3351e 100644 --- a/templates/CRM/Twingle/Page/Profiles.tpl +++ b/templates/CRM/Twingle/Page/Profiles.tpl @@ -33,6 +33,7 @@ {foreach from=$profiles item=profile} + {assign var="profile_id" value=$profile.id} {assign var="profile_name" value=$profile.name} {$profile.name} @@ -42,12 +43,12 @@ {ts domain="de.systopia.twingle"}{$profile_stats.$profile_name.access_counter_txt}{/ts} {ts domain="de.systopia.twingle"}{$profile_stats.$profile_name.last_access_txt}{/ts} - {ts domain="de.systopia.twingle"}Edit{/ts} - {ts domain="de.systopia.twingle"}Copy{/ts} + {ts domain="de.systopia.twingle"}Edit{/ts} + {ts domain="de.systopia.twingle"}Copy{/ts} {if $profile_name == 'default'} - {ts domain="de.systopia.twingle"}Reset{/ts} + {ts domain="de.systopia.twingle"}Reset{/ts} {else} - {ts domain="de.systopia.twingle"}Delete{/ts} + {ts domain="de.systopia.twingle"}Delete{/ts} {/if} From a16be91822c92859386c05a2c7cb1406dd091851 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Wed, 16 Aug 2023 14:26:23 +0200 Subject: [PATCH 02/10] include profile name in update query --- CRM/Twingle/Profile.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index ae62782..2c336f1 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -235,10 +235,11 @@ class CRM_Twingle_Profile { if ($this->id !== NULL) { // existing profile -> just update the config CRM_Core_DAO::executeQuery( - "UPDATE civicrm_twingle_profile SET config = %2 WHERE id = %1", + "UPDATE civicrm_twingle_profile SET config = %2, name = %3 WHERE id = %1", [ 1 => [$this->id, 'String'], 2 => [json_encode($this->data), 'String'], + 3 => [$this->name, 'String'], ]); } else { From 6f6b9e059936a84ef9b2853c275a8d78564e2399 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Wed, 16 Aug 2023 14:32:38 +0200 Subject: [PATCH 03/10] use correct error code --- CRM/Twingle/Profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index 2c336f1..335e95c 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -298,7 +298,7 @@ class CRM_Twingle_Profile { } catch (Exception $e) { throw new ProfileException( E::ts("Could not delete profile: %1", [1 => $e->getMessage()]), - ProfileException::ERROR_CODE_COULD_NOT_RESET_PROFILE + ProfileException::ERROR_CODE_COULD_NOT_DELETE_PROFILE ); } } From c7e51b4d3cb705ab49b7c5f5edbc980c93d4793d Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Wed, 16 Aug 2023 14:45:36 +0200 Subject: [PATCH 04/10] do not attempt to delete unverified profile_id --- CRM/Twingle/Form/Profile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index d7fe333..996f22d 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -160,7 +160,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { switch ($this->_op) { case 'delete': - if ($this->profile_id) { + if ($this->profile) { CRM_Utils_System::setTitle(E::ts('Delete Twingle API profile %1', [1 => $this->profile->getName()])); $this->addButtons([ [ From 09dda832a48004878c2fa659bb3ecc698462a7d5 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Wed, 6 Sep 2023 16:24:03 +0200 Subject: [PATCH 05/10] validate profile when copying --- CRM/Twingle/Form/Profile.php | 30 +++++++++++++++++++++++++----- CRM/Twingle/Profile.php | 8 +++++++- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index 996f22d..5205b52 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -180,12 +180,32 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { if (!$source_id) { $this->profile = CRM_Twingle_Profile::createDefaultProfile(); } else { - $source_profile = CRM_Twingle_Profile::getProfile($source_id); - $this->profile = $source_profile->copy(); + try { + $source_profile = CRM_Twingle_Profile::getProfile($source_id); + $this->profile = $source_profile->copy(); + $this->profile->validate(); + } catch (ProfileValidationError $e) { + if ($e->getErrorCode() == ProfileValidationError::ERROR_CODE_PROFILE_VALIDATION_FAILED) { + Civi::log()->error($e->getLogMessage()); + CRM_Core_Session::setStatus(E::ts('The profile is invalid and cannot be copied.'), E::ts('Error')); + CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/settings/twingle/profiles', 'reset=1')); + return; + } + } catch (ProfileException $e) { + if ($e->getErrorCode() == ProfileException::ERROR_CODE_PROFILE_NOT_FOUND) { + Civi::log()->error($e->getLogMessage()); + CRM_Core_Session::setStatus(E::ts('The profile to be copied could not be found.'), E::ts('Error')); + CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/settings/twingle/profiles', 'reset=1')); + return; + } + } + catch (Civi\Core\Exception\DBQueryException $e) { + Civi::log()->error($e->getMessage()); + CRM_Core_Session::setStatus(E::ts('A database error has occurred. See the log for details.'), E::ts('Error')); + CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/settings/twingle/profiles', 'reset=1')); + return; + } } - // Propose a new name for this profile. - $profile_name = $this->profile->getName() . '_copy'; - $this->profile->setName($profile_name); CRM_Utils_System::setTitle(E::ts('New Twingle API profile')); break; diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index 335e95c..5d9f53a 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -80,8 +80,14 @@ class CRM_Twingle_Profile { */ public function copy() { $copy = clone $this; + + // Remove unique data $copy->id = NULL; $copy->data['selector'] = NULL; + + // Propose a new name for this profile. + $profile_name = $this->getName() . '_copy'; + $copy->setName($profile_name); return $copy; } @@ -484,7 +490,7 @@ class CRM_Twingle_Profile { return new CRM_Twingle_Profile($profile_data->name, json_decode($profile_data->config, 1), (int) $profile_data->id); } } - return NULL; + throw new ProfileException('Profile not found.', ProfileException::ERROR_CODE_PROFILE_NOT_FOUND); } /** From 4feeb01611309c8385bdf08abe086354e726f885 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Wed, 6 Sep 2023 16:29:55 +0200 Subject: [PATCH 06/10] make sure that default values are present --- CRM/Twingle/Form/Profile.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index 5205b52..199e421 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -640,6 +640,9 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { public function setDefaultValues() { $defaults = parent::setDefaultValues(); if (in_array($this->_op, ['create', 'edit', 'copy'])) { + if (!$this->profile) { + $this->profile = CRM_Twingle_Profile::createDefaultProfile()->copy(); + } $defaults['name'] = $this->profile->getName(); $profile_data = $this->profile->getData(); foreach ($profile_data as $element_name => $value) { From aef1ae739653a2eb6d58729d7090af7528fe30ff Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Wed, 6 Sep 2023 16:34:56 +0200 Subject: [PATCH 07/10] refactoring --- CRM/Twingle/Profile.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index 5d9f53a..d5109a7 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -221,7 +221,8 @@ class CRM_Twingle_Profile { * Verifies whether the profile is valid (i.e. consistent and not colliding * with other profiles). * - * @throws Exception + * @throws \CRM\Twingle\Exceptions\ProfileValidationError + * @throws \Civi\Core\Exception\DBQueryException * When the profile could not be successfully validated. */ public function verifyProfile() { @@ -231,7 +232,9 @@ class CRM_Twingle_Profile { } /** - * Persists the profile within the CiviCRM settings. + * Persists the profile within the database. + * + * @throws \CRM\Twingle\Exceptions\ProfileException */ public function saveProfile() { // make sure it's valid @@ -269,7 +272,7 @@ class CRM_Twingle_Profile { /** * Deletes the profile from the database * - * @throws \CRM_Twingle_Exceptions_ProfileException + * @throws \CRM\Twingle\Exceptions\ProfileException */ public function deleteProfile() { // Do only reset default profile @@ -481,6 +484,7 @@ class CRM_Twingle_Profile { * * @return CRM_Twingle_Profile | NULL * @throws \Civi\Core\Exception\DBQueryException + * @throws \CRM\Twingle\Exceptions\ProfileException */ public static function getProfile(int $id = NULL) { if (!empty($id)) { From f81b476a3054707dd67a111d47eb7b6264e0a3af Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Thu, 5 Oct 2023 14:32:29 +0200 Subject: [PATCH 08/10] fix exception on profile creation --- CRM/Twingle/Form/Profile.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index 199e421..430d335 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -149,8 +149,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { } // Verify that a profile with the given id exists. - - if ($this->_op != 'copy') { + if ($this->_op != 'copy' && $this->_op != 'create') { $this->profile_id = CRM_Utils_Request::retrieve('id', 'Int', $this); $this->profile = CRM_Twingle_Profile::getProfile($this->profile_id); } From 5efed1f6c8d91e3bbea1c6233b91879efa86b10c Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Mon, 25 Mar 2024 16:03:07 +0100 Subject: [PATCH 09/10] Fix @throws tags with wrong class name --- CRM/Twingle/Profile.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index d5109a7..8d9a269 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -221,7 +221,7 @@ class CRM_Twingle_Profile { * Verifies whether the profile is valid (i.e. consistent and not colliding * with other profiles). * - * @throws \CRM\Twingle\Exceptions\ProfileValidationError + * @throws \Civi\Twingle\Exceptions\ProfileValidationError * @throws \Civi\Core\Exception\DBQueryException * When the profile could not be successfully validated. */ @@ -234,7 +234,7 @@ class CRM_Twingle_Profile { /** * Persists the profile within the database. * - * @throws \CRM\Twingle\Exceptions\ProfileException + * @throws \Civi\Twingle\Exceptions\ProfileException */ public function saveProfile() { // make sure it's valid @@ -272,7 +272,7 @@ class CRM_Twingle_Profile { /** * Deletes the profile from the database * - * @throws \CRM\Twingle\Exceptions\ProfileException + * @throws \Civi\Twingle\Exceptions\ProfileException */ public function deleteProfile() { // Do only reset default profile @@ -484,7 +484,7 @@ class CRM_Twingle_Profile { * * @return CRM_Twingle_Profile | NULL * @throws \Civi\Core\Exception\DBQueryException - * @throws \CRM\Twingle\Exceptions\ProfileException + * @throws \Civi\Twingle\Exceptions\ProfileException */ public static function getProfile(int $id = NULL) { if (!empty($id)) { From fc40af8db53d9559206b36c2386750430c88552c Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Thu, 4 Apr 2024 12:13:53 +0200 Subject: [PATCH 10/10] Fix code style --- CRM/Twingle/Form/Settings.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CRM/Twingle/Form/Settings.php b/CRM/Twingle/Form/Settings.php index 6303dc9..0ff7454 100644 --- a/CRM/Twingle/Form/Settings.php +++ b/CRM/Twingle/Form/Settings.php @@ -25,7 +25,8 @@ use CRM_Twingle_ExtensionUtil as E; class CRM_Twingle_Form_Settings extends CRM_Core_Form { /** - * @var arraylistofallsettingsoptions + * @var array + * List of all settings options. */ public static $SETTINGS_LIST = [ 'twingle_prefix', @@ -133,7 +134,8 @@ class CRM_Twingle_Form_Settings extends CRM_Core_Form { // if activity creation is active, make sure the fields are set $protection_mode = CRM_Utils_Array::value('twingle_protect_recurring', $this->_submitValues); if ($protection_mode == CRM_Twingle_Config::RCUR_PROTECTION_ACTIVITY) { - foreach (['twingle_protect_recurring_activity_type', + foreach ([ + 'twingle_protect_recurring_activity_type', 'twingle_protect_recurring_activity_subject', 'twingle_protect_recurring_activity_status', 'twingle_protect_recurring_activity_assignee',