From bbbf6e1cc6ae941389fb9e9fe58a64de74016668 Mon Sep 17 00:00:00 2001 From: Marc Michalsky Date: Wed, 25 Aug 2021 16:06:50 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=EF=B8=8F=20Do=20not=20sync=20Twingle?= =?UTF-8?q?=20projects=20to=20CiviCRM=20which=20are=20marked=20as=20such?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is a checkbox in TwingleMANAGER that allows you to enable and disable API calls to the Twingl API (de.systopia.twingle). This commit makes the TwingleCampaign extension pay attention to this checkbox, so if it is unchecked, no campaign will be created in CiviCRM for this Twingle project. --- CRM/TwingleCampaign/BAO/TwingleProject.php | 5 +++++ api/v3/TwingleProject/Sync.php | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CRM/TwingleCampaign/BAO/TwingleProject.php b/CRM/TwingleCampaign/BAO/TwingleProject.php index 46e4a53..8f509c0 100644 --- a/CRM/TwingleCampaign/BAO/TwingleProject.php +++ b/CRM/TwingleCampaign/BAO/TwingleProject.php @@ -165,6 +165,11 @@ class CRM_TwingleCampaign_BAO_TwingleProject extends Campaign { */ public function create(bool $no_hook = FALSE): bool { + # If this project is not meant to be synced, do not create a campaign + if (!$this->values['project_options']['has_civi_crm_activated']) { + return FALSE; + } + $result = parent::create($no_hook); // Check if campaign was created successfully diff --git a/api/v3/TwingleProject/Sync.php b/api/v3/TwingleProject/Sync.php index 4d578ce..26a46be 100644 --- a/api/v3/TwingleProject/Sync.php +++ b/api/v3/TwingleProject/Sync.php @@ -230,9 +230,14 @@ function civicrm_api3_twingle_project_Sync(array $params): array { $project->getResponse('Ready to create TwingleProject'); } - $project->create(TRUE); - $returnValues[$project->getId()] = - $project->getResponse('TwingleProject created'); + if ($project->create(TRUE)) { + $returnValues[$project->getId()] = + $project->getResponse('TwingleProject created'); + } + else { + $returnValues[$project->getId()] = + $project->getResponse('TwingleProject not selected for synchronization'); + } } catch (Exception $e) { $errors[$project_from_twingle['id']] = $e->getMessage(); Civi::log()->error(