From d449a97d6aa360dcc234a4a563bdade85162742e Mon Sep 17 00:00:00 2001 From: Itamar Bar-Lev Shapira Date: Wed, 1 Feb 2017 17:23:09 +0100 Subject: [PATCH 1/3] Drush command for resending messages --- drush/message_notify.drush.inc | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 drush/message_notify.drush.inc diff --git a/drush/message_notify.drush.inc b/drush/message_notify.drush.inc new file mode 100644 index 0000000..2021bf9 --- /dev/null +++ b/drush/message_notify.drush.inc @@ -0,0 +1,62 @@ + 'message_notify_resend', + 'description' => 'Resend selected messages by minimal and maximal message IDs.', + 'arguments' => array( + 'min_mid' => 'Message ID to start from.', + 'max_mid' => 'Maximal message ID to resend.', + ), + 'options' => array( + 'notifier' => "The notifier to use. 'email' by default.", + ), + 'examples' => array( + 'drush message-resend 120 140' => '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) { + 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'); +} From 4852b4fd175cbe700d22be397a9c382fe04680e3 Mon Sep 17 00:00:00 2001 From: Itamar Bar-Lev Shapira Date: Wed, 1 Feb 2017 17:30:23 +0100 Subject: [PATCH 2/3] Adding comment --- drush/message_notify.drush.inc | 1 + 1 file changed, 1 insertion(+) diff --git a/drush/message_notify.drush.inc b/drush/message_notify.drush.inc index 2021bf9..ee76cbc 100644 --- a/drush/message_notify.drush.inc +++ b/drush/message_notify.drush.inc @@ -49,6 +49,7 @@ function message_notify_resend($min_mid, $max_mid) { $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++; From 594d27ef1ef90d7dda5188e6cc4cb32341b97723 Mon Sep 17 00:00:00 2001 From: Itamar Bar-Lev Shapira Date: Wed, 1 Feb 2017 17:38:43 +0100 Subject: [PATCH 3/3] Making command description translatable --- drush/message_notify.drush.inc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drush/message_notify.drush.inc b/drush/message_notify.drush.inc index ee76cbc..a13610a 100644 --- a/drush/message_notify.drush.inc +++ b/drush/message_notify.drush.inc @@ -13,16 +13,16 @@ function message_notify_drush_command() { $items['message-resend'] = array( 'callback' => 'message_notify_resend', - 'description' => 'Resend selected messages by minimal and maximal message IDs.', + 'description' => dt('Resend selected messages by minimal and maximal message IDs.'), 'arguments' => array( - 'min_mid' => 'Message ID to start from.', - 'max_mid' => 'Maximal message ID to resend.', + 'min_mid' => dt('Message ID to start from.'), + 'max_mid' => dt('Maximal message ID to resend.'), ), 'options' => array( - 'notifier' => "The notifier to use. 'email' by default.", + 'notifier' => dt('The notifier to use. \'email\' by default.'), ), 'examples' => array( - 'drush message-resend 120 140' => 'Resend messages with ID between 120 and 140.', + 'drush message-resend 120 140' => dt('Resend messages with ID between 120 and 140.'), ), );