move logic for pushing TwingleProjects into TwingleProject class

This commit is contained in:
Marc Michalsky forumZFD 2020-11-13 16:18:16 +01:00
parent 2aee8ca2d9
commit 690e26410b
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
2 changed files with 31 additions and 31 deletions

View file

@ -108,37 +108,8 @@ class TwingleApiCall {
// Prepare url for curl
$url = $this->protocol . 'project' . $this->baseUrl . $values['id'];
// Send curl
$result = $this->curlPost($url, $values);
// Update TwingleProject in Civi with results from api call
if (is_array($result) && !array_key_exists('message', $result)) {
// Try to update the local TwingleProject campaign
try {
$project->update($result);
$project->create();
return $project->getResponse('TwingleProject pushed to Twingle');
} catch (Exception $e) {
// Log Exception
Civi::log()->error(
"Could not push TwingleProject campaign: $e->getMessage()"
);
// Return result array with error description
return $project->getResponse(
"TwingleProject was likely pushed to Twingle but the
local update of the campaign failed: $e->getMessage()"
);
}
}
else {
$message = $result['message'];
return $project->getResponse(
$message
? "TwingleProject could not get pushed to Twingle: $message"
: 'TwingleProject could not get pushed to Twingle'
);
}
// Send curl and return result
return $this->curlPost($url, $values);
}
/**

View file

@ -152,6 +152,35 @@ class TwingleProject extends Campaign {
}
else {
$result = $twingleApi->pushProject($project);
// Update TwingleProject in Civi with results from api call
if (is_array($result) && !array_key_exists('message', $result)) {
// Try to update the local TwingleProject campaign
try {
$project->update($result);
$project->create();
return $project->getResponse('TwingleProject pushed to Twingle');
} catch (Exception $e) {
// Log Exception
$errorMessage = $e->getMessage();
Civi::log()->error(
"Could not push TwingleProject campaign: $errorMessage"
);
// Return result array with error description
return $project->getResponse(
"TwingleProject was likely pushed to Twingle but the local " .
"update of the campaign failed: $errorMessage"
);
}
}
else {
$message = $result['message'];
return $project->getResponse(
$message
? "TwingleProject could not get pushed to Twingle: $message"
: 'TwingleProject could not get pushed to Twingle'
);
}
}
}
elseif ($result['status'] == 'TwingleProject exists') {