delete TwingleProject by project_id

This commit is contained in:
Marc Michalsky forumZFD 2021-02-08 13:59:08 +01:00
parent f6d46520cd
commit 6affd53c02
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9

View file

@ -81,28 +81,43 @@ function civicrm_api3_twingle_project_Delete(array $params): array {
$params['sequential'] = 1;
// Delete TwingleProject on Twingle's side
try {
$twingleApi->deleteProject($params['project_id']);
$result_values['twingle'] = 'TwingleProject deleted';
} catch (Exception $e) {
// If Twingle does not know the project_id
if ($e->getMessage() == 'http status code 404 (not found)') {
$result_values['twingle'] = 'project not found';
}
// If the deletion curl failed
else {
$error_occurred = TRUE;
Civi::log()->error(
E::LONG_NAME .
' could not delete TwingleProject (project_id ' . $params['project_id']
. ') on Twingle\'s side: ' . $e->getMessage(),
);
// Set deletion status
// To delete the TwingleProject on Twingle's side, we need the project_id
// If no project_id is provided, try to get it via TwingleProject.getsingle
if (!$params['project_id']) {
try {
$project = civicrm_api3('TwingleProject', 'getsingle', $params);
$params['project_id'] = $project['values'][0]['project_id'];
} catch (CiviCRM_API3_Exception $e) {
$result_values['twingle'] = 'Could not delete TwingleProject: ' . $e->getMessage();
}
}
// Delete TwingleProject on Twingle's side
if ($params['project_id']) {
try {
$twingleApi->deleteProject($params['project_id']);
$result_values['twingle'] = 'TwingleProject deleted';
} catch (Exception $e) {
// If Twingle does not know the project_id
if ($e->getMessage() == 'http status code 404 (not found)') {
$result_values['twingle'] = 'project not found';
}
// If the deletion curl failed
else {
$error_occurred = TRUE;
Civi::log()->error(
E::LONG_NAME .
' could not delete TwingleProject (project_id ' . $params['project_id']
. ') on Twingle\'s side: ' . $e->getMessage(),
);
// Set deletion status
$result_values['twingle'] = 'Could not delete TwingleProject: ' . $e->getMessage();
}
}
}
// Delete the TwingleProject campaign on CiviCRM's side
try {
$project = civicrm_api3('TwingleProject', 'getsingle', $params);
@ -139,5 +154,4 @@ function civicrm_api3_twingle_project_Delete(array $params): array {
'Delete'
);
}
}