diff --git a/message.drush.inc b/message.drush.inc new file mode 100644 index 0000000..9c2a57f --- /dev/null +++ b/message.drush.inc @@ -0,0 +1,72 @@ + 'Show a message that has been saved to the database.', + 'arguments' => array( + 'id' => 'The ID of the message instance to show.', + ), + 'options' => array( + 'entity' => "May specify that the ID should be used to look up 'node', 'comment', or 'user'-related messages.", + ), + 'aliases' => array('msg-show'), + ); + + return $items; +} + +/** + * Implementation of hook_drush_help(). + */ +function message_drush_help($section) { + switch ($section) { + case 'drush:message-show': + return dt('Supply a message or entity id, see the related messages rendered.'); + } +} + +/** + * Command callback for message-show. + */ +function drush_message_show($id) { + $entity = drush_get_option('entity', ''); + + if (empty($entity)) { + $messages = array($id); + } + else { + $sql = "SELECT iid FROM {message_instance} WHERE entity_type = '%s' AND eid = %d"; + $results = db_query($sql, $entity, $id); + + $messages = array(); + while ($item = db_result($results)) { + $messages[] = $item; + } + } + + _drush_message_print_messages($messages); +} + +/** + * Helper function to render the passed message. + */ +function _drush_message_print_messages($messages) { + $messages = message_instance_load_multiple($messages); + + $output[0] = array('iid', 'rendered message'); + foreach ($messages as $key => $message) { + $output[$message->iid] = array($message->iid, message_show_message($message, TRUE)); + } + + drush_print_table($output, TRUE); +}