From 021eda0156e84c5a3058ae3071049a51ca3bc0ac Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 16 Jul 2015 07:58:26 -0400 Subject: [PATCH] Bug 8483 - Borrower reading history should include deleted items When showing a borrower's reading history, it'd be good to be able to include the deleted items also, as we have that information available. Test Plan: 1) Apply this patch 2) prove t/db_dependent/Members/GetAllIssues.t 3) Check out and return an item for a patron 4) Delete that item 5) Verify the record still shows in the patron's reading history 6) Delete the record entirely 7) Verify the record still shows in the patron's reading history, but that the title is now just text instead of a hyperlink. Signed-off-by: Heather Braum --- C4/Members.pm | 54 +++++++++++++--------- Koha/BiblioItem.pm | 8 ++++ Koha/Config/SysPref.pm | 5 +- Koha/Patron.pm | 52 +++++++++++++++++++++ installer/data/mysql/atomicupdate/bug_8483.sql | 1 + installer/data/mysql/kohastructure.sql | 4 +- .../prog/en/modules/members/readingrec.tt | 8 +++- 7 files changed, 106 insertions(+), 26 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_8483.sql diff --git a/C4/Members.pm b/C4/Members.pm index ac64477..b62a33e 100644 --- a/C4/Members.pm +++ b/C4/Members.pm @@ -36,6 +36,7 @@ use C4::NewsChannels; #get slip news use DateTime; use Koha::Database; use Koha::DateUtils; +use Koha::Patrons; use Koha::Patron::Debarments qw(IsDebarred); use Text::Unaccent qw( unac_string ); use Koha::AuthUtils qw(hash_password); @@ -998,31 +999,42 @@ sub GetAllIssues { my ( $borrowernumber, $order, $limit ) = @_; return unless $borrowernumber; + $order = 'date_due desc' unless $order; + my ( $column, $sort ) = split( / /, $order ); + $column ||= 'date_due'; + $sort ||= 'desc'; - my $dbh = C4::Context->dbh; - my $query = -'SELECT *, issues.timestamp as issuestimestamp, issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp - 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 - WHERE borrowernumber=? - UNION ALL - SELECT *, old_issues.timestamp as issuestimestamp, old_issues.renewals AS renewals,items.renewals AS totalrenewals,items.timestamp AS itemstimestamp - FROM old_issues - LEFT JOIN items on items.itemnumber=old_issues.itemnumber - LEFT JOIN biblio ON items.biblionumber=biblio.biblionumber - LEFT JOIN biblioitems ON items.biblioitemnumber=biblioitems.biblioitemnumber - WHERE borrowernumber=? AND old_issues.itemnumber IS NOT NULL - order by ' . $order; - if ($limit) { - $query .= " limit $limit"; + my $borrower = Koha::Patrons->find( $borrowernumber ); + my $checkouts = $borrower->all_checkouts( { order => { column => $column, sort => $sort } , limit => $limit } ); + + my @results; + foreach my $checkout (@$checkouts) { + my $item = $checkout->item( { deleted => 1 } ); + next unless $item; + + my $biblio = $item->biblio( { deleted => 1 } ); + next unless $biblio; + + my $biblioitem = $item->biblioitem( { deleted => 1 } ); + next unless $biblioitem; + + my $checkout_hashref = $checkout->unblessed(); + my $item_hashref = $item->unblessed(); + my $biblio_hashref = $biblio->unblessed(); + my $biblioitem_hashref = $biblioitem->unblessed(); + + my $hashref = { %$checkout_hashref, %$item_hashref, %$biblio_hashref, %$biblioitem_hashref }; + $hashref->{issuestimestamp} = $checkout->timestamp(); + $hashref->{renewals} = $checkout->renewals(); + $hashref->{totalrenewals} = $item->renewals(); + $hashref->{itemstimestamp} = $item->timestamp(); + $hashref->{record_is_deleted} = ref($biblio) eq 'Koha::Deleted::Biblio'; + + push( @results, $hashref ); } - my $sth = $dbh->prepare($query); - $sth->execute( $borrowernumber, $borrowernumber ); - return $sth->fetchall_arrayref( {} ); + return \@results; } diff --git a/Koha/BiblioItem.pm b/Koha/BiblioItem.pm index 7186d46..35de0d4 100644 --- a/Koha/BiblioItem.pm +++ b/Koha/BiblioItem.pm @@ -1,5 +1,7 @@ package Koha::BiblioItem; +# Copyright ByWater Solutions 2015 +# # This file is part of Koha. # # Koha is free software; you can redistribute it and/or modify it under the @@ -41,4 +43,10 @@ sub _type { return 'Biblioitem'; } +=head1 AUTHOR + +Kyle M Hall + +=cut + 1; diff --git a/Koha/Config/SysPref.pm b/Koha/Config/SysPref.pm index e1850b5..4429b00 100644 --- a/Koha/Config/SysPref.pm +++ b/Koha/Config/SysPref.pm @@ -23,6 +23,9 @@ use Carp; use Koha::Database; +use Koha::Checkouts; +use Koha::Old::Checkouts; + use base qw(Koha::Object); =head1 NAME @@ -35,7 +38,7 @@ Koha::Config::SysPref - Koha System Preference Object class =cut -=head3 type +=head3 _type =cut diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 684f274..4f52fc3 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -94,6 +94,58 @@ sub siblings { ); } +=head3 all_checkouts + +=cut + +sub all_checkouts { + my ( $self, $params ) = @_; + + my $limit = $params->{limit}; + + my $order_by_column = $params->{order} ? $params->{order}->{column} : 'date_due'; + my $order_by_sort = $params->{order} ? $params->{order}->{sort} : 'desc'; + + my @results; + my $results_found = 0; + + my $issues = Koha::Checkouts->search( + { + borrowernumber => $self->borrowernumber(), + }, + { + order_by => { "-$order_by_sort" => $order_by_column } + } + ); + + while ( my $i = $issues->next() ) { + push( @results, $i ); + $results_found++; + last if ( $limit && $results_found >= $limit ); + } + + if ( !$limit || $results_found < $limit ) { + + $issues = Koha::Old::Checkouts->search( + { + borrowernumber => $self->borrowernumber(), + }, + { + order_by => { "-$order_by_sort" => $order_by_column } + } + ); + + while ( my $i = $issues->next() ) { + push( @results, $i ); + $results_found++; + last if ( $limit && $results_found >= $limit ); + } + + } + + return wantarray ? @results : \@results; +} + =head3 type =cut diff --git a/installer/data/mysql/atomicupdate/bug_8483.sql b/installer/data/mysql/atomicupdate/bug_8483.sql new file mode 100644 index 0000000..d706468 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_8483.sql @@ -0,0 +1 @@ +ALTER TABLE `old_issues` DROP FOREIGN KEY `old_issues_ibfk_2` ; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 63fefe7..4102888 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1176,7 +1176,7 @@ CREATE TABLE `issues` ( -- information related to check outs or issues KEY `branchcode_idx` (`branchcode`), KEY `bordate` (`borrowernumber`,`timestamp`), CONSTRAINT `issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE RESTRICT ON UPDATE CASCADE, - CONSTRAINT `issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE RESTRICT ON UPDATE CASCADE + CONSTRAINT `issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE RESTRICT ON UPDATE CASCADE, ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- @@ -1675,8 +1675,6 @@ CREATE TABLE `old_issues` ( -- lists items that were checked out and have been r KEY `branchcode_idx` (`branchcode`), KEY `old_bordate` (`borrowernumber`,`timestamp`), CONSTRAINT `old_issues_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) - ON DELETE SET NULL ON UPDATE SET NULL, - CONSTRAINT `old_issues_ibfk_2` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE SET NULL ON UPDATE SET NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt index 0f3bbe9..4eaf7b1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt @@ -97,7 +97,13 @@ [% issue.issuestimestamp | $KohaDates with_hours => 1 %] - [% issue.title |html %] + + [% IF issue.record_is_deleted %] + [% issue.title |html %] + [% ELSE %] + [% issue.title |html %] + [% END %] + [% issue.author %] -- 2.1.4