C4::Message - object for messages in the message_queue table


How to add a new message to the queue:

  use C4::Message;
  use C4::Items;
  my $borrower = { borrowernumber => 1 };
  my $item     = C4::Items::GetItem(1);
  my $letter =  C4::Letters::GetPreparedLetter (
      module => 'circulation',
      letter_code => 'CHECKOUT',
      branchcode => $branch,
      tables => {
          'biblio', $item->{biblionumber},
          'biblioitems', $item->{biblionumber},
  C4::Message->enqueue($letter, $borrower->{borrowernumber}, 'email');

How to update a borrower's last checkout message:

  use C4::Message;
  my $borrower = { borrowernumber => 1 };
  my $message  = C4::Message->find_last_message($borrower, 'CHECKOUT', 'email');
  $message->append("you also checked out some other book....");


This module presents an OO interface to the message_queue. Previously, you could only add messages to the message_queue via C4::Letters::EnqueueMessage(). With this module, you can also get previously inserted messages, manipulate them, and save them back to the database.

Class Methods


This method creates an in-memory version of a message object.


This method searches the message_queue table for a row with the given message_id and it'll return a C4::Message object if it finds one.

C4::Message->find_last_message($borrower, $letter_code, $transport)

This method is used to get the borrower's most recent, pending, check-in or checkout message. (This makes it possible to add more information to the message before it gets sent out.)

C4::Message->enqueue($letter, $borrower, $transport)

This is a front-end for C4::Letters::EnqueueLetter() that adds metadata to the message.

Instance Methods


This saves the $message object back to the database. It needs to have already been created via enqueue for this to work.


This method automatically serializes and deserializes the metadata attribute. (It is stored in YAML format.)


If passed a hashref, this method will assume that the hashref is in the form that C4::Letters::getletter() returns. It will append the body of the letter to the message.


If passed a string, it'll append the string to the message.

Attributes Accessors














C4::Circulation, C4::Letters, C4::Members::Messaging


John Beppu <john.beppu@liblime.com>