* @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 = [];
);
if ($newStatus != $pledgeStatus[$pledgeId]) {
$returnMessages[] = "- status updated to: {$allPledgeStatus[$newStatus]}";
- $updateCnt += 1;
+ ++$updateCnt;
}
}
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}";
}
// end if ( $sendReminders )
$returnMessages[] = "{$updateCnt} records updated.";
- return ['is_error' => 0, 'messages' => implode("\n\r", $returnMessages)];
+ return $returnMessages;
}
/**
* @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)));
}
/**