From bd375631fcc0495661260df21bd32085a7bd387e Mon Sep 17 00:00:00 2001 From: Indranil Das Gupta Date: Fri, 22 May 2015 03:49:10 +0530 Subject: [PATCH] Bug 14206: Adds delete function for non email templates MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit C4::Letters::getletter() is called in tools/letter.pl by the function delete_confirm() to display the selected notice for deletion. Due to current implementation of getletter(), a notice that does not use the 'email' template (but uses any/all of the other templates - sms, print or phone) can't be deleted from the staff client. This patch adds deletion capability for notices that do not use email template, but uses any/all of the other templates i.e. sms, print or phone. This also adds 2 tests to t/db_dependent/Letters.t for testing both conditions - a) when message_transport_type is specified b) when it is not. Test plan ========= 1/ Go to Tools -> Notices & Slips. Add a new notice only for print, leave 'Library' and 'Koha module' options as default selections. Enter 'KOHA_14206' and 'Koha Test 14206' against Code and Name respectively, and 'Test' and 'Test Message' for subject and body. Leave the Email, Phone and SMS tabs blank. Save the notice. 2/ On the notices listing page the new notice will be listed. Try to delete it. It will load the 'Delete notice' dialog form, but the table will not show any data under s - 'Library', 'Module', 'Code' or 'Name'. 3/ Click the "Yes, delete" button. The page will be submitted and the Notices listing reloaded. The print-only KOHA_14206 notice should continue to exist. This is *wrong*. 4/ Apply this patch 5/ Reload the listings page and click on the 'Delete' link for Notice KOHA_14206. This time, it should show the data under 'Module', 'Code' or 'Name' at least. 6/ Click on 'Yes, delete'. The page should submit and the listing page reload. This time KOHA_14206 will be gone. 7/ Run prove -v t/db_dependent/Letters.t All tests should PASS without any error. Followed test plan. Works as expected. Signed-off-by: Marc Véron Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 8895caa33985bbb0cad9b011c4706d4591d2869b) Signed-off-by: Chris Cormack Signed-off-by: Liz Rea --- C4/Letters.pm | 7 ++++--- t/db_dependent/Letters.t | 8 +++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/C4/Letters.pm b/C4/Letters.pm index 0faa91e908..5b4d27bcb6 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -207,8 +207,7 @@ sub GetLettersAvailableForALibrary { our %letter; sub getletter { my ( $module, $code, $branchcode, $message_transport_type ) = @_; - $message_transport_type ||= 'email'; - + $message_transport_type //= '%'; if ( C4::Context->preference('IndependentBranches') and $branchcode @@ -226,7 +225,8 @@ sub getletter { my $sth = $dbh->prepare(q{ SELECT * FROM letter - WHERE module=? AND code=? AND (branchcode = ? OR branchcode = '') AND message_transport_type = ? + WHERE module=? AND code=? AND (branchcode = ? OR branchcode = '') + AND message_transport_type LIKE ? ORDER BY branchcode DESC LIMIT 1 }); $sth->execute( $module, $code, $branchcode, $message_transport_type ); @@ -237,6 +237,7 @@ sub getletter { return { %$line }; } + =head2 DelLetter DelLetter( diff --git a/t/db_dependent/Letters.t b/t/db_dependent/Letters.t index 016c213ef4..efc0bd579f 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 => 58; +use Test::More tests => 60; use Test::MockModule; use Test::Warn; @@ -172,6 +172,12 @@ is( $letter->{title}, $title, 'GetLetters gets the title correctly' ); is( $letter->{content}, $content, 'GetLetters gets the content correctly' ); is( $letter->{message_transport_type}, 'email', 'GetLetters gets the message type correctly' ); +# Regression test for Bug 14206 +$dbh->do( q|INSERT INTO letter(branchcode,module,code,name,is_html,title,content,message_transport_type) VALUES ('FFL','my module','my code','my name',1,?,?,'print')|, undef, $title, $content ); +my $letter14206_a = C4::Letters::getletter('my module', 'my code', 'FFL' ); +is( $letter14206_a->{message_transport_type}, 'print', 'Bug 14206 - message_transport_type not passed, correct mtt detected' ); +my $letter14206_b = C4::Letters::getletter('my module', 'my code', 'FFL', 'print'); +is( $letter14206_b->{message_transport_type}, 'print', 'Bug 14206 - message_transport_type passed, correct mtt detected' ); # addalert my $type = 'my type'; -- 2.39.5