From bfdd5150c1e01f7167bb1702cebba218dfeec38e Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 8 Jan 2018 12:32:55 -0300 Subject: [PATCH] Bug 19935: Replace GetPendingIssues - Remove the residue Here we are, no more occurrences of GetPendingIssues, we can remove the tests and subroutine \o/ Signed-off-by: Benjamin Rokseth Signed-off-by: Josef Moravec Signed-off-by: Jonathan Druart --- C4/Members.pm | 89 +-------------- t/db_dependent/Members/GetPendingIssues.t | 130 ---------------------- 2 files changed, 1 insertion(+), 218 deletions(-) delete mode 100644 t/db_dependent/Members/GetPendingIssues.t diff --git a/C4/Members.pm b/C4/Members.pm index 0862f51754..da5ed59e50 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -63,7 +63,6 @@ BEGIN { #Get data push @EXPORT, qw( - &GetPendingIssues &GetAllIssues &GetBorrowersToExpunge @@ -572,92 +571,6 @@ sub fixup_cardnumber { return $result + 1; } -=head2 GetPendingIssues - - my $issues = &GetPendingIssues(@borrowernumber); - -Looks up what the patron with the given borrowernumber has borrowed. - -C<&GetPendingIssues> returns a -reference-to-array where each element is a reference-to-hash; the -keys are the fields from the C, C, and C tables. -The keys include C fields. - -=cut - -sub GetPendingIssues { - my @borrowernumbers = @_; - - unless (@borrowernumbers ) { # return a ref_to_array - return \@borrowernumbers; # to not cause surprise to caller - } - - # Borrowers part of the query - my $bquery = ''; - for (my $i = 0; $i < @borrowernumbers; $i++) { - $bquery .= ' issues.borrowernumber = ?'; - if ($i < $#borrowernumbers ) { - $bquery .= ' OR'; - } - } - - # FIXME: namespace collision: each table has "timestamp" fields. Which one is "timestamp" ? - # FIXME: circ/ciculation.pl tries to sort by timestamp! - # FIXME: namespace collision: other collisions possible. - # FIXME: most of this data isn't really being used by callers. - my $query = - "SELECT issues.*, - items.*, - biblio.*, - biblioitems.volume, - biblioitems.number, - biblioitems.itemtype, - biblioitems.isbn, - biblioitems.issn, - biblioitems.publicationyear, - biblioitems.publishercode, - biblioitems.volumedate, - biblioitems.volumedesc, - biblioitems.lccn, - biblioitems.url, - borrowers.firstname, - borrowers.surname, - borrowers.cardnumber, - issues.timestamp AS timestamp, - issues.renewals AS renewals, - issues.borrowernumber AS borrowernumber, - items.renewals AS totalrenewals - FROM issues - LEFT JOIN items ON items.itemnumber = issues.itemnumber - LEFT JOIN biblio ON items.biblionumber = biblio.biblionumber - LEFT JOIN biblioitems ON items.biblioitemnumber = biblioitems.biblioitemnumber - LEFT JOIN borrowers ON issues.borrowernumber = borrowers.borrowernumber - WHERE - $bquery - ORDER BY issues.issuedate" - ; - - my $sth = C4::Context->dbh->prepare($query); - $sth->execute(@borrowernumbers); - my $data = $sth->fetchall_arrayref({}); - my $today = dt_from_string; - foreach (@{$data}) { - if ($_->{issuedate}) { - $_->{issuedate} = dt_from_string($_->{issuedate}, 'sql'); - } - $_->{date_due_sql} = $_->{date_due}; - # FIXME no need to have this value - $_->{date_due} or next; - $_->{date_due_sql} = $_->{date_due}; - # FIXME no need to have this value - $_->{date_due} = dt_from_string($_->{date_due}, 'sql'); - if ( DateTime->compare($_->{date_due}, $today) == -1 ) { - $_->{overdue} = 1; - } - } - return $data; -} - =head2 GetAllIssues $issues = &GetAllIssues($borrowernumber, $sortkey, $limit); @@ -911,7 +824,7 @@ sub GetBorrowersToExpunge { <> - NOTE: Not all table fields are available, pleasee see GetPendingIssues for a list of available fields. + NOTE: Fields from tables issues, items, biblio and biblioitems are available =cut diff --git a/t/db_dependent/Members/GetPendingIssues.t b/t/db_dependent/Members/GetPendingIssues.t deleted file mode 100644 index 56e06965b0..0000000000 --- a/t/db_dependent/Members/GetPendingIssues.t +++ /dev/null @@ -1,130 +0,0 @@ -#!/usr/bin/perl - -# 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 . - -use Modern::Perl; - -use Test::More tests => 20; -use Test::MockModule; - -use t::lib::TestBuilder; - -use C4::Biblio; -use C4::Items; -use C4::Members; -use C4::Circulation; -use Koha::Library; -use Koha::Patrons; -use MARC::Record; - -my $schema = Koha::Database->schema; -my $dbh = C4::Context->dbh; -$schema->storage->txn_begin; - -my $builder = t::lib::TestBuilder->new; - -$dbh->do(q|DELETE FROM issues|); -$dbh->do(q|DELETE FROM borrowers|); -$dbh->do(q|DELETE FROM items|); -$dbh->do(q|DELETE FROM branches|); -$dbh->do(q|DELETE FROM biblio|); -$dbh->do(q|DELETE FROM categories|); - -my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; -my $categorycode = $builder->build( { source => 'Category' } )->{categorycode}; -my $itemtype = $builder->build( { source => 'Itemtype' } )->{itemtype}; - -my %item_infos = ( - homebranch => $branchcode, - holdingbranch => $branchcode, - itype => $itemtype -); - - -my ($biblionumber1) = AddBiblio( MARC::Record->new, '' ); -my $itemnumber1 = - AddItem( { barcode => '0101', %item_infos }, $biblionumber1 ); -my $itemnumber2 = - AddItem( { barcode => '0102', %item_infos }, $biblionumber1 ); - -my ($biblionumber2) = AddBiblio( MARC::Record->new, '' ); -my $itemnumber3 = - AddItem( { barcode => '0203', %item_infos }, $biblionumber2 ); - -my $borrowernumber1 = - AddMember( categorycode => $categorycode, branchcode => $branchcode ); -my $borrowernumber2 = - AddMember( categorycode => $categorycode, branchcode => $branchcode ); -my $borrower1 = Koha::Patrons->find( $borrowernumber1 )->unblessed; -my $borrower2 = Koha::Patrons->find( $borrowernumber2 )->unblessed; - -my $module = new Test::MockModule('C4::Context'); -$module->mock( 'userenv', sub { { branch => $branchcode } } ); - -my $issues = - C4::Members::GetPendingIssues( $borrowernumber1, $borrowernumber2 ); -is( @$issues, 0, 'GetPendingIssues returns the correct number of elements' ); - -AddIssue( $borrower1, '0101' ); -$issues = C4::Members::GetPendingIssues($borrowernumber1); -is( @$issues, 1, 'GetPendingIssues returns the correct number of elements' ); -is( $issues->[0]->{itemnumber}, - $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' ); -my $issues_bis = - C4::Members::GetPendingIssues( $borrowernumber1, $borrowernumber2 ); -is_deeply( $issues, $issues_bis, 'GetPendingIssues functions correctly' ); -$issues = C4::Members::GetPendingIssues($borrowernumber2); -is( @$issues, 0, 'GetPendingIssues returns the correct number of elements' ); - -AddIssue( $borrower1, '0102' ); -$issues = C4::Members::GetPendingIssues($borrowernumber1); -is( @$issues, 2, 'GetPendingIssues returns the correct number of elements' ); -is( $issues->[0]->{itemnumber}, - $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' ); -is( $issues->[1]->{itemnumber}, - $itemnumber2, 'GetPendingIssues returns the itemnumber correctly' ); -$issues_bis = - C4::Members::GetPendingIssues( $borrowernumber1, $borrowernumber2 ); -is_deeply( $issues, $issues_bis, 'GetPendingIssues functions correctly' ); -$issues = C4::Members::GetPendingIssues($borrowernumber2); -is( @$issues, 0, 'GetPendingIssues returns the correct number of elements' ); - -AddIssue( $borrower2, '0203' ); -$issues = C4::Members::GetPendingIssues($borrowernumber2); -is( @$issues, 1, 'GetAllIssues returns the correct number of elements' ); -is( $issues->[0]->{itemnumber}, - $itemnumber3, 'GetPendingIssues returns the itemnumber correctly' ); -$issues = C4::Members::GetPendingIssues($borrowernumber1); -is( @$issues, 2, 'GetPendingIssues returns the correct number of elements' ); -is( $issues->[0]->{itemnumber}, - $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' ); -is( $issues->[1]->{itemnumber}, - $itemnumber2, 'GetPendingIssues returns the itemnumber correctly' ); -$issues = C4::Members::GetPendingIssues( $borrowernumber1, $borrowernumber2 ); -is( @$issues, 3, 'GetPendingIssues returns the correct number of elements' ); -is( $issues->[0]->{itemnumber}, - $itemnumber1, 'GetPendingIssues returns the itemnumber correctly' ); -is( $issues->[1]->{itemnumber}, - $itemnumber2, 'GetPendingIssues returns the itemnumber correctly' ); -is( $issues->[2]->{itemnumber}, - $itemnumber3, 'GetPendingIssues returns the itemnumber correctly' ); - -$issues = C4::Members::GetPendingIssues(); -is( @$issues, 0, - 'GetPendingIssues without borrower numbers returns an empty array' ); - -$schema->storage->txn_begin; - -- 2.39.5