From f1835dd405765608ab8b3a97825a2468a45742b4 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Thu, 12 Oct 2017 13:35:56 +0000 Subject: [PATCH] Bug 12802: Update all circulation alerts, not only the first one Since SendCirculationAlert can generate multiple entries in message_queue, it should update them all if pending messages already exist --- C4/Circulation.pm | 10 ++++++---- C4/Message.pm | 19 ++++++++----------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index b915b34007..8a0f691eec 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3362,13 +3362,15 @@ sub SendCirculationAlert { $schema->storage->txn_begin; C4::Context->dbh->do(q|LOCK TABLE message_queue READ|) unless $do_not_lock; C4::Context->dbh->do(q|LOCK TABLE message_queue WRITE|) unless $do_not_lock; - my $message = C4::Message->find_last_message($borrower, $type, $mtt); - unless ( $message ) { + my @messages = C4::Message->find_last_messages($borrower, $type, $mtt); + unless ( @messages ) { C4::Context->dbh->do(q|UNLOCK TABLES|) unless $do_not_lock; C4::Message->enqueue($letter, $borrower, $mtt); } else { - $message->append($letter); - $message->update; + foreach my $message (@messages) { + $message->append($letter); + $message->update; + } } C4::Context->dbh->do(q|UNLOCK TABLES|) unless $do_not_lock; $schema->storage->txn_commit; diff --git a/C4/Message.pm b/C4/Message.pm index 800b82f30d..29a190bd13 100644 --- a/C4/Message.pm +++ b/C4/Message.pm @@ -53,7 +53,7 @@ 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'); + my $message = C4::Message->find_last_messages($borrower, 'CHECKOUT', 'email'); $message->append("you also checked out some other book...."); $message->update; @@ -110,17 +110,17 @@ sub find { } } -=head3 C4::Message->find_last_message($borrower, $letter_code, $transport) +=head3 C4::Message->find_last_messages($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 +checkout messages. (This makes it possible to add more information to the message before it gets sent out.) =cut -# C4::Message->find_last_message($borrower, $letter_code, $transport) -# -- get the borrower's most recent pending checkin or checkout notification -sub find_last_message { +# C4::Message->find_last_messages($borrower, $letter_code, $transport) +# -- get the borrower's most recent pending checkin or checkout notifications +sub find_last_messages { my ($class, $borrower, $letter_code, $transport) = @_; # $type is the message_transport_type $transport ||= 'email'; @@ -139,11 +139,8 @@ sub find_last_message { $letter_code, $transport, ); - if (@$msgs) { - return $class->new($msgs->[0]); - } else { - return; - } + + return map { $class->new($_) } @$msgs; } -- 2.11.0