CRM_Core_BAO_ActionSchedule::processQueue is only called from one place. It either succeeds or throws
an exception so there is no value in returning anything & the parsing of what it does return assumes that it
could return false
Some slight tightenig around typing as buildRecipientContact is also only called from one place
*
* @return array
* Array(scalar $id => Mapping $mapping).
+ *
* @throws \CRM_Core_Exception
*/
public static function getMappings($filters = NULL) {
}
/**
- * @param int $mappingID
- * @param $now
+ * Build a list of the contacts to send to.
+ *
+ * @param string $mappingID
+ * Value from the mapping_id field in the civicrm_action_schedule able. It might be a string like
+ * 'contribpage' for an older class like CRM_Contribute_ActionMapping_ByPage of for ones following
+ * more recent patterns, an integer.
+ * @param string $now
* @param array $params
*
* @throws API_Exception
+ * @throws \CRM_Core_Exception
*/
- public static function buildRecipientContacts($mappingID, $now, $params = []) {
+ public static function buildRecipientContacts(string $mappingID, $now, $params = []) {
$actionSchedule = new CRM_Core_DAO_ActionSchedule();
+
$actionSchedule->mapping_id = $mappingID;
$actionSchedule->is_active = 1;
if (!empty($params)) {
}
/**
- * @param null $now
+ * Main processing callback for sending out scheduled reminders.
+ *
+ * @param string $now
* @param array $params
*
- * @return array
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
*/
public static function processQueue($now = NULL, $params = []) {
$now = $now ? CRM_Utils_Time::setTime($now) : CRM_Utils_Time::getTime();
$mappings = CRM_Core_BAO_ActionSchedule::getMappings();
foreach ($mappings as $mappingID => $mapping) {
- CRM_Core_BAO_ActionSchedule::buildRecipientContacts($mappingID, $now, $params);
+ CRM_Core_BAO_ActionSchedule::buildRecipientContacts((string) $mappingID, $now, $params);
CRM_Core_BAO_ActionSchedule::sendMailings($mappingID, $now);
}
-
- $result = [
- 'is_error' => 0,
- 'messages' => ts('Sent all scheduled reminders successfully'),
- ];
- return $result;
}
/**
* @param string $returnFormat
* Format in which date is to be retrieved.
*
- * @return date
+ * @return string
*/
public static function getTime($returnFormat = 'YmdHis') {
return date($returnFormat, self::getTimeRaw());
* @param string $returnFormat
* Format in which date is to be retrieved.
*
- * @return date
+ * @return string
*/
public static function setTime($newDateTime, $returnFormat = 'YmdHis') {
self::$_delta = strtotime($newDateTime) - time();
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
- * $Id$
- *
*/
}
/**
- * Send the scheduled reminders for all contacts (either for activities or events).
+ * Send the scheduled reminders as configured.
*
* @param array $params
- * (reference ) input parameters.
- * now - the time to use, in YmdHis format
- * - makes testing a bit simpler since we can simulate past/future time
+ * - now - the time to use, in YmdHis format
+ * - makes testing a bit simpler since we can simulate past/future time
*
* @return array
+ * @throws \API_Exception
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
function civicrm_api3_job_send_reminder($params) {
//note that $params['rowCount' can be overridden by one of the preferred syntaxes ($options['limit'] = x
$params['rowCount'] = 0;
$lock = Civi::lockManager()->acquire('worker.core.ActionSchedule');
if (!$lock->isAcquired()) {
- return civicrm_api3_create_error('Could not acquire lock, another ActionSchedule process is running');
+ throw new API_Exception('Could not acquire lock, another ActionSchedule process is running');
}
- $result = CRM_Core_BAO_ActionSchedule::processQueue(CRM_Utils_Array::value('now', $params), $params);
+ CRM_Core_BAO_ActionSchedule::processQueue($params['now'] ?? NULL, $params);
$lock->release();
-
- if ($result['is_error'] == 0) {
- return civicrm_api3_create_success();
- }
- else {
- return civicrm_api3_create_error($result['messages']);
- }
+ return civicrm_api3_create_success(1, $params, 'ActionSchedule', 'send_reminder');
}
/**