From 84e1b1196ee371fe981588bd0afc29bd2bb80768 Mon Sep 17 00:00:00 2001 From: Marc Michalsky forumZFD Date: Thu, 10 Dec 2020 15:29:17 +0100 Subject: [PATCH] implement TwingleProject.create --- api/v3/TwingleProject/Create.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/api/v3/TwingleProject/Create.php b/api/v3/TwingleProject/Create.php index ce8df35..007995d 100644 --- a/api/v3/TwingleProject/Create.php +++ b/api/v3/TwingleProject/Create.php @@ -50,6 +50,7 @@ function _civicrm_api3_twingle_project_Create_spec(array &$spec) { * */ function civicrm_api3_twingle_project_Create($params) { + $returnValues = []; $title = $params['title']; $name = strtolower(preg_replace('/[^A-Za-z0-9]/', '_', $title)); @@ -65,14 +66,29 @@ function civicrm_api3_twingle_project_Create($params) { $project = new TwingleProject($values, 'CIVICRM'); - $project->create(); + $create_project = $project->create(); - $sync = $result = civicrm_api3('TwingleSync', 'post'); + $projectId = $project->getId(); + + $sync = $result = civicrm_api3( + 'TwingleSync', + 'singlesync', + ['campaign_id' => $projectId] + ); if ($sync['is_error'] == 0) { - $returnValues = civicrm_api3(); + $returnValues = $sync['values']['project']; + } + elseif ($create_project['status'] == "TwingleProject created") { + throw new API_Exception( + "TwingleProject was created but could not get pushed to Twingle" + ); + } + else { + throw new API_Exception( + "TwingleProject creation failed" + ); } - $returnValues = null; return civicrm_api3_create_success($returnValues, $params, 'TwingleProject', 'Create'); }