diff --git a/CRM/TwingleCampaign/BAO/TwingleApiCall.php b/CRM/TwingleCampaign/BAO/TwingleApiCall.php index 52d2627..66d2052 100644 --- a/CRM/TwingleCampaign/BAO/TwingleApiCall.php +++ b/CRM/TwingleCampaign/BAO/TwingleApiCall.php @@ -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); } /** diff --git a/CRM/TwingleCampaign/BAO/TwingleProject.php b/CRM/TwingleCampaign/BAO/TwingleProject.php index 185fbd3..4c38617 100644 --- a/CRM/TwingleCampaign/BAO/TwingleProject.php +++ b/CRM/TwingleCampaign/BAO/TwingleProject.php @@ -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') {