Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions drush/message_notify.drush.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/**
* @file
* Message notify drush commands.
*/

/**
* Implements hook_drush_command().
*/
function message_notify_drush_command() {
$items = array();

$items['message-resend'] = array(
'callback' => 'message_notify_resend',
'description' => dt('Resend selected messages by minimal and maximal message IDs.'),
'arguments' => array(
'min_mid' => dt('Message ID to start from.'),
'max_mid' => dt('Maximal message ID to resend.'),
),
'options' => array(
'notifier' => dt('The notifier to use. \'email\' by default.'),
),
'examples' => array(
'drush message-resend 120 140' => dt('Resend messages with ID between 120 and 140.'),
),
);

return $items;
}

/**
* Drush callback: Resend messages.
*/
function message_notify_resend($min_mid, $max_mid) {
// Allow to change the notifier.
$notifier = drush_get_option('notifier', 'email');

// Fetch the messages.
$query = new EntityFieldQuery();
$result = $query->entityCondition('entity_type', 'message')
->propertyCondition('mid', array(intval($min_mid), intval($max_mid)), 'BETWEEN')
->execute();

if (empty($result['message'])) {
drush_log(dt('No messages found.'), 'ok');
return;
}

$sent_count = 0;
foreach (message_load_multiple(array_keys($result['message'])) as $message) {
// Send the message.
if (message_notify_send_message($message, array(), $notifier)) {
drush_log(dt('Message #@mid resent.', array('@mid' => $message->mid)), 'success');
$sent_count++;
}
else {
drush_log(dt('Failed sending message #@mid.', array('@mid' => $message->mid)), 'error');
}
}

drush_log(dt('Resent @count messages by @notifier.', array('@count' => $sent_count, '@notifier' => $notifier)), 'success');
}