Bug 19943: Gentle error handling for bookcount.pl
authorTomas Cohen Arazi <tomascohen@theke.io>
Fri, 9 Mar 2018 13:51:53 +0000 (10:51 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 23 Mar 2018 15:32:05 +0000 (12:32 -0300)
This patch tests the required parameters and redirects with a 400 HTTP
code if parameters are invalid.

It also removes the need for the passed biblioitemnumber which is not
used at all.

A (now) useless sub is removed too.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
circ/bookcount.pl
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt

index 3d20aac..438d851 100755 (executable)
@@ -34,12 +34,14 @@ use Koha::Libraries;
 
 my $input        = new CGI;
 my $itm          = $input->param('itm');
-my $bi           = $input->param('bi');
 my $biblionumber = $input->param('biblionumber');
 
-my $idata = itemdatanum($itm);
 my $biblio = Koha::Biblios->find( $biblionumber );
-die "No valid biblionumber passed" unless $biblio; # FIXME A bit rude!
+my $item   = Koha::Items->find( $itm );
+
+if ( !defined $biblio or !defined $item ) {
+    print $input->redirect("/cgi-bin/koha/errors/400.pl");
+}
 
 my $lastmove = lastmove($itm);
 
@@ -76,10 +78,9 @@ $template->param(
     biblionumber            => $biblionumber,
     title                   => $biblio->title,
     author                  => $biblio->author,
-    barcode                 => $idata->{'barcode'},
-    biblioitemnumber        => $bi,
-    homebranch              => $idata->{homebranch},
-    holdingbranch           => $idata->{holdingbranch},
+    barcode                 => $item->barcode,
+    homebranch              => $item->homebranch,
+    holdingbranch           => $item->holdingbranch,
     lastdate                => $lastdate ? $lastdate : 0,
     count                   => $count,
     libraries               => $libraries,
@@ -88,13 +89,6 @@ $template->param(
 output_html_with_http_headers $input, $cookie, $template->output;
 exit;
 
-sub itemdatanum {
-    my ($itemnumber) = @_;
-    my $sth = C4::Context->dbh->prepare("SELECT * FROM items WHERE itemnumber=?");
-    $sth->execute($itemnumber);
-    return $sth->fetchrow_hashref;
-}
-
 sub lastmove {
     my ($itemnumber) = @_;
     my $dbh = C4::Context->dbh;
index 3fb7856..ad8aefb 100644 (file)
                 </li>
             [% END %]
 
-                <li><span class="label">Total checkouts:</span>[% IF ( ITEM_DAT.issues ) %][% ITEM_DAT.issues %][% ELSE %]0[% END %]  (<a href="/cgi-bin/koha/circ/bookcount.pl?&amp;biblionumber=[% ITEM_DAT.biblionumber %]&amp;bi=[% ITEM_DAT.biblioitemnumber %]&amp;itm=[% ITEM_DAT.itemnumber %]">View item's checkout history</a>)</li>
+                <li><span class="label">Total checkouts:</span>[% IF ( ITEM_DAT.issues ) %][% ITEM_DAT.issues %][% ELSE %]0[% END %]  (<a href="/cgi-bin/koha/circ/bookcount.pl?&amp;biblionumber=[% ITEM_DAT.biblionumber %]&amp;itm=[% ITEM_DAT.itemnumber %]">View item's checkout history</a>)</li>
 
                 <li><span class="label">Last seen:</span>[% IF ( ITEM_DAT.datelastseen ) %][% ITEM_DAT.datelastseen | $KohaDates %] [%END %]&nbsp;</li>
                 <li><span class="label">Last borrowed:</span>[% IF (ITEM_DAT.datelastborrowed ) %][% ITEM_DAT.datelastborrowed | $KohaDates %][% END %]&nbsp;</li>