From 8ee0079b3787cc407b595de35e2e01802c125174 Mon Sep 17 00:00:00 2001 From: Marc Michalsky forumZFD Date: Tue, 29 Sep 2020 08:41:02 +0200 Subject: [PATCH] change createProject() to syncProject() and handle existin projects --- api/v3/TwingleSync/models/TwingleApiCall.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/api/v3/TwingleSync/models/TwingleApiCall.php b/api/v3/TwingleSync/models/TwingleApiCall.php index 2d0bfcf..0d95f42 100644 --- a/api/v3/TwingleSync/models/TwingleApiCall.php +++ b/api/v3/TwingleSync/models/TwingleApiCall.php @@ -106,10 +106,23 @@ class TwingleApiCall { * @throws \CiviCRM_API3_Exception * @throws \Exception */ - return $project->create(); + public function syncProject($values) { + + if (is_array($values)) { + $project = new TwingleProject($values); + + $result = $project->create(); + + if ( + $result['state'] == 'exists' && + $values['last_update'] > $project->getTimestamp() + ) { + $result = $project->update(); } - } catch (\Exception $e) { - // TODO: Handle Exception + + return $result; + } else { + return null; } }