From 482b8e2d0d1ff4d3c51ae302609da47d2ffc0256 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Fri, 17 Dec 2021 09:05:51 +0100 Subject: [PATCH 01/30] =?UTF-8?q?=F0=9F=90=9B=20Fix=20bug=20#5:=20Error=20?= =?UTF-8?q?when=20altering=20any=20case=20type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CRM/TwingleCampaign/BAO/CustomField.php | 31 ++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/CRM/TwingleCampaign/BAO/CustomField.php b/CRM/TwingleCampaign/BAO/CustomField.php index 04324f3..a0a9b81 100644 --- a/CRM/TwingleCampaign/BAO/CustomField.php +++ b/CRM/TwingleCampaign/BAO/CustomField.php @@ -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(); From 3e73ed733bb6a753005e368c9fe238e749772982 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Fri, 17 Dec 2021 12:13:13 +0100 Subject: [PATCH 02/30] =?UTF-8?q?=E2=9C=A8=20improve=20hex=20color=20valid?= =?UTF-8?q?ation=20#4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CRM/TwingleCampaign/BAO/TwingleProject.php | 34 +++++++++++++--------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/CRM/TwingleCampaign/BAO/TwingleProject.php b/CRM/TwingleCampaign/BAO/TwingleProject.php index 8f509c0..fc3f779 100644 --- a/CRM/TwingleCampaign/BAO/TwingleProject.php +++ b/CRM/TwingleCampaign/BAO/TwingleProject.php @@ -31,6 +31,13 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign { 'one_time', ]; + // All fields for hex color codes + const colorFields = [ + 'design_background_color', + 'design_primary_color', + 'design_font_color', + ]; + /** * ## TwingleProject constructor * @@ -143,11 +150,13 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign { */ private function strToInt(array &$values) { foreach ($values as $key => $value) { - if (ctype_digit($value)) { - $values[$key] = intval($value); - } - elseif (is_array($value)) { - $this->strToInt($values[$key]); + if (!in_array($key, self::colorFields)) { + if (ctype_digit($value)) { + $values[$key] = intval($value); + } + elseif (is_array($value)) { + $this->strToInt($values[$key]); + } } } } @@ -298,21 +307,18 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign { } // Validate hexadecimal color fields - $colorFields = - [ - 'design_background_color', - 'design_primary_color', - 'design_font_color', - ]; - foreach ($colorFields as $colorField) { + foreach (self::colorFields as $colorField) { if ( - !empty($this->values['project_options'][$colorField]) && + ( + !empty($this->values['project_options'][$colorField]) || + $this->values['project_options'][$colorField] === "0" + ) && ( !( ctype_xdigit($this->values['project_options'][$colorField]) || is_integer($this->values['project_options'][$colorField]) ) || - strlen((string) $this->values['project_options'][$colorField]) > 6 + strlen((string) $this->values['project_options'][$colorField]) != 6 ) ) { $valid = FALSE; From fbe30b0ce582f8e9e49a56e6c5804e0be2cdf917 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Fri, 17 Dec 2021 12:19:46 +0100 Subject: [PATCH 03/30] =?UTF-8?q?=F0=9F=97=91=EF=B8=8F=20get=20rid=20of=20?= =?UTF-8?q?the=20warning=20about=20using=20an=20deprecated=20constant?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- twinglecampaign.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/twinglecampaign.php b/twinglecampaign.php index bda4f1d..04ff8ca 100644 --- a/twinglecampaign.php +++ b/twinglecampaign.php @@ -411,8 +411,7 @@ function _validateAndSendInput($id, $campaign_type_id): bool { CRM_Core_Session::setStatus( $errorMessage, E::ts("Input validation failed"), - error, - [unique => TRUE] + error ); // Validation failed return FALSE; From 0ab5bb1fa93d50081ad127697367990418b43d82 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Fri, 17 Dec 2021 12:23:38 +0100 Subject: [PATCH 04/30] =?UTF-8?q?=F0=9F=A9=B9=20call=20the=20right=20API?= =?UTF-8?q?=20to=20fetch=20OptionValues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CRM/TwingleCampaign/BAO/OptionValue.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/TwingleCampaign/BAO/OptionValue.php b/CRM/TwingleCampaign/BAO/OptionValue.php index 9de6594..1d808aa 100644 --- a/CRM/TwingleCampaign/BAO/OptionValue.php +++ b/CRM/TwingleCampaign/BAO/OptionValue.php @@ -158,7 +158,7 @@ class CRM_TwingleCampaign_BAO_OptionValue { // If a specific option value is required try { $option_value = civicrm_api3( - 'CustomValue', + 'OptionValue', 'get', [ 'sequential' => 1, From 2abf1676bd64522fa4beadabc5d238f4fd54caa2 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Fri, 17 Dec 2021 12:28:15 +0100 Subject: [PATCH 05/30] =?UTF-8?q?=F0=9F=94=96=201.0.1=20stable=20release?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changes: - ✨ #4 improve hex color validation - 🐛 #5 fix bug: error when altering any case type - 🗑️ get rid of the warning about using an deprecated constant - 🩹 call the right API to fetch OptionValues --- info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.xml b/info.xml index 24956c7..e31f067 100644 --- a/info.xml +++ b/info.xml @@ -15,7 +15,7 @@ http://www.gnu.org/licenses/agpl-3.0.html 2021-12-15 - 1.0 + 1.0.1 stable 5.14.0 From cb4c11feee636a85f3f8c1bd6761b3e49f68543d Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Thu, 20 Jan 2022 16:52:11 +0100 Subject: [PATCH 06/30] =?UTF-8?q?=F0=9F=90=9B=20bug=20fix:=20color=20field?= =?UTF-8?q?s=20were=20converted=20from=20hex=20to=20dec=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added this two color fields to $colorFields: - design_button_font_color - design_button_font_color_light --- CRM/TwingleCampaign/BAO/TwingleProject.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CRM/TwingleCampaign/BAO/TwingleProject.php b/CRM/TwingleCampaign/BAO/TwingleProject.php index fc3f779..2e2cd1d 100644 --- a/CRM/TwingleCampaign/BAO/TwingleProject.php +++ b/CRM/TwingleCampaign/BAO/TwingleProject.php @@ -36,6 +36,8 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign { 'design_background_color', 'design_primary_color', 'design_font_color', + 'design_button_font_color', + 'design_button_font_color_light', ]; /** From 6a50ea2c166d020f432c9a584a5fc38812704c66 Mon Sep 17 00:00:00 2001 From: Daniel Scholten Date: Thu, 21 Jul 2022 10:42:37 +0200 Subject: [PATCH 07/30] Documentation to enable scheduled job in nonproductive sites --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 60025fa..59ba268 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,8 @@ decrease this interval by changing the configuration of the scheduled job named Furthermore, the synchronization may get triggered also if a donation for an unknown event arrives via the Twingle API extension. +A CiviCRM site running [not in productive mode](https://docs.civicrm.org/sysadmin/en/latest/misc/staging-production/) will by default not run any scheduled jobs. In that case you can individually enable the TwingleSync job by adding the parameter runInNonProductionEnvironment=TRUE to the job. + ## Known Issues - The **Campaign Manager** displays a *«Campaign XY has been saved»* message even if the input validation failed and the @@ -81,4 +83,4 @@ extension. - [ ] Make the Twingle Event Settings for contact matching, case creation and creation of soft credits an individual setting in each project -- [ ] Make more payment methods available \ No newline at end of file +- [ ] Make more payment methods available From 975b77eaf25997b88eef3652f6f6b4776f42ca9b Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Mon, 21 Nov 2022 16:12:04 +0100 Subject: [PATCH 08/30] =?UTF-8?q?=F0=9F=94=A7=20do=20not=20only=20fetch=20?= =?UTF-8?q?active=20campaigns=20from=20campaign.get?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v3/TwingleProject/Sync.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/api/v3/TwingleProject/Sync.php b/api/v3/TwingleProject/Sync.php index 26a46be..aed3d2a 100644 --- a/api/v3/TwingleProject/Sync.php +++ b/api/v3/TwingleProject/Sync.php @@ -176,8 +176,7 @@ function civicrm_api3_twingle_project_Sync(array $params): array { $projects_from_twingle = $twingleApi->getProject(); // Get all TwingleProjects from CiviCRM - $projects_from_civicrm = civicrm_api3('TwingleProject', 'get', - ['is_active' => 1,]); + $projects_from_civicrm = civicrm_api3('TwingleProject', 'get'); // If call to TwingleProject.get failed, forward error message if ($projects_from_civicrm['is_error'] != 0) { From 6476a163fcd42e059b7fbddd84351c6ec66baf17 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Mon, 21 Nov 2022 16:52:38 +0100 Subject: [PATCH 09/30] =?UTF-8?q?=F0=9F=94=96=20bump=20version=20to=201.0.?= =?UTF-8?q?2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.xml b/info.xml index e31f067..b3b1950 100644 --- a/info.xml +++ b/info.xml @@ -15,7 +15,7 @@ http://www.gnu.org/licenses/agpl-3.0.html 2021-12-15 - 1.0.1 + 1.0.2 stable 5.14.0 From 51b19ac68d56dd64c4db7a203e2bfce6991e885e Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Tue, 28 Feb 2023 15:14:31 +0100 Subject: [PATCH 10/30] =?UTF-8?q?=F0=9F=90=9B=20fix=20bug:=20cannot=20sear?= =?UTF-8?q?ch=20for=20TwingleForm=20by=20twingle=5Fproject=5Fid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/v3/TwingleForm/Get.php | 14 ++++++++++++++ api/v3/TwingleForm/Getsingle.php | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/api/v3/TwingleForm/Get.php b/api/v3/TwingleForm/Get.php index 3e2f867..6adaf2e 100644 --- a/api/v3/TwingleForm/Get.php +++ b/api/v3/TwingleForm/Get.php @@ -14,6 +14,13 @@ use CRM_TwingleCampaign_Utils_ExtensionCache as Cache; function _civicrm_api3_twingle_form_Get_spec(array &$spec) { $spec['id'] = [ 'name' => 'id', + 'title' => E::ts('Campaign ID'), + 'type' => CRM_Utils_Type::T_INT, + 'api.required' => 0, + 'description' => E::ts('The campaign ID'), + ]; + $spec['twingle_project_id'] = [ + 'name' => 'twingle_project_id', 'title' => E::ts('TwingleProject ID'), 'type' => CRM_Utils_Type::T_INT, 'api.required' => 0, @@ -66,6 +73,13 @@ function civicrm_api3_twingle_form_Get(array $params): array { // Get custom fields $custom_field_mapping = Cache::getInstance()->getCustomFieldMapping(); + // Replace twingle_project_id key with custom field name + if (key_exists('twingle_project_id', $params)) { + $params[$custom_field_mapping['twingle_project_id']] = + $params['twingle_project_id']; + unset($params['twingle_project_id']); + } + // Replace twingle_project_type key with custom field name if (key_exists('twingle_project_type', $params)) { $params[$custom_field_mapping['twingle_project_type']] = diff --git a/api/v3/TwingleForm/Getsingle.php b/api/v3/TwingleForm/Getsingle.php index e763683..09e18d5 100644 --- a/api/v3/TwingleForm/Getsingle.php +++ b/api/v3/TwingleForm/Getsingle.php @@ -12,6 +12,13 @@ use CRM_TwingleCampaign_ExtensionUtil as E; function _civicrm_api3_twingle_form_Getsingle_spec(array &$spec) { $spec['id'] = [ 'name' => 'id', + 'title' => E::ts('Campaign ID'), + 'type' => CRM_Utils_Type::T_INT, + 'api.required' => 0, + 'description' => E::ts('The campaign ID'), + ]; + $spec['twingle_project_id'] = [ + 'name' => 'twingle_project_id', 'title' => E::ts('TwingleProject ID'), 'type' => CRM_Utils_Type::T_INT, 'api.required' => 0, From a4cda1427b920e14ebd4e236fcd60f01a616801c Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Tue, 28 Feb 2023 15:22:33 +0100 Subject: [PATCH 11/30] =?UTF-8?q?=F0=9F=94=96=20bump=20version=20to=201.0.?= =?UTF-8?q?3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 🐛 fix bug: cannot search for TwingleForm by twingle_project_id - Documentation to enable scheduled job in nonproductive sites by @RoWo-DS --- info.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/info.xml b/info.xml index b3b1950..b7ae3af 100644 --- a/info.xml +++ b/info.xml @@ -14,8 +14,8 @@ https://lab.civicrm.org/Marc_Michalsky/de-forumzfd-twinglecampaign/-/issues http://www.gnu.org/licenses/agpl-3.0.html - 2021-12-15 - 1.0.2 + 2023-02-28 + 1.0.3 stable 5.14.0 From bfa3ae7e32859e273bc763e60c5069bb316a9c7f Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Mon, 14 Aug 2023 16:11:30 +0200 Subject: [PATCH 12/30] fix wrong return type --- CRM/TwingleCampaign/BAO/TwingleProject.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/CRM/TwingleCampaign/BAO/TwingleProject.php b/CRM/TwingleCampaign/BAO/TwingleProject.php index 2e2cd1d..d63dd42 100644 --- a/CRM/TwingleCampaign/BAO/TwingleProject.php +++ b/CRM/TwingleCampaign/BAO/TwingleProject.php @@ -181,15 +181,8 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign { return FALSE; } - $result = parent::create($no_hook); + return parent::create($no_hook); - // Check if campaign was created successfully - if ($result['is_error'] == 0) { - return TRUE; - } - else { - throw new Exception($result['error_message']); - } } /** From 54adee32a937f0b6ce666bdebcd8dddd147eb2a5 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Mon, 14 Aug 2023 16:12:56 +0200 Subject: [PATCH 13/30] Add new project types 'shop' and 'giftshop' --- CRM/TwingleCampaign/resources/campaigns.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CRM/TwingleCampaign/resources/campaigns.php b/CRM/TwingleCampaign/resources/campaigns.php index ffd097c..9c59709 100644 --- a/CRM/TwingleCampaign/resources/campaigns.php +++ b/CRM/TwingleCampaign/resources/campaigns.php @@ -113,7 +113,9 @@ return [ "option_values" => [ "default" => E::ts("Default"), "event" => E::ts("Events"), - "membership" => E::ts("Membership") + "membership" => E::ts("Membership"), + "shop" => E::ts("Shop"), + "giftshop" => E::ts("Gift Shop") ], "text_length" => 32, "is_active" => 1, From 2949ab0168cdd50ccfb0e1036b9e2e014448a098 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Mon, 14 Aug 2023 16:15:05 +0200 Subject: [PATCH 14/30] create new option values when custom field is changed --- CRM/TwingleCampaign/BAO/CustomField.php | 117 +++++++++++++----------- 1 file changed, 62 insertions(+), 55 deletions(-) diff --git a/CRM/TwingleCampaign/BAO/CustomField.php b/CRM/TwingleCampaign/BAO/CustomField.php index a0a9b81..9666d30 100644 --- a/CRM/TwingleCampaign/BAO/CustomField.php +++ b/CRM/TwingleCampaign/BAO/CustomField.php @@ -62,10 +62,11 @@ class CRM_TwingleCampaign_BAO_CustomField { * @param bool $upgrade * If true: Does not show UF message if custom field already exists * - * @returns array Result of custom field creation api call + * @returns array|False Result of custom field creation api call. False if + * field already existed und wasn't upgraded. * @throws \CiviCRM_API3_Exception */ - public function create(bool $upgrade = FALSE): ?array { + public function create(bool $upgrade = FALSE) { // Check if the field already exists $field = civicrm_api3( @@ -129,52 +130,74 @@ class CRM_TwingleCampaign_BAO_CustomField { return NULL; } else { - return NULL; + $this->id = $field['values'][0]['id']; + $this->custom_group_id = $field['values'][0]['custom_group_id']; + return $this->upgrade($field['values'][0]); } } /** - * Update an existing custom field + * Upgrade an existing custom field * - * @returns array Result of custom field creation api call + * @param $attributes + * Custom Field data + * @returns array|False Result of custom field creation api call, False if + * field was not upgraded */ - public function update(): array { + private function upgrade($attributes) { + $upgrade_necessary = False; - try { - $this->result = civicrm_api3( - 'CustomField', - 'create', - $this->getSetAttributes()); + if (key_exists('option_group_id', $attributes)) { + $this->addOptions($attributes); + } - // Log field creation - if ($this->result['is_error'] == 0) { - Civi::log()->info("$this->extensionName has updated a custom field. + foreach ($this as $var => $value) { + // put array items into attributes + if (array_key_exists($var, $attributes) && $attributes[$var] != $value) { + $this->$var = $attributes[$var]; + $upgrade_necessary = True; + } + } + + if ($upgrade_necessary) { + try { + $this->result = civicrm_api3( + 'CustomField', + 'create', + $this->getSetAttributes()); + + // Log field creation + if ($this->result['is_error'] == 0) { + Civi::log()->info("$this->extensionName has updated a custom field. label: $this->label name: $this->name id: $this->id group: $this->custom_group_id" - ); + ); + return $this->result; + } + else { + throw new CiviCRM_API3_Exception($this->result['error_message']); + } + } + catch (CiviCRM_API3_Exception $e) { + // If the field could not get created: log error + $errorMessage = $e->getMessage(); + if ($this->name && $this->custom_group_id) { + Civi::log() + ->error("$this->extensionName could not create new custom field \"$this->name\" for group \"$this->custom_group_id\": $errorMessage"); + CRM_Utils_System::setUFMessage(E::ts('Creation of custom field \'%1\' failed. Find more information in the logs.', [1 => $this->name])); + } + // If there is not enough information: log simple error message + else { + Civi::log() + ->error("$this->extensionName could not create new custom field: $errorMessage"); + CRM_Utils_System::setUFMessage(E::ts("Creation of custom field failed. Find more information in the logs.")); + } return $this->result; } - else { - throw new CiviCRM_API3_Exception($this->result['error_message']); - } - } catch (CiviCRM_API3_Exception $e) { - // If the field could not get created: log error - $errorMessage = $e->getMessage(); - if ($this->name && $this->custom_group_id) { - Civi::log() - ->error("$this->extensionName could not create new custom field \"$this->name\" for group \"$this->custom_group_id\": $errorMessage"); - CRM_Utils_System::setUFMessage(E::ts('Creation of custom field \'%1\' failed. Find more information in the logs.', [1 => $this->name])); - } - // If there is not enough information: log simple error message - else { - Civi::log() - ->error("$this->extensionName could not create new custom field: $errorMessage"); - CRM_Utils_System::setUFMessage(E::ts("Creation of custom field failed. Find more information in the logs.")); - } - return $this->result; } + return False; } /** @@ -188,30 +211,14 @@ class CRM_TwingleCampaign_BAO_CustomField { $result = []; try { - $option_group_id = civicrm_api3( - 'CustomField', - 'getsingle', - ['id' => $this->id] - )['option_group_id']; - } catch (CiviCRM_API3_Exception $e) { - $errorMessage = $e->getMessage(); - Civi::log() - ->error("$this->extensionName could not get get option group id for custom field \"$this->name\": $errorMessage"); - CRM_Utils_System::setUFMessage( - E::ts('%1 could not get option group id for custom field \'%2\'. Find more information in the logs.', - [1 => $this->extensionName, 2 => $this->name]) - ); - } - - try { - foreach ($options as $key => $value) { + foreach ($this->option_values as $key => $value) { $option_value_exists = civicrm_api3( 'OptionValue', 'get', [ 'sequential' => 1, - 'option_group_id' => $option_group_id, + 'option_group_id' => $options['option_group_id'], 'value' => $key, ] ); @@ -222,7 +229,7 @@ class CRM_TwingleCampaign_BAO_CustomField { 'OptionValue', 'create', [ - 'option_group_id' => $option_group_id, + 'option_group_id' => $options['option_group_id'], 'value' => $key, 'label' => $value, ] @@ -347,12 +354,12 @@ class CRM_TwingleCampaign_BAO_CustomField { if ($this->label && $this->custom_group_id) { Civi::log() ->error("$this->extensionName could not delete custom field - \"$this->label\" for group \"$this->custom_group_id\": + \"$this->label\" for group \"$this->custom_group_id\": $this->result['error_message']"); } else { Civi::log() - ->error("$this->extensionName could not delete custom field: + ->error("$this->extensionName could not delete custom field: $this->result['error_message']"); } } @@ -496,4 +503,4 @@ class CRM_TwingleCampaign_BAO_CustomField { $this->option_values = $option_values; } -} \ No newline at end of file +} From 82b4632d63aa6a502888d32e92508d63a21588b5 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Mon, 14 Aug 2023 16:16:50 +0200 Subject: [PATCH 15/30] implement matomo integration --- CRM/TwingleCampaign/BAO/Configuration.php | 11 ++- CRM/TwingleCampaign/Form/Settings.php | 7 ++ CRM/TwingleCampaign/Utils/MatomoSnippet.php | 75 +++++++++++++++++++ api/v3/TwingleForm/Get.php | 42 ++++++++++- .../CRM/TwingleCampaign/Form/Settings.tpl | 5 ++ 5 files changed, 134 insertions(+), 6 deletions(-) create mode 100644 CRM/TwingleCampaign/Utils/MatomoSnippet.php diff --git a/CRM/TwingleCampaign/BAO/Configuration.php b/CRM/TwingleCampaign/BAO/Configuration.php index 6d2614e..4d26232 100644 --- a/CRM/TwingleCampaign/BAO/Configuration.php +++ b/CRM/TwingleCampaign/BAO/Configuration.php @@ -7,7 +7,8 @@ class CRM_TwingleCampaign_BAO_Configuration { 'twingle_api_key', 'twinglecampaign_xcm_profile', 'twinglecampaign_default_case', - 'twinglecampaign_soft_credits' + 'twinglecampaign_soft_credits', + 'twinglecampaign_matomo_integration' ]; @@ -27,6 +28,12 @@ class CRM_TwingleCampaign_BAO_Configuration { Civi::settings()->set('twinglecampaign_soft_credits', 0); } + // Set twinglecampaign_matomo_integration to '0' if checkbox is unchecked + if (!array_key_exists('twinglecampaign_matomo_integration', $settings)) { + Civi::settings()->set('twinglecampaign_matomo_integration', 0); + } + + Civi::settings()->add($settings); } @@ -63,4 +70,4 @@ class CRM_TwingleCampaign_BAO_Configuration { } } -} \ No newline at end of file +} diff --git a/CRM/TwingleCampaign/Form/Settings.php b/CRM/TwingleCampaign/Form/Settings.php index f614ce5..5b599e0 100644 --- a/CRM/TwingleCampaign/Form/Settings.php +++ b/CRM/TwingleCampaign/Form/Settings.php @@ -46,6 +46,13 @@ class CRM_TwingleCampaign_Form_Settings extends CRM_Core_Form { FALSE ); + $this->addElement( + 'checkbox', + 'twinglecampaign_matomo_integration', + E::ts('Use Matomo to track user interaction with Twingle forms'), + FALSE + ); + $this->addButtons([ [ 'type' => 'submit', diff --git a/CRM/TwingleCampaign/Utils/MatomoSnippet.php b/CRM/TwingleCampaign/Utils/MatomoSnippet.php new file mode 100644 index 0000000..79fd3ec --- /dev/null +++ b/CRM/TwingleCampaign/Utils/MatomoSnippet.php @@ -0,0 +1,75 @@ +", + "", + "", + ]); + } + + /** + * Returns JavaScript snippet to track events in Matomo. + * + * @return string + */ + public static function get_event_tracker() { + $code = "_paq.push(['trackEvent', 'twingle', 'donation', event.data.value.recurringRythm, event.data.value.amount]);"; + return self::embed_in_base_function($code); + } + + /** + * Returns JavaScript snippet to track Matomo goals. + * + * @param $goal_id + * The ID of your Matomo goal. + * + * @return string + */ + public static function get_goal_tracker($goal_id) { + $code = "_paq.push(['trackGoal', $goal_id]);"; + return self::embed_in_base_function($code); + } + + /** + * Returns JavaScript snippet to track ecommerce activity in Matomo. + * + * @return string + */ + public static function get_ecommerce_tracker() { + $code = implode("\n", [ + "_paq.push(['addEcommerceItem', event.data.value.rythm, '', event.data.value.target, event.data.value.amount]);", + "_paq.push(['trackEcommerceOrder', 'anonymizedData', event.data.value.amount]);", + ]); + return self::embed_in_base_function($code); + } + + /** + * Appends the given code to the original code. + * + * @param $original + * The original code. + * @param $appendix + * The code you want to append to the original code. + * + * @return string + * The combined code after appending the appendix. + */ + public static function append_code($original, $appendix) { + return $original . '\n' . $appendix; + } + +} diff --git a/api/v3/TwingleForm/Get.php b/api/v3/TwingleForm/Get.php index 6adaf2e..86a5475 100644 --- a/api/v3/TwingleForm/Get.php +++ b/api/v3/TwingleForm/Get.php @@ -2,6 +2,7 @@ use CRM_TwingleCampaign_ExtensionUtil as E; use CRM_TwingleCampaign_Utils_ExtensionCache as Cache; +use CRM_TwingleCampaign_Utils_MatomoSnippet as MatomoSnippet; /** * TwingleForm.Get API specification (optional) @@ -110,16 +111,49 @@ function civicrm_api3_twingle_form_Get(array $params): array { 'project_type' => $value[$custom_field_mapping['twingle_project_type']], 'counter' => $value[$custom_field_mapping['twingle_project_counter']] ]; + $matomo_integration_enabled = Civi::settings()->get('twinglecampaign_matomo_integration', False); switch ($value[$custom_field_mapping['twingle_project_type']]) { case 'event': - $returnValues[$value['id']]['embed_code'] = - $value[$custom_field_mapping['twingle_project_eventall']]; + if ($matomo_integration_enabled) { + $returnValues[$value['id']]['embed_code'] = + MatomoSnippet::append_code( + $value[$custom_field_mapping['twingle_project_eventall']], + MatomoSnippet::get_event_tracker() + ); + } + else { + $returnValues[$value['id']]['embed_code'] = + $value[$custom_field_mapping['twingle_project_eventall']]; + } + break; + case 'shop': + if ($matomo_integration_enabled) { + $returnValues[$value['id']]['embed_code'] = + MatomoSnippet::append_code( + $value[$custom_field_mapping['twingle_project_widget']], + MatomoSnippet::get_ecommerce_tracker() + ); + } + else { + $returnValues[$value['id']]['embed_code'] = + $value[$custom_field_mapping['twingle_project_widget']]; + } break; default: - $returnValues[$value['id']]['embed_code'] = - $value[$custom_field_mapping['twingle_project_widget']]; + if ($matomo_integration_enabled) { + $returnValues[$value['id']]['embed_code'] = + MatomoSnippet::append_code( + $value[$custom_field_mapping['twingle_project_widget']], + MatomoSnippet::get_event_tracker() + ); + } + else { + $returnValues[$value['id']]['embed_code'] = + $value[$custom_field_mapping['twingle_project_widget']]; + } } } + return civicrm_api3_create_success($returnValues, $query, 'TwingleForm', 'Get'); } else { diff --git a/templates/CRM/TwingleCampaign/Form/Settings.tpl b/templates/CRM/TwingleCampaign/Form/Settings.tpl index a7c7c14..288c13e 100644 --- a/templates/CRM/TwingleCampaign/Form/Settings.tpl +++ b/templates/CRM/TwingleCampaign/Form/Settings.tpl @@ -26,6 +26,11 @@
{$form.twinglecampaign_soft_credits.html}
+
+
{$form.twinglecampaign_matomo_integration.label}
+
{$form.twinglecampaign_matomo_integration.html}
+
+
From de19c3991cfc2aba35ccd98f9dede4fa8796b3d6 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Mon, 14 Aug 2023 16:18:56 +0200 Subject: [PATCH 16/30] =?UTF-8?q?=F0=9F=94=96=20bump=20version=20to=201.0.?= =?UTF-8?q?4-dev?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CRM/TwingleCampaign/Upgrader.php | 81 +------------------------------- info.xml | 4 +- 2 files changed, 3 insertions(+), 82 deletions(-) diff --git a/CRM/TwingleCampaign/Upgrader.php b/CRM/TwingleCampaign/Upgrader.php index 5c1a706..09e7401 100644 --- a/CRM/TwingleCampaign/Upgrader.php +++ b/CRM/TwingleCampaign/Upgrader.php @@ -20,7 +20,7 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base { * changed campaigns will get pulled from Twingle. * @throws \CiviCRM_API3_Exception */ - public function upgrade_02(): bool { + public function upgrade_03(): bool { $campaign_info = require E::path() . '/CRM/TwingleCampaign/resources/campaigns.php'; @@ -294,83 +294,4 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base { Civi::settings()->revert('twingle_api_key'); } - - /** - * Example: Run a couple simple queries. - * - * @return TRUE on success - * @throws Exception - * - * public function upgrade_4200() { - * $this->ctx->log->info('Applying update 4200'); - * CRM_Core_DAO::executeQuery('UPDATE foo SET bar = "whiz"'); - * CRM_Core_DAO::executeQuery('DELETE FROM bang WHERE willy = wonka(2)'); - * return TRUE; - * } // */ - - - /** - * Example: Run an external SQL script. - * - * @return TRUE on success - * @throws Exception - * public function upgrade_4201() { - * $this->ctx->log->info('Applying update 4201'); - * // this path is relative to the extension base dir - * $this->executeSqlFile('sql/upgrade_4201.sql'); - * return TRUE; - * } // */ - - - /** - * Example: Run a slow upgrade process by breaking it up into smaller chunk. - * - * @return TRUE on success - * @throws Exception - * public function upgrade_4202() { - * $this->ctx->log->info('Planning update 4202'); // PEAR Log interface - * - * $this->addTask(E::ts('Process first step'), 'processPart1', $arg1, $arg2); - * $this->addTask(E::ts('Process second step'), 'processPart2', $arg3, $arg4); - * $this->addTask(E::ts('Process second step'), 'processPart3', $arg5); - * return TRUE; - * } - * public function processPart1($arg1, $arg2) { sleep(10); return TRUE; } - * public function processPart2($arg3, $arg4) { sleep(10); return TRUE; } - * public function processPart3($arg5) { sleep(10); return TRUE; } - * // */ - - - /** - * Example: Run an upgrade with a query that touches many (potentially - * millions) of records by breaking it up into smaller chunks. - * - * @return TRUE on success - * @throws Exception - * public function upgrade_4203() { - * $this->ctx->log->info('Planning update 4203'); // PEAR Log interface - * - * $minId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(min(id),0) FROM - * civicrm_contribution'); - * $maxId = CRM_Core_DAO::singleValueQuery('SELECT coalesce(max(id),0) FROM - * civicrm_contribution'); for ($startId = $minId; $startId <= $maxId; - * $startId += self::BATCH_SIZE) { - * $endId = $startId + self::BATCH_SIZE - 1; - * $title = E::ts('Upgrade Batch (%1 => %2)', array( - * 1 => $startId, - * 2 => $endId, - * )); - * $sql = ' - * UPDATE civicrm_contribution SET foobar = whiz(wonky()+wanker) - * WHERE id BETWEEN %1 and %2 - * '; - * $params = array( - * 1 => array($startId, 'Integer'), - * 2 => array($endId, 'Integer'), - * ); - * $this->addTask($title, 'executeSql', $sql, $params); - * } - * return TRUE; - * } // */ - } diff --git a/info.xml b/info.xml index b7ae3af..415f6ed 100644 --- a/info.xml +++ b/info.xml @@ -15,8 +15,8 @@ http://www.gnu.org/licenses/agpl-3.0.html 2023-02-28 - 1.0.3 - stable + 1.0.4-dev + dev 5.14.0 From c45f275fc3cf863be3c31a714f542233c9e7d17c Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Mon, 14 Aug 2023 16:50:25 +0200 Subject: [PATCH 17/30] =?UTF-8?q?=F0=9F=90=9B=20bug=20fix:=20do=20not=20cr?= =?UTF-8?q?eate=20empty=20option=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CRM/TwingleCampaign/BAO/CustomField.php | 1 + CRM/TwingleCampaign/Utils/CaseTypes.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/TwingleCampaign/BAO/CustomField.php b/CRM/TwingleCampaign/BAO/CustomField.php index 9666d30..edeb505 100644 --- a/CRM/TwingleCampaign/BAO/CustomField.php +++ b/CRM/TwingleCampaign/BAO/CustomField.php @@ -243,6 +243,7 @@ class CRM_TwingleCampaign_BAO_CustomField { [ 'id' => $option_value_exists['values'][0]['id'], 'label' => $value, + 'value' => $value, ] ); } diff --git a/CRM/TwingleCampaign/Utils/CaseTypes.php b/CRM/TwingleCampaign/Utils/CaseTypes.php index 312a23f..b05282c 100644 --- a/CRM/TwingleCampaign/Utils/CaseTypes.php +++ b/CRM/TwingleCampaign/Utils/CaseTypes.php @@ -8,7 +8,6 @@ use CRM_TwingleCampaign_ExtensionUtil as E; * @return array */ function getCaseTypes(): array { - $caseTypes = [NULL => E::ts('none')]; try { $result = civicrm_api3('CaseType', 'get', [ 'sequential' => 1, From 8863bbeed0df8a718ace6477c75ad9ccf0fec268 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Mon, 14 Aug 2023 16:53:47 +0200 Subject: [PATCH 18/30] =?UTF-8?q?=F0=9F=94=96=20bump=20version=20to=201.0.?= =?UTF-8?q?4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- info.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/info.xml b/info.xml index 415f6ed..ee812cb 100644 --- a/info.xml +++ b/info.xml @@ -15,8 +15,8 @@ http://www.gnu.org/licenses/agpl-3.0.html 2023-02-28 - 1.0.4-dev - dev + 1.0.4 + stable 5.14.0 From e5ab52f24b402d4925e42c72d6ef8160bfc8570f Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Mon, 14 Aug 2023 17:20:24 +0200 Subject: [PATCH 19/30] =?UTF-8?q?=F0=9F=90=9B=20fix=20bug:=20double=20esca?= =?UTF-8?q?ping=20of=20`\n`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CRM/TwingleCampaign/Utils/MatomoSnippet.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/TwingleCampaign/Utils/MatomoSnippet.php b/CRM/TwingleCampaign/Utils/MatomoSnippet.php index 79fd3ec..f6b62af 100644 --- a/CRM/TwingleCampaign/Utils/MatomoSnippet.php +++ b/CRM/TwingleCampaign/Utils/MatomoSnippet.php @@ -69,7 +69,7 @@ class CRM_TwingleCampaign_Utils_MatomoSnippet { * The combined code after appending the appendix. */ public static function append_code($original, $appendix) { - return $original . '\n' . $appendix; + return $original . $appendix; } } From dc723ed8aa803002ba202022c21b8a2f886633a3 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Mon, 14 Aug 2023 17:45:19 +0200 Subject: [PATCH 20/30] =?UTF-8?q?=F0=9F=90=9B=20bug=20fix:=20wrong=20value?= =?UTF-8?q?=20for=20option=20values?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CRM/TwingleCampaign/BAO/CustomField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/TwingleCampaign/BAO/CustomField.php b/CRM/TwingleCampaign/BAO/CustomField.php index edeb505..da2c824 100644 --- a/CRM/TwingleCampaign/BAO/CustomField.php +++ b/CRM/TwingleCampaign/BAO/CustomField.php @@ -243,7 +243,7 @@ class CRM_TwingleCampaign_BAO_CustomField { [ 'id' => $option_value_exists['values'][0]['id'], 'label' => $value, - 'value' => $value, + 'value' => $key, ] ); } From 571a86ea66bd47b0abe59719c6fad3418e0a7622 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Mon, 14 Aug 2023 18:44:36 +0200 Subject: [PATCH 21/30] =?UTF-8?q?=F0=9F=94=96=20bump=20version=20to=201.0.?= =?UTF-8?q?5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.xml b/info.xml index ee812cb..af3474b 100644 --- a/info.xml +++ b/info.xml @@ -15,7 +15,7 @@ http://www.gnu.org/licenses/agpl-3.0.html 2023-02-28 - 1.0.4 + 1.0.5 stable 5.14.0 From bcd2b448d21c8c17265ce27e8e57912949750e2d Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Mon, 8 Apr 2024 12:18:57 +0200 Subject: [PATCH 22/30] fix udefined constant "error" --- CRM/TwingleCampaign/Upgrader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/TwingleCampaign/Upgrader.php b/CRM/TwingleCampaign/Upgrader.php index 09e7401..f103551 100644 --- a/CRM/TwingleCampaign/Upgrader.php +++ b/CRM/TwingleCampaign/Upgrader.php @@ -96,7 +96,7 @@ class CRM_TwingleCampaign_Upgrader extends CRM_TwingleCampaign_Upgrader_Base { [1 => $e->getMessage()] ), E::ts('Scheduled Job'), - error + 'error' ); } From db1ab691388b20372361cfa75de64406f0c96072 Mon Sep 17 00:00:00 2001 From: Dominic Tubach Date: Fri, 19 Apr 2024 10:15:55 +0200 Subject: [PATCH 23/30] APIWrapper: Make `mapDonation()` static becauts it's called static --- CRM/TwingleCampaign/Utils/APIWrapper.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CRM/TwingleCampaign/Utils/APIWrapper.php b/CRM/TwingleCampaign/Utils/APIWrapper.php index 5afe426..4397aa1 100644 --- a/CRM/TwingleCampaign/Utils/APIWrapper.php +++ b/CRM/TwingleCampaign/Utils/APIWrapper.php @@ -103,12 +103,12 @@ class CRM_TwingleCampaign_Utils_APIWrapper { * the de.systopia.twingle extension can include the campaign into the * contribution which it will create. * - * @param $apiRequest - * @param $callsame + * @param array $apiRequest + * @param callable $callsame * * @return mixed */ - public function mapDonation($apiRequest, $callsame) { + public static function mapDonation(array $apiRequest, callable $callsame) { if (array_key_exists( 'campaign_id', @@ -207,4 +207,4 @@ class CRM_TwingleCampaign_Utils_APIWrapper { } } -} \ No newline at end of file +} From 9118b622d04beada2fd126f9051ea9b609fecf98 Mon Sep 17 00:00:00 2001 From: Dominic Tubach Date: Fri, 19 Apr 2024 10:29:04 +0200 Subject: [PATCH 24/30] APIWrapper: Rethrow exception --- CRM/TwingleCampaign/Utils/APIWrapper.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CRM/TwingleCampaign/Utils/APIWrapper.php b/CRM/TwingleCampaign/Utils/APIWrapper.php index 5afe426..c9c5d68 100644 --- a/CRM/TwingleCampaign/Utils/APIWrapper.php +++ b/CRM/TwingleCampaign/Utils/APIWrapper.php @@ -204,7 +204,9 @@ class CRM_TwingleCampaign_Utils_APIWrapper { 'contribution_id' => $contribution['id'], ] ); + + throw $e; } } -} \ No newline at end of file +} From cbb148b22fe29d6ae9541cd3acf255c02090c549 Mon Sep 17 00:00:00 2001 From: Dominic Tubach Date: Mon, 22 Apr 2024 10:10:51 +0200 Subject: [PATCH 25/30] Avoid `array_key_exists()` on `NULL` --- CRM/TwingleCampaign/Utils/APIWrapper.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/CRM/TwingleCampaign/Utils/APIWrapper.php b/CRM/TwingleCampaign/Utils/APIWrapper.php index 5afe426..932a88d 100644 --- a/CRM/TwingleCampaign/Utils/APIWrapper.php +++ b/CRM/TwingleCampaign/Utils/APIWrapper.php @@ -129,11 +129,7 @@ class CRM_TwingleCampaign_Utils_APIWrapper { } } } - elseif (array_key_exists( - 'event', - $apiRequest['params']['custom_fields']) && - !empty($apiRequest['params']['custom_fields']['event']) - ) { + elseif (!empty($apiRequest['params']['custom_fields']['event'])) { try { $targetCampaign = civicrm_api3( 'TwingleEvent', From beb9d8f170d39a2b7947d1bbe6aeee9a0869ea10 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Sat, 15 Jun 2024 11:36:12 +0200 Subject: [PATCH 26/30] take into account the latest changes to the Twingle API --- .../Exceptions/TwingleCampaignException.php | 4 ++-- CRM/TwingleCampaign/Utils/APIWrapper.php | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CRM/TwingleCampaign/Exceptions/TwingleCampaignException.php b/CRM/TwingleCampaign/Exceptions/TwingleCampaignException.php index 0f99555..61baf6b 100644 --- a/CRM/TwingleCampaign/Exceptions/TwingleCampaignException.php +++ b/CRM/TwingleCampaign/Exceptions/TwingleCampaignException.php @@ -1,8 +1,8 @@ $contribution['campaign_id']] ); - $response['values']['soft_credit'] = + $response['soft_credit'] = self::createSoftCredit($contribution, $twingle_event)['values']; $event->setResponse($response); } catch (CiviCRM_API3_Exception $e) { @@ -58,8 +58,8 @@ class CRM_TwingleCampaign_Utils_APIWrapper { } } // Create soft credit for sepa mandate - elseif (array_key_exists('sepa_mandate', $response['values'])) { - $sepa_mandate = array_pop($response_copy['values']['sepa_mandate']); + elseif (array_key_exists('sepa_mandate', $response)) { + $sepa_mandate = array_pop($response_copy['sepa_mandate']); try { $contribution = civicrm_api3( @@ -84,7 +84,7 @@ class CRM_TwingleCampaign_Utils_APIWrapper { 'getsingle', ['id' => $contribution['contribution_campaign_id']] ); - $response['values']['soft_credit'] = + $response['soft_credit'] = self::createSoftCredit($contribution, $twingle_event)['values']; $event->setResponse($response); } catch (CiviCRM_API3_Exception $e) { From de9cd894b71319d7c611eb648af026f9166b58fb Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Sat, 15 Jun 2024 12:12:35 +0200 Subject: [PATCH 27/30] =?UTF-8?q?=F0=9F=94=96=20bump=20version=20to=201.0.?= =?UTF-8?q?7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- info.xml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/info.xml b/info.xml index af3474b..1b5cc69 100644 --- a/info.xml +++ b/info.xml @@ -14,13 +14,12 @@ https://lab.civicrm.org/Marc_Michalsky/de-forumzfd-twinglecampaign/-/issues http://www.gnu.org/licenses/agpl-3.0.html - 2023-02-28 - 1.0.5 + 2024-06-15 + 1.0.7 stable - 5.14.0 + 5.74 - de.systopia.xcm de.systopia.campaign From 91c70c645a267175c83f84e71eae68d0feebef45 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Thu, 18 Jul 2024 15:35:31 +0200 Subject: [PATCH 28/30] Push only active campaigns to Twingle --- api/v3/TwingleProject/Sync.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/v3/TwingleProject/Sync.php b/api/v3/TwingleProject/Sync.php index aed3d2a..ca72d0e 100644 --- a/api/v3/TwingleProject/Sync.php +++ b/api/v3/TwingleProject/Sync.php @@ -193,8 +193,8 @@ function civicrm_api3_twingle_project_Sync(array $params): array { foreach ($projects_from_civicrm['values'] as $project_from_civicrm) { if ( !in_array($project_from_civicrm['project_id'], - array_column($projects_from_twingle, 'id') - )) { + array_column($projects_from_twingle, 'id'), + ) && $project_from_civicrm['is_active'] == 1) { // store campaign id in $id $id = $project_from_civicrm['id']; unset($project_from_civicrm['id']); From 7415fac88d697df94e68470d9c225c8eadb6b577 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Thu, 18 Jul 2024 15:37:30 +0200 Subject: [PATCH 29/30] Cover the case where an event creator passes only one name part --- CRM/TwingleCampaign/BAO/TwingleEvent.php | 6 ++++-- CRM/TwingleCampaign/Utils/StringOperations.php | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CRM/TwingleCampaign/BAO/TwingleEvent.php b/CRM/TwingleCampaign/BAO/TwingleEvent.php index 4248c1d..faf609b 100644 --- a/CRM/TwingleCampaign/BAO/TwingleEvent.php +++ b/CRM/TwingleCampaign/BAO/TwingleEvent.php @@ -219,13 +219,15 @@ class CRM_TwingleCampaign_BAO_TwingleEvent extends Campaign { private static function matchContact(string $names, string $email): ?int { $names = StringOps::split_names($names); // Hopefully just a temporary solution - $firstnames = $names['firstnames']; - $lastname = $names['lastname']; + $firstnames = $names['firstnames'] ?? NULL; + $lastname = $names['lastname'] ?? NULL; + $display_name = $names['display_name'] ?? NULL; try { $contact = civicrm_api3('Contact', 'getorcreate', [ 'xcm_profile' => Civi::settings()->get('twinglecampaign_xcm_profile'), 'first_name' => $firstnames, 'last_name' => $lastname, + 'display_name' => $display_name, 'email' => $email, ]); return (int) $contact['id']; diff --git a/CRM/TwingleCampaign/Utils/StringOperations.php b/CRM/TwingleCampaign/Utils/StringOperations.php index 19c0fd3..98e6657 100644 --- a/CRM/TwingleCampaign/Utils/StringOperations.php +++ b/CRM/TwingleCampaign/Utils/StringOperations.php @@ -49,7 +49,7 @@ class CRM_TwingleCampaign_Utils_StringOperations { $firstnames = implode(" ", $names); return ['firstnames' => $firstnames, 'lastname' => $lastname]; } - return $string; + return ['display_name' => $string]; } /** @@ -71,4 +71,4 @@ class CRM_TwingleCampaign_Utils_StringOperations { public static function startsWith($haystack, $needle): bool { return substr_compare($haystack, $needle, 0, strlen($needle)) === 0; } -} \ No newline at end of file +} From 012f4901e4c1fa4ce9c42ff5ec0958018affd1be Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Thu, 18 Jul 2024 15:38:42 +0200 Subject: [PATCH 30/30] =?UTF-8?q?=F0=9F=94=96=20bump=20version=20to=201.0.?= =?UTF-8?q?8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- info.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/info.xml b/info.xml index 1b5cc69..7971b85 100644 --- a/info.xml +++ b/info.xml @@ -15,7 +15,7 @@ http://www.gnu.org/licenses/agpl-3.0.html 2024-06-15 - 1.0.7 + 1.0.8 stable 5.74