/**
* @param array $filters
* Filter by property (e.g. 'id').
+ *
* @return array
* Array(scalar $id => Mapping $mapping).
+ *
+ * @throws \CRM_Core_Exception
*/
public static function getMappings($filters = NULL) {
static $_action_mapping;
if ($_action_mapping === NULL) {
- $event = \Civi\Core\Container::singleton()->get('dispatcher')
- ->dispatch(\Civi\ActionSchedule\Events::MAPPINGS,
+ $event = \Civi::dispatcher()
+ ->dispatch('civi.actionSchedule.getMappings',
new \Civi\ActionSchedule\Event\MappingRegisterEvent());
$_action_mapping = $event->getMappings();
}
* @param int $id
* ID of the Reminder to be deleted.
*
+ * @throws CRM_Core_Exception
*/
public static function del($id) {
if ($id) {
return;
}
}
- CRM_Core_Error::fatal(ts('Invalid value passed to delete function.'));
+ throw new CRM_Core_Exception(ts('Invalid value passed to delete function.'));
}
/**
}
/**
- * @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;
}
/**
$select->where("e.id = reminder.entity_id OR reminder.entity_table = 'civicrm_contact'");
}
- \Civi\Core\Container::singleton()->get('dispatcher')
+ \Civi::dispatcher()
->dispatch(
- \Civi\ActionSchedule\Events::MAILING_QUERY,
+ 'civi.actionSchedule.prepareMailingQuery',
new \Civi\ActionSchedule\Event\MailingQueryEvent($actionSchedule, $mapping, $select)
);
* @return \Civi\Token\TokenProcessor
*/
protected static function createTokenProcessor($schedule, $mapping) {
- $tp = new \Civi\Token\TokenProcessor(\Civi\Core\Container::singleton()->get('dispatcher'), [
+ $tp = new \Civi\Token\TokenProcessor(\Civi::dispatcher(), [
'controller' => __CLASS__,
'actionSchedule' => $schedule,
'actionMapping' => $mapping,