Skip to content

Commit

Permalink
Merge pull request #24059 from eileenmcnaughton/pledged
Browse files Browse the repository at this point in the history
dev/core#3749 Fix process pledges to throw exception when civiPledge disabled
  • Loading branch information
seamuslee001 authored Jul 28, 2022
2 parents f71239a + adca269 commit b7fefa3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
12 changes: 5 additions & 7 deletions CRM/Pledge/BAO/Pledge.php
Original file line number Diff line number Diff line change
Expand Up @@ -772,11 +772,10 @@ public static function getContactPledgeCount($contactID) {
* @param array $params
*
* @return array
* @throws \API_Exception
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public static function updatePledgeStatus($params): array {
public static function updatePledgeStatus(array $params): array {

$returnMessages = [];

Expand Down Expand Up @@ -875,7 +874,7 @@ public static function updatePledgeStatus($params): array {
);
if ($newStatus != $pledgeStatus[$pledgeId]) {
$returnMessages[] = "- status updated to: {$allPledgeStatus[$newStatus]}";
$updateCnt += 1;
++$updateCnt;
}
}

Expand Down Expand Up @@ -992,8 +991,7 @@ public static function updatePledgeStatus($params): array {
civicrm_api3('activity', 'create', $activityParams);
}
catch (CiviCRM_API3_Exception $e) {
$returnMessages[] = "Failed creating Activity for Pledge Reminder: " . $e->getMessage();
return ['is_error' => 1, 'message' => $returnMessages];
throw new CRM_Core_Exception('Failed creating Activity for Pledge Reminder: ' . $e->getMessage());
}
$returnMessages[] = "Payment reminder sent to: {$pledgerName} - {$toEmail}";
}
Expand All @@ -1005,7 +1003,7 @@ public static function updatePledgeStatus($params): array {
// end if ( $sendReminders )
$returnMessages[] = "{$updateCnt} records updated.";

return ['is_error' => 0, 'messages' => implode("\n\r", $returnMessages)];
return $returnMessages;
}

/**
Expand Down
17 changes: 6 additions & 11 deletions api/v3/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,19 +306,14 @@ function _civicrm_api3_job_update_greeting_spec(&$params) {
* @param array $params
*
* @return array
*
* @throws \CRM_Core_Exception
*/
function civicrm_api3_job_process_pledge($params) {
// *** Uncomment the next line if you want automated reminders to be sent
// $params['send_reminders'] = true;
$result = CRM_Pledge_BAO_Pledge::updatePledgeStatus($params);

if ($result['is_error'] == 0) {
// experiment: detailed execution log is a result here
return civicrm_api3_create_success($result['messages']);
}
else {
return civicrm_api3_create_error($result['error_message']);
function civicrm_api3_job_process_pledge(array $params): array {
if (!CRM_Core_Component::isEnabled('CiviPledge')) {
throw new CRM_Core_Exception(ts('%1 is not enabled'), [1 => ['CiviPledge']]);
}
return civicrm_api3_create_success(implode("\n\r", CRM_Pledge_BAO_Pledge::updatePledgeStatus($params)));
}

/**
Expand Down

0 comments on commit b7fefa3

Please sign in to comment.