From bc33bf08a2dbef93a40fa96252ec2885db58560d Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Thu, 16 Jul 2015 07:47:32 -0400 Subject: [PATCH] Bug 8483 - Borrower reading history should include deleted items TODO: Break patch into smaller parts, add unit tests --- C4/Members.pm | 54 ++++++++----- Koha/Biblio.pm | 52 ++++++++++++ Koha/BiblioItem.pm | 52 ++++++++++++ Koha/BiblioItems.pm | 58 ++++++++++++++ Koha/Biblios.pm | 58 ++++++++++++++ Koha/Borrower.pm | 55 +++++++++++++ Koha/Checkout.pm | 76 ++++++++++++++++++ Koha/Checkouts.pm | 58 ++++++++++++++ Koha/Deleted/Biblio.pm | 57 ++++++++++++++ Koha/Deleted/BiblioItem.pm | 57 ++++++++++++++ Koha/Deleted/BiblioItems.pm | 63 +++++++++++++++ Koha/Deleted/Biblios.pm | 64 +++++++++++++++ Koha/Deleted/Item.pm | 58 ++++++++++++++ Koha/Deleted/Items.pm | 63 +++++++++++++++ Koha/Item.pm | 100 ++++++++++++++++++++++++ Koha/Items.pm | 58 ++++++++++++++ Koha/Object.pm | 12 +++ Koha/Objects.pm | 14 ++++ Koha/OldCheckout.pm | 57 ++++++++++++++ Koha/OldCheckouts.pm | 63 +++++++++++++++ installer/data/mysql/atomicupdate/bug_8483.sql | 1 + installer/data/mysql/kohastructure.sql | 2 +- opac/opac-readingrecord.pl | 1 + 23 files changed, 1111 insertions(+), 22 deletions(-) create mode 100644 Koha/Biblio.pm create mode 100644 Koha/BiblioItem.pm create mode 100644 Koha/BiblioItems.pm create mode 100644 Koha/Biblios.pm create mode 100644 Koha/Checkout.pm create mode 100644 Koha/Checkouts.pm create mode 100644 Koha/Deleted/Biblio.pm create mode 100644 Koha/Deleted/BiblioItem.pm create mode 100644 Koha/Deleted/BiblioItems.pm create mode 100644 Koha/Deleted/Biblios.pm create mode 100644 Koha/Deleted/Item.pm create mode 100644 Koha/Deleted/Items.pm create mode 100644 Koha/Item.pm create mode 100644 Koha/Items.pm create mode 100644 Koha/OldCheckout.pm create mode 100644 Koha/OldCheckouts.pm create mode 100644 installer/data/mysql/atomicupdate/bug_8483.sql diff --git a/C4/Members.pm b/C4/Members.pm index 1a172db..aa9833e 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 ); } @@ -1116,31 +1118,41 @@ 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(); + + push( @results, $hashref ); } - my $sth = $dbh->prepare($query); - $sth->execute( $borrowernumber, $borrowernumber ); - return $sth->fetchall_arrayref( {} ); + return \@results; } diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm new file mode 100644 index 0000000..5be8c3a --- /dev/null +++ b/Koha/Biblio.pm @@ -0,0 +1,52 @@ +package Koha::Biblio; + +# Copyright ByWater Solutions 2015 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Biblio - Koha Biblio Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Biblio'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/BiblioItem.pm b/Koha/BiblioItem.pm new file mode 100644 index 0000000..19c6525 --- /dev/null +++ b/Koha/BiblioItem.pm @@ -0,0 +1,52 @@ +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 +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::BiblioItem - Koha BiblioItem Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Biblioitem'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/BiblioItems.pm b/Koha/BiblioItems.pm new file mode 100644 index 0000000..76f2023 --- /dev/null +++ b/Koha/BiblioItems.pm @@ -0,0 +1,58 @@ +package Koha::BiblioItems; + +# Copyright ByWater Solutions 2015 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::BiblioItem; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::BiblioItem - Koha BiblioItem Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Biblioitem'; +} + +sub object_class { + return 'Koha::BiblioItem'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/Biblios.pm b/Koha/Biblios.pm new file mode 100644 index 0000000..44feb1b --- /dev/null +++ b/Koha/Biblios.pm @@ -0,0 +1,58 @@ +package Koha::Biblios; + +# Copyright ByWater Solutions 2015 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Biblio; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Biblio - Koha Biblio Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Biblio'; +} + +sub object_class { + return 'Koha::Biblio'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/Borrower.pm b/Koha/Borrower.pm index 93426bf..9cdb48f 100644 --- a/Koha/Borrower.pm +++ b/Koha/Borrower.pm @@ -23,6 +23,9 @@ use Carp; use Koha::Database; +use Koha::Checkouts; +use Koha::OldCheckouts; + 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::OldCheckouts->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/Checkout.pm b/Koha/Checkout.pm new file mode 100644 index 0000000..f30f6e1 --- /dev/null +++ b/Koha/Checkout.pm @@ -0,0 +1,76 @@ +package Koha::Checkout; + +# Copyright ByWater Solutions 2015 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; +use Koha::Items; +use Koha::Deleted::Items; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Checkout - Koha Checkout Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 item + +my $item = $checkout->item({ deleted => 1 }); + +Returns the related Koha::Item for this checkout. + +If the parameter delete is passed and true, and the itemnumber +is not found for current items, this method will look for a matching +deleted item. + +=cut + +sub item { + my ( $self, $params ) = @_; + + my $item = Koha::Items->search( { itemnumber => $self->itemnumber() } )->next(); + + $item ||= Koha::Deleted::Items->search( { itemnumber => $self->itemnumber() } )->next() if ( $params->{deleted} ); + + return $item || undef; +} + +=head3 type + +=cut + +sub type { + return 'Issue'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/Checkouts.pm b/Koha/Checkouts.pm new file mode 100644 index 0000000..9b1ddc1 --- /dev/null +++ b/Koha/Checkouts.pm @@ -0,0 +1,58 @@ +package Koha::Checkouts; + +# Copyright ByWater Solutions 2015 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Checkout; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Checkouts - Koha Checkouts Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Issue'; +} + +sub object_class { + return 'Koha::Checkout'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/Deleted/Biblio.pm b/Koha/Deleted/Biblio.pm new file mode 100644 index 0000000..86b64f2 --- /dev/null +++ b/Koha/Deleted/Biblio.pm @@ -0,0 +1,57 @@ +package Koha::Deleted::Biblio; + +# Copyright ByWater Solutions 2015 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use base qw(Koha::Biblio); + +=head1 NAME + +Koha::Deleted::Biblio - Koha Biblio Object class + +This class is an extension of Koha::Biblio. + +New methods should only be added to Koha::Biblio unless they are specifically +and only for dealing with deleted bibs. + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Deletedbiblio'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/Deleted/BiblioItem.pm b/Koha/Deleted/BiblioItem.pm new file mode 100644 index 0000000..ca4a43b --- /dev/null +++ b/Koha/Deleted/BiblioItem.pm @@ -0,0 +1,57 @@ +package Koha::Deleted::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 +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use base qw(Koha::BiblioItem); + +=head1 NAME + +Koha::Deleted::BiblioItem - Koha Deleted BiblioItem Object class + +This class is an extension of Koha::BiblioItem. + +New methods should only be added to Koha::BiblioItem unless they are specifically +and only for dealing with deleted biblioitems. + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Deletedbiblioitem'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/Deleted/BiblioItems.pm b/Koha/Deleted/BiblioItems.pm new file mode 100644 index 0000000..084af5a --- /dev/null +++ b/Koha/Deleted/BiblioItems.pm @@ -0,0 +1,63 @@ +package Koha::Deleted::BiblioItems; + +# Copyright ByWater Solutions 2015 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Deleted::BiblioItem; + +use base qw(Koha::BiblioItems); + +=head1 NAME + +Koha::BiblioItem - Koha BiblioItem Object class + +This class is an extension of Koha::BiblioItems. + +New methods should only be added to Koha::BiblioItems unless they are specifically +and only for dealing with deleted biblioitem sets + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Deletedbiblioitem'; +} + +sub object_class { + return 'Koha::Deleted::BiblioItem'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/Deleted/Biblios.pm b/Koha/Deleted/Biblios.pm new file mode 100644 index 0000000..7c15130 --- /dev/null +++ b/Koha/Deleted/Biblios.pm @@ -0,0 +1,64 @@ +package Koha::Deleted::Biblios; + +# Copyright ByWater Solutions 2015 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Deleted::Biblio; + +use base qw(Koha::Biblios); + +=head1 NAME + +Koha::Deleted::Biblios - Koha Deleted Bibliographic Record set object class + +This class is an extension of Koha::Biblios. + +New methods should only be added to Koha::Biblios unless they are specifically +and only for dealing with deleted bib sets + + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Deletedbiblio'; +} + +sub object_class { + return 'Koha::Deleted::Biblio'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/Deleted/Item.pm b/Koha/Deleted/Item.pm new file mode 100644 index 0000000..77a0a2a --- /dev/null +++ b/Koha/Deleted/Item.pm @@ -0,0 +1,58 @@ +package Koha::Deleted::Item; + +# Copyright ByWater Solutions 2015 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use base qw(Koha::Item); + +=head1 NAME + +Koha::Deleted::Item - Koha Deleted Item Object class + +This class is an extension of Koha::Item. + +New methods should only be added to Koha::Item unless they are specifically +and only for dealing with deleted items only. + + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Deleteditem'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/Deleted/Items.pm b/Koha/Deleted/Items.pm new file mode 100644 index 0000000..363c01b --- /dev/null +++ b/Koha/Deleted/Items.pm @@ -0,0 +1,63 @@ +package Koha::Deleted::Items; + +# Copyright ByWater Solutions 2014 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Deleted::Item; + +use base qw(Koha::Items); + +=head1 NAME + +Koha::Deleted::Items - Koha Deleted Items Object class + +This class is an extension of Koha::Items. + +New methods should only be added to Koha::Items unless they are specifically +and only for dealing with deleted item sets + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Deleteditem'; +} + +sub object_class { + return 'Koha::Deleted::Item'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/Item.pm b/Koha/Item.pm new file mode 100644 index 0000000..b9f1f8b --- /dev/null +++ b/Koha/Item.pm @@ -0,0 +1,100 @@ +package Koha::Item; + +# Copyright ByWater Solutions 2014 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; +use Koha::Biblios; +use Koha::Deleted::Biblios; +use Koha::BiblioItems; +use Koha::Deleted::BiblioItems; + +use base qw(Koha::Object); + +=head1 NAME + +Koha::Item - Koha Item Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 biblio + +my $biblio = $checkout->biblio({ deleted => 1 }); + +Returns the related Koha::Biblio for this checkout. + +If the parameter delete is passed and true, and the biblionumber +is not found for current biblios, this method will look for a matching +deleted biblio. + +=cut + +sub biblio { + my ( $self, $params ) = @_; + + my $biblio = Koha::Biblios->search( { biblionumber => $self->biblionumber() } )->next(); + + $biblio ||= Koha::Deleted::Biblios->search( { biblionumber => $self->biblionumber() } )->next() if ( $params->{deleted} ); + + return $biblio || undef; +} + +=head3 biblioitem + +my $biblioitem = $checkout->biblio({ deleted => 1 }); + +Returns the related Koha::Biblio for this checkout. + +If the parameter delete is passed and true, and the biblioitemnumber +is not found for current biblioitems, this method will look for a matching +deleted biblioitem. + +=cut + +sub biblioitem { + my ( $self, $params ) = @_; + + my $biblioitem = Koha::BiblioItems->search( { biblionumber => $self->biblionumber() } )->next(); + + $biblioitem ||= Koha::Deleted::BiblioItems->search( { biblionumber => $self->biblionumber() } )->next() if ( $params->{deleted} ); + + return $biblioitem || undef; +} + +=head3 type + +=cut + +sub type { + return 'Item'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/Items.pm b/Koha/Items.pm new file mode 100644 index 0000000..c24e294 --- /dev/null +++ b/Koha/Items.pm @@ -0,0 +1,58 @@ +package Koha::Items; + +# Copyright ByWater Solutions 2014 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::Item; + +use base qw(Koha::Objects); + +=head1 NAME + +Koha::Item - Koha Item Object class + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'Item'; +} + +sub object_class { + return 'Koha::Item'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; 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/Koha/OldCheckout.pm b/Koha/OldCheckout.pm new file mode 100644 index 0000000..9ef9dbe --- /dev/null +++ b/Koha/OldCheckout.pm @@ -0,0 +1,57 @@ +package Koha::OldCheckout; + +# Copyright ByWater Solutions 2015 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use base qw(Koha::Checkout); + +=head1 NAME + +Koha::OldCheckout - Koha OldCheckout Object class + +This class is an extension of Koha::Checkout. + +New methods should only be added to Koha::Checkout unless they are specifically +and only for dealing with old checkouts. + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'OldIssue'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/Koha/OldCheckouts.pm b/Koha/OldCheckouts.pm new file mode 100644 index 0000000..e575c53 --- /dev/null +++ b/Koha/OldCheckouts.pm @@ -0,0 +1,63 @@ +package Koha::OldCheckouts; + +# Copyright ByWater Solutions 2015 +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +use Modern::Perl; + +use Carp; + +use Koha::Database; + +use Koha::OldCheckout; + +use base qw(Koha::Checkouts); + +=head1 NAME + +Koha::OldIssues - Koha OldIssues Object class + +This class is an extension of Koha::Checkouts. + +New methods should only be added to Koha::Checkouts unless they are specifically +and only for dealing with old checkouts. + +=head1 API + +=head2 Class Methods + +=cut + +=head3 type + +=cut + +sub type { + return 'OldIssue'; +} + +sub object_class { + return 'Koha::OldCheckout'; +} + +=head1 AUTHOR + +Kyle M Hall + +=cut + +1; diff --git a/installer/data/mysql/atomicupdate/bug_8483.sql b/installer/data/mysql/atomicupdate/bug_8483.sql new file mode 100644 index 0000000..0a853e6 --- /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 df123ee..fd47cfd 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1162,7 +1162,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`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; -- diff --git a/opac/opac-readingrecord.pl b/opac/opac-readingrecord.pl index 3848aaa..42e2861 100755 --- a/opac/opac-readingrecord.pl +++ b/opac/opac-readingrecord.pl @@ -76,6 +76,7 @@ $limit //= ''; $limit = ( $limit eq 'full' ) ? 0 : 50; my $issues = GetAllIssues( $borrowernumber, $order, $limit ); +warn "ISSUES: " . scalar @$issues; my $itype_attribute = ( C4::Context->preference('item-level_itypes') ) ? 'itype' : 'itemtype'; -- 1.7.2.5