From 36bc64347ff361094f57c4076a9e648c3f28382d Mon Sep 17 00:00:00 2001 From: Aleisha Date: Wed, 24 Jun 2015 01:15:32 +0000 Subject: [PATCH] Bug 14445: Silences warn in letter.pl When changing Koha module to 'Circulation', there is a warn saying that $code is uninitialized. This patch sets $code to an empty string to silence the warn. To test: 1) Go to Tools, the Notices & Slips 2) Click 'new notice' (This will trigger warns, but ignore these as they will be corrected in the next patch) 3) Change Koha module to 'Circulation' 4) Notice warn about uninitialized $code variable 5) Apply patch and reload page, change Koha module to 'Circulation' 6) Notice page still works and warns are gone --- tools/letter.pl | 97 ++++++++++++++++++++++++------------------------------- 1 file changed, 42 insertions(+), 55 deletions(-) diff --git a/tools/letter.pl b/tools/letter.pl index 82c6f87..2e6b4c2 100755 --- a/tools/letter.pl +++ b/tools/letter.pl @@ -4,18 +4,18 @@ # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along -# with Koha; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . =head1 tools/letter.pl @@ -42,7 +42,7 @@ use strict; use warnings; -use CGI; +use CGI qw ( -utf8 ); use C4::Auth; use C4::Context; use C4::Output; @@ -50,34 +50,6 @@ use C4::Branch; # GetBranches use C4::Letters; use C4::Members::Attributes; -# _letter_from_where($branchcode,$module, $code, $mtt) -# - return FROM WHERE clause and bind args for a letter -sub _letter_from_where { - my ($branchcode, $module, $code, $mtt) = @_; - my $sql = q{FROM letter WHERE branchcode = ? AND module = ? AND code = ?}; - $sql .= q{ AND message_transport_type = ?} if $mtt ne '*'; - my @args = ( $branchcode || '', $module, $code, ($mtt ne '*' ? $mtt : ()) ); -# Mysql is retarded. cause branchcode is part of the primary key it cannot be null. How does that -# work with foreign key constraint I wonder... - -# if ($branchcode) { -# $sql .= " AND branchcode = ?"; -# push @args, $branchcode; -# } else { -# $sql .= " AND branchcode IS NULL"; -# } - - return ($sql, \@args); -} - -# get_letters($branchcode,$module, $code, $mtt) -# - return letters with the given $branchcode, $module, $code and $mtt exists -sub get_letters { - my ($sql, $args) = _letter_from_where(@_); - my $dbh = C4::Context->dbh; - my $letter = $dbh->selectall_hashref("SELECT * $sql", 'message_transport_type', undef, @$args); - return $letter; -} # $protected_letters = protected_letters() # - return a hashref of letter_codes representing letters that should never be deleted sub protected_letters { @@ -127,13 +99,11 @@ if ( $op eq 'add_validate' or $op eq 'copy_validate' ) { if ($op eq 'copy_form') { my $oldbranchcode = $input->param('oldbranchcode') || q||; my $branchcode = $input->param('branchcode') || q||; - my $oldcode = $input->param('oldcode') || $input->param('code'); add_form($oldbranchcode, $module, $code); $template->param( oldbranchcode => $oldbranchcode, branchcode => $branchcode, branchloop => _branchloop($branchcode), - oldcode => $oldcode, copying => 1, modify => 0, ); @@ -145,8 +115,7 @@ elsif ( $op eq 'delete_confirm' ) { delete_confirm($branchcode, $module, $code); } elsif ( $op eq 'delete_confirmed' ) { - my $mtt = $input->param('message_transport_type'); - delete_confirmed($branchcode, $module, $code, $mtt); + delete_confirmed($branchcode, $module, $code); $op = q{}; # next operation is to return to default screen } else { @@ -168,7 +137,13 @@ sub add_form { my $letters; # if code has been passed we can identify letter and its an update action if ($code) { - $letters = get_letters($branchcode,$module, $code, '*'); + $letters = C4::Letters::GetLetterTemplates( + { + branchcode => $branchcode, + module => $module, + code => $code, + } + ); } my $message_transport_types = GetMessageTransportTypes(); @@ -218,9 +193,13 @@ sub add_form { my $field_selection; push @{$field_selection}, add_fields('branches'); + $code //= ''; if ($module eq 'reserves') { push @{$field_selection}, add_fields('borrowers', 'reserves', 'biblio', 'items'); } + elsif ( $module eq 'acquisition' ) { + push @{$field_selection}, add_fields('aqbooksellers', 'aqorders', 'biblio', 'items'); + } elsif ($module eq 'claimacquisition') { push @{$field_selection}, add_fields('aqbooksellers', 'aqorders', 'biblio', 'biblioitems'); } @@ -278,12 +257,19 @@ sub add_validate { my $is_html = $input->param("is_html_$mtt"); my $title = shift @title; my $content = shift @content; - my $letter = get_letters($branchcode,$oldmodule, $code, $mtt); + my $letter = C4::Letters::getletter( $oldmodule, $code, $branchcode, $mtt); + + # getletter can return the default letter even if we pass a branchcode + # If we got the default one and we needed the specific one, we didn't get the one we needed! + if ( $letter and $branchcode ne $letter->{branchcode} ) { + $letter = undef; + } unless ( $title and $content ) { + # Delete this mtt if no title or content given delete_confirmed( $branchcode, $oldmodule, $code, $mtt ); next; } - elsif ( exists $letter->{$mtt} ) { + elsif ( $letter and $letter->{message_transport_type} eq $mtt ) { $dbh->do( q{ UPDATE letter @@ -310,23 +296,24 @@ sub add_validate { sub delete_confirm { my ($branchcode, $module, $code) = @_; my $dbh = C4::Context->dbh; - my $letter = get_letters($branchcode, $module, $code, '*'); + my $letter = C4::Letters::getletter($module, $code, $branchcode); my @values = values %$letter; $template->param( - branchcode => $branchcode, - branchname => GetBranchName($branchcode), - code => $code, - module => $module, - name => $values[0]->{name}, + letter => $letter, ); return; } sub delete_confirmed { my ($branchcode, $module, $code, $mtt) = @_; - my ($sql, $args) = _letter_from_where($branchcode, $module, $code, $mtt); - my $dbh = C4::Context->dbh; - $dbh->do("DELETE $sql", undef, @$args); + C4::Letters::DelLetter( + { + branchcode => $branchcode, + module => $module, + code => $code, + mtt => $mtt + } + ); # setup default display for screen default_display($branchcode); return; -- 1.7.10.4