diff --git a/message_notify.module b/message_notify.module index bc07651..59a989d 100644 --- a/message_notify.module +++ b/message_notify.module @@ -6,6 +6,15 @@ */ /** + * Implements hook_cron_queue_info_alter(). + */ +function message_notify_cron_queue_info_alter(&$queues) { + if (module_exists('queue_mail')) { + $queues[QUEUE_MAIL_QUEUE_NAME]['worker callback'] = 'message_notify_send_queued_message'; + } +} + +/** * Process and send a message. * * @param $message @@ -34,6 +43,23 @@ function message_notify_send_message(Message $message, array $options = array(), } /** + * Worker callback for Queue Mail items. + */ +function message_notify_send_queued_message($message = array()) { + $message = queue_mail_send($message); + + if ($message['module'] == 'message_notify') { + $plugin = message_notify_get_notifier('email'); + $class = ctools_plugin_load_class('message_notify', 'notifier', 'email', 'class'); + + $notifier = new $class($plugin, $message['params']['message_entity']); + $notifier->postSend($message['result'] ? MESSAGE_NOTIFY_SUCCESS : MESSAGE_NOTIFY_ERROR, $message); + } + + return $message; +} + +/** * Add defaults values to the notifier plugins. * * - 'description': The description of the plugin. diff --git a/plugins/notifier/abstract.inc b/plugins/notifier/abstract.inc index 4283e77..3659ac0 100644 --- a/plugins/notifier/abstract.inc +++ b/plugins/notifier/abstract.inc @@ -1,5 +1,9 @@ deliver($output); - $this->postSend($result, $output); + + if ($result != MESSAGE_NOTIFY_QUEUE) { + $this->postSend($result, $output); + } + return $result; } @@ -97,13 +105,13 @@ abstract class MessageNotifierBase implements MessageNotifierInterface { $options = $plugin['options']; $save = FALSE; - if (!$result) { - watchdog('message_notify', t('Could not send message using @title to user ID @uid.'), array('@label' => $plugin['title'], '@uid' => $message->uid), WATCHDOG_ERROR); + if ($result == MESSAGE_NOTIFY_ERROR) { + watchdog('message_notify', t('Could not send message using @title to user ID @uid.'), array('@title' => $plugin['title'], '@uid' => $message->uid), WATCHDOG_ERROR); if ($options['save on fail']) { $save = TRUE; } } - elseif ($result && $options['save on success']) { + elseif ($result == MESSAGE_NOTIFY_SUCCESS && $options['save on success']) { $save = TRUE; } diff --git a/plugins/notifier/email/MessageNotifierEmail.class.php b/plugins/notifier/email/MessageNotifierEmail.class.php index b0e5da4..e928a29 100644 --- a/plugins/notifier/email/MessageNotifierEmail.class.php +++ b/plugins/notifier/email/MessageNotifierEmail.class.php @@ -28,8 +28,13 @@ class MessageNotifierEmail extends MessageNotifierBase { // Pass the message entity along to hook_drupal_mail(). $output['message_entity'] = $message; - $result = drupal_mail('message_notify', $message->type, $mail, $lang, $output); - return $result['result']; + $result = drupal_mail('message_notify', $message->type, $mail, $lang, $output); + + if ($result['send']) { + return $result['result'] ? MESSAGE_NOTIFY_SUCCESS : MESSAGE_NOTIFY_ERROR; + } + + return MESSAGE_NOTIFY_QUEUE; } } diff --git a/plugins/notifier/sms/MessageNotifierSMS.class.php b/plugins/notifier/sms/MessageNotifierSMS.class.php index e3fe434..276fed2 100644 --- a/plugins/notifier/sms/MessageNotifierSMS.class.php +++ b/plugins/notifier/sms/MessageNotifierSMS.class.php @@ -20,6 +20,10 @@ class MessageNotifierSMS extends MessageNotifierBase { throw new MessageNotifyException('Message cannot be sent using SMS as the "smsNumber" property is missing from the Message entity or user entity.'); } - return sms_send($this->message->smsNumber, strip_tags($output['message_notify_sms_body'])); + if (sms_send($this->message->smsNumber, strip_tags($output['message_notify_sms_body']))) { + return MESSAGE_NOTIFY_SUCCESS; + } + + return MESSAGE_NOTIFY_ERROR; } } diff --git a/tests/plugins/notifier/MessageNotifierTest.class.php b/tests/plugins/notifier/MessageNotifierTest.class.php index 1efc3e1..d5a7894 100644 --- a/tests/plugins/notifier/MessageNotifierTest.class.php +++ b/tests/plugins/notifier/MessageNotifierTest.class.php @@ -7,8 +7,8 @@ class MessageNotifierTest extends MessageNotifierBase { public function deliver(array $output = array()) { $this->message->output = $output; - // Return TRUE or FALSE as it was set on the Message. - return empty($this->fail); + // Return message status. + return empty($this->fail) ? MESSAGE_NOTIFY_SUCCESS : MESSAGE_NOTIFY_ERROR; } }