Koha/svc/holds
Julian Maurice b168f4a2e9 Bug 21395: Make perlcritic happy
This patch adds a .perlcriticrc (copied from qa-test-tools) and fixes
almost all perlcrictic violations according to this .perlcriticrc
The remaining violations are silenced out by appending a '## no critic'
to the offending lines. They can still be seen by using the --force
option of perlcritic
This patch also modify t/00-testcritic.t to check all Perl files using
the new .perlcriticrc.
I'm not sure if this test script is still useful as it is now equivalent
to `perlcritic --quiet .` and it looks like it is much slower
(approximatively 5 times slower on my machine)

Test plan:
1. Run `perlcritic --quiet .` from the root directory. It should output
   nothing
2. Run `perlcritic --quiet --force .`. It should output 7 errors (6
   StringyEval, 1 BarewordFileHandles)
3. Run `TEST_QA=1 prove t/00-testcritic.t`
4. Read the patch. Check that all changes make sense and do not
   introduce undesired behaviour

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2020-06-29 12:37:02 +02:00

159 lines
5.3 KiB
Perl
Executable file

#!/usr/bin/perl
# Copyright 2014 ByWater Solutions
#
# 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 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.
#
# You should have received a copy of the GNU General Public License
# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
use CGI;
use JSON qw(to_json);
use C4::Auth qw(check_cookie_auth);
use C4::Charset;
use C4::Circulation qw(GetTransfers);
use C4::Context;
use Koha::DateUtils;
use Koha::Holds;
use Koha::ItemTypes;
use Koha::Libraries;
my $input = new CGI;
my ( $auth_status, $sessionID ) =
check_cookie_auth( $input->cookie('CGISESSID'),
{ circulate => 'circulate_remaining_permissions' } );
if ( $auth_status ne "ok" ) {
exit 0;
}
my $branch = C4::Context->userenv->{'branch'};
my $schema = Koha::Database->new()->schema();
my @sort_columns =
qw/reservedate title itemcallnumber barcode expirationdate priority/;
my $borrowernumber = $input->param('borrowernumber');
my $offset = $input->param('iDisplayStart');
my $results_per_page = $input->param('iDisplayLength');
my $sorting_direction = $input->param('sSortDir_0') || 'desc';
my $iSortCol = $input->param('iSortCol_0') // 0;
my $sorting_column = $sort_columns[$iSortCol] // 'reservedate';
binmode STDOUT, ":encoding(UTF-8)";
print $input->header( -type => 'text/plain', -charset => 'UTF-8' );
my $holds_rs = Koha::Holds->search(
{ borrowernumber => $borrowernumber },
{
order_by => { "-$sorting_direction" => $sorting_column }
}
);
my @holds;
while ( my $h = $holds_rs->next() ) {
my $item = $h->item();
my $biblionumber = $h->biblio()->biblionumber();
my $itemtype_limit;
if ( $h->itemtype ) {
my $itemtype = Koha::ItemTypes->find( $h->itemtype );
$itemtype_limit = $itemtype->translated_description;
}
my $libraries = Koha::Libraries->search({}, { order_by => ['branchname'] })->unblessed;
for my $library ( @$libraries ) {
$library->{selected} = 1 if $library->{branchcode} eq $h->branchcode();
}
my $biblio = $h->biblio();
my @subtitles = split(/ \| /, $biblio->subtitle() // '');
my $hold = {
DT_RowId => $h->reserve_id(),
biblionumber => $biblionumber,
title => $biblio->title(),
subtitle => \@subtitles,
medium => $biblio->medium() // '',
part_number => $biblio->part_number() // '',
part_name => $biblio->part_name() // '',
author => $biblio->author(),
reserve_id => $h->reserve_id(),
branchcode => $h->branch()->branchname(),
branches => $libraries,
reservedate => $h->reservedate(),
expirationdate => $h->expirationdate(),
suspend => $h->suspend(),
suspend_until => $h->suspend_until(),
found => $h->found(),
waiting => $h->is_waiting(),
waiting_at => $h->branch()->branchname(),
waiting_here => $h->branch()->branchcode() eq $branch,
priority => $h->priority(),
itemtype_limit => $itemtype_limit,
reservedate_formatted => $h->reservedate() ? output_pref(
{ dt => dt_from_string( $h->reservedate() ), dateonly => 1 }
)
: q{},
suspend_until_formatted => $h->suspend_until() ? output_pref(
{ dt => dt_from_string( $h->suspend_until() ), dateonly => 1 }
)
: q{},
expirationdate_formatted => $h->expirationdate() ? output_pref(
{ dt => dt_from_string( $h->expirationdate() ), dateonly => 1 }
)
: q{},
};
$hold->{transfered} = 0;
$hold->{not_transfered} = 0;
if ($item) {
$hold->{itemnumber} = $item->itemnumber();
$hold->{barcode} = $item->barcode();
$hold->{itemtype} = $item->effective_itemtype();
$hold->{enumchron} = $item->enumchron();
$hold->{itemcallnumber} = $item->itemcallnumber() || q{};
my ( $transferred_when, $transferred_from, $transferred_to ) =
GetTransfers( $item->itemnumber() );
if ($transferred_when) {
$hold->{color} = 'transferred';
$hold->{transferred} = 1;
$hold->{date_sent} = output_pref( dt_from_string($transferred_when) );
$hold->{from_branch} = Koha::Libraries->find($transferred_from)->branchname;
}
elsif ( $item->holding_branch() && $item->holding_branch()->branchcode() ne
$h->branch()->branchcode() )
{
$hold->{not_transferred} = 1;
$hold->{not_transferred_by} = $h->item()->holding_branch()->branchname();
}
}
push( @holds, $hold );
}
my $data;
$data->{'iTotalRecords'} = scalar @holds;
$data->{'iTotalDisplayRecords'} = scalar @holds;
$data->{'sEcho'} = $input->param('sEcho') || undef;
$data->{'aaData'} = \@holds;
print to_json($data);