Bugzilla – Attachment 42932 Details for
Bug 8483
Borrower reading history should include deleted items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 8483 - Borrower reading history should include deleted items
Bug-8483---Borrower-reading-history-should-include.patch (text/plain), 9.25 KB, created by
Kyle M Hall (khall)
on 2015-09-28 16:05:50 UTC
(
hide
)
Description:
Bug 8483 - Borrower reading history should include deleted items
Filename:
MIME Type:
Creator:
Kyle M Hall (khall)
Created:
2015-09-28 16:05:50 UTC
Size:
9.25 KB
patch
obsolete
>From 803c98bb10ce622b781a6f5c850a122997e5c9d4 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >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) Verify old checkouts for deleted items show in reading history >--- > C4/Members.pm | 55 ++++++++++++-------- > Koha/Borrower.pm | 55 ++++++++++++++++++++ > Koha/Object.pm | 12 ++++ > Koha/Objects.pm | 14 +++++ > installer/data/mysql/atomicupdate/bug_8483.sql | 2 + > installer/data/mysql/kohastructure.sql | 4 +- > .../prog/en/modules/members/readingrec.tt | 8 +++- > 7 files changed, 125 insertions(+), 25 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_8483.sql > >diff --git a/C4/Members.pm b/C4/Members.pm >index 0b8e7d7..0770451 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -42,6 +42,8 @@ use Text::Unaccent qw( unac_string ); > use Koha::AuthUtils qw(hash_password); > use Koha::Database; > use Module::Load; >+use Koha::Borrowers; >+ > if ( C4::Context->preference('NorwegianPatronDBEnable') && C4::Context->preference('NorwegianPatronDBEnable') == 1 ) { > load Koha::NorwegianPatronDB, qw( NLUpdateHashedPIN NLEncryptPIN NLSync ); > } >@@ -1122,31 +1124,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::Borrowers->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/Borrower.pm b/Koha/Borrower.pm >index 93426bf..a210dc1 100644 >--- a/Koha/Borrower.pm >+++ b/Koha/Borrower.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,6 +38,58 @@ Koha::Borrower - Koha Borrower Object class > > =cut > >+=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/Koha/Object.pm b/Koha/Object.pm >index a77eb5c..504872c 100644 >--- a/Koha/Object.pm >+++ b/Koha/Object.pm >@@ -266,6 +266,18 @@ sub AUTOLOAD { > return; > } > >+=head3 $object->unblessed(); >+ >+Returns an unblessed representation of object. >+ >+=cut >+ >+sub unblessed { >+ my ($self) = @_; >+ >+ return { $self->_result->get_columns }; >+} >+ > =head3 type > > This method must be defined in the child class. The value is the name of the DBIC resultset. >diff --git a/Koha/Objects.pm b/Koha/Objects.pm >index 8ef6390..f6add21 100644 >--- a/Koha/Objects.pm >+++ b/Koha/Objects.pm >@@ -195,6 +195,20 @@ sub _wrap { > return @objects; > } > >+=head3 Koha::Objects->unblessed >+ >+Returns an unblessed representation of objects. >+ >+=cut >+ >+sub unblessed { >+ my ($self) = @_; >+ >+ return [ map { $_->unblessed } $self->as_list ]; >+} >+ >+ >+ > =head3 Koha::Objects->_resultset > > Returns the internal resultset or creates it if undefined >diff --git a/installer/data/mysql/atomicupdate/bug_8483.sql b/installer/data/mysql/atomicupdate/bug_8483.sql >new file mode 100644 >index 0000000..408e844 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_8483.sql >@@ -0,0 +1,2 @@ >+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 dab7538..deb78b4 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -1164,7 +1164,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; > > -- >@@ -1640,8 +1640,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 6fb109e..b6929c6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/readingrec.tt >@@ -94,7 +94,13 @@ > <td> > <span title="[% issue.issuestimestamp %]">[% issue.issuestimestamp | $KohaDates with_hours => 1 %]</span> > </td> >- <td><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% issue.biblionumber %]">[% issue.title |html %]</a></td> >+ <td> >+ [% IF issue.record_is_deleted %] >+ [% issue.title |html %] >+ [% ELSE %] >+ <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% issue.biblionumber %]">[% issue.title |html %]</a> >+ [% END %] >+ </td> > > <td>[% issue.author %]</td> > >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 8483
:
41013
|
41014
|
41015
|
41016
|
41017
|
41999
|
42000
|
42001
|
42787
|
42788
|
42789
|
42932
|
42935
|
42939
|
42940
|
42941
|
49129
|
49130
|
49131
|
49134
|
49135
|
49136
|
49137
|
49139
|
49140
|
49141
|
49142
|
49143
|
49144
|
49145