From 5ac7f3690d274e93cd38ee441c480d4d9c597a52 Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Mon, 21 Oct 2019 19:18:55 -0300 Subject: [PATCH] Bug 23673: Add "Updated on" column to patron's notices This patch adds "Updated on" column to patron's notices tab. It also adds logic to C4::Letters to retrieve updated_on column. To test: 1. Apply patches. 2. Restart plack. 3. Choose a patron and add a purchase suggestion. 4. Change suggestion status. 5. Open patron's notifications. CHECK => Messages table has now "Updated on" and "Time created" columns, and "Time" column is gone. SUCCESS => There is a message with status pending, with a "time created" that equals "updated on" 6. Execute in the shell in Koha directory $ ./misc/cronjobs/process_message_queue.pl 7. Open patron's notifications one more time. SUCCESS => The message changed status. Time created remained the same, and now "updated on" has the current timestamp. 8. Resend the message and repeat sep 6. SUCCESS => Every time you change the status, time created remains the same and updated on updates. 9. Run `prove t/db_dependant/Letters.t` 10. Sign off Signed-off-by: Kelly McElligott Signed-off-by: Andrew Fuerste-Henry Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- C4/Letters.pm | 6 +++--- .../intranet-tmpl/prog/en/modules/members/notices.tt | 6 ++++-- t/db_dependent/Letters.t | 8 +++++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 097096a501..0233ef52f4 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -1070,7 +1070,7 @@ sub GetQueuedMessages { my $dbh = C4::Context->dbh(); my $statement = << 'ENDSQL'; -SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued +SELECT message_id, borrowernumber, subject, content, message_transport_type, status, time_queued, updated_on FROM message_queue ENDSQL @@ -1124,7 +1124,7 @@ sub GetMessage { return unless $message_id; my $dbh = C4::Context->dbh; return $dbh->selectrow_hashref(q| - SELECT message_id, borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, content_type + SELECT message_id, borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, updated_on, to_address, from_address, content_type FROM message_queue WHERE message_id = ? |, {}, $message_id ); @@ -1368,7 +1368,7 @@ sub _is_duplicate { WHERE message_transport_type = ? AND borrowernumber = ? AND letter_code = ? - AND CAST(time_queued AS date) = CAST(NOW() AS date) + AND CAST(updated_on AS date) = CAST(NOW() AS date) AND status="sent" AND content = ? |, {}, $message->{message_transport_type}, $message->{borrowernumber}, $message->{letter_code}, $message->{content} ); diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt index b5e2bebe7b..bf81f012e2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/notices.tt @@ -35,7 +35,8 @@ Notice Type Status - Time + Updated on + Time created @@ -73,6 +74,7 @@ [% END %] + [% QUEUED_MESSAGE.updated_on | $KohaDates with_hours => 1 %] [% QUEUED_MESSAGE.time_queued | $KohaDates with_hours => 1 %] [% END %] @@ -98,7 +100,7 @@ $(document).ready(function() { $("#noticestable").dataTable($.extend(true, {}, dataTablesDefaults, { "aaSorting": [[ 3, "desc" ]], - "aoColumns": [ null,null,null,{ "sType": "title-string" } ], + "aoColumns": [ null,null,null, { "sType": "title-string" } ,{ "sType": "title-string" } ], "sPaginationType": "full" })); diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index 41f2a05fb8..6353f9c07d 100644 --- a/t/db_dependent/Letters.t +++ b/t/db_dependent/Letters.t @@ -18,7 +18,7 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 69; +use Test::More tests => 73; use Test::MockModule; use Test::Warn; @@ -132,8 +132,12 @@ is( $messages->[0]->{subject}, $my_message->{letter}->{title}, 'EnqueueLetter st is( $messages->[0]->{content}, $my_message->{letter}->{content}, 'EnqueueLetter stores the content correctly' ); is( $messages->[0]->{message_transport_type}, $my_message->{message_transport_type}, 'EnqueueLetter stores the message type correctly' ); is( $messages->[0]->{status}, 'pending', 'EnqueueLetter stores the status pending correctly' ); +isnt( $messages->[0]->{time_queued}, undef, 'Time queued inserted by default in message_queue table' ); +is( $messages->[0]->{updated_on}, $messages->[0]->{time_queued}, 'Time status changed equals time queued when created in message_queue table' ); +my $message_time_queued = $messages->[0]->{time_queued}; +sleep 1; # SendQueuedMessages my $messages_processed = C4::Letters::SendQueuedMessages( { type => 'email' }); is($messages_processed, 0, 'No queued messages processed if type limit passed with unused type'); @@ -145,6 +149,8 @@ is( 'failed', 'message marked failed if tried to send SMS message for borrower with no smsalertnumber set (bug 11208)' ); +isnt($messages->[0]->{updated_on}, $messages->[0]->{time_queued}, 'Time status changed differs from time queued when status changes' ); +is($messages->[0]->{time_queued}, $message_time_queued, 'Time queued remaines inmutable' ); # ResendMessage my $resent = C4::Letters::ResendMessage($messages->[0]->{message_id}); -- 2.39.5