From 5757965e43212e03f6a0c07376b11d5a55e9bb15 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 5 Mar 2014 11:24:58 -0500 Subject: [PATCH] Bug 9011 - Add the ability to store the last patron to return an item --- C4/Circulation.pm | 18 +++++++++++++++--- installer/data/mysql/sysprefs.sql | 1 + installer/data/mysql/updatedatabase.pl | 8 ++++++++ .../prog/en/modules/admin/preferences/opac.pref | 7 +++++++ t/db_dependent/Circulation_anonymization.t | 19 +++++++++++++++++-- 5 files changed, 48 insertions(+), 5 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index efa857d..fe57a01 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -3535,11 +3535,23 @@ sub AnonymizeItemIssueHistory { 'me.itemnumber' => $itemnumber, 'me.borrowernumber' => { '!=' => $a }, }, - { prefetch => 'borrower', order_by => { -desc => 'returndate' } } + { prefetch => 'borrower', order_by => { -desc => 'issue_id' } } ); - my $oi = $old_issues_rs->next(); - if ( $oi->borrower()->privacy() == 2 ) { + my $oi; + if ( C4::Context->preference('StoreLastBorrower') ) { + + # If storing last borrower, skip the latest old_issue for this item + $old_issues_rs->next(); + $oi = $old_issues_rs->next(); + } + else { + + # If *not* storing last borrower, use the latest old_issue for this item + $oi = $old_issues_rs->next(); + } + + if ( $oi && $oi->borrower()->privacy() == 2 ) { $oi->set_column( 'borrowernumber', $a ); $oi->update(); } diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 54b8a5e..654258d 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -360,6 +360,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('StaffDetailItemSelection', '1', NULL, 'Enable item selection in record detail page', 'YesNo'), ('StaffSerialIssueDisplayCount','3','','Number of serial issues to display per subscription in the Staff client','Integer'), ('StaticHoldsQueueWeight','0',NULL,'Specify a list of library location codes separated by commas -- the list of codes will be traversed and weighted with first values given higher weight for holds fulfillment -- alternatively, if RandomizeHoldsQueueWeight is set, the list will be randomly selective','Integer'), +('StoreLastBorrower','0','','If ON, the last borrower to return an item will be stored in items.last_returned_by','YesNo'), ('SubfieldsToUseWhenPrefill','','','Define a list of subfields to use when prefilling items (separated by space)','Free'), ('SubscriptionDuplicateDroppedInput','','','List of fields which must not be rewritten when a subscription is duplicated (Separated by pipe |)','Free'), ('SubscriptionHistory','simplified','simplified|full','Define the display preference for serials issue history in OPAC','Choice'), diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index e0d0b94..8ae2733 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -8052,6 +8052,14 @@ if(CheckVersion($DBversion)) { SetVersion($DBversion); } +$DBversion = "3.13.00.XXX"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('StoreLastBorrower','0','','If ON, the last borrower to return an item will be stored in items.last_returned_by','YesNo')"); + + print "Upgrade to $DBversion done (Bug 9011 - Add the ability to store the last patron to return an item)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref index d541440..6532f11 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/opac.pref @@ -563,6 +563,13 @@ OPAC: track: "Track" no: "Don't track" - links that patrons click on + - + - pref: StoreLastBorrower + default: 0 + choices: + yes: Store + no: "Don't store" + - the last patron to return an item. This setting is independent of opacreadinghistory/AnonymousPatron. Shelf Browser: - diff --git a/t/db_dependent/Circulation_anonymization.t b/t/db_dependent/Circulation_anonymization.t index caec6b5..d886bf1 100644 --- a/t/db_dependent/Circulation_anonymization.t +++ b/t/db_dependent/Circulation_anonymization.t @@ -6,7 +6,7 @@ use C4::Context; use C4::Circulation; use Koha::Database; -use Test::More tests => 4; +use Test::More tests => 6; BEGIN { use_ok('C4::Circulation'); @@ -132,6 +132,8 @@ my $userenv = C4::Context->userenv #Begin Tests +C4::Context->set_preference( 'StoreLastBorrower', 0 ); + AddIssue( $borrower_1, 'barcode_1' ); AddReturn('barcode_1'); my $old_issue = @@ -141,13 +143,26 @@ ok( $old_issue->borrower()->borrowernumber() == $anonymous_patron->borrowernumbe my $next_issue_id = $old_issue->issue_id() + 1; - AddIssue( $borrower_2, 'barcode_1' ); AddReturn('barcode_1'); $old_issue = $schema->resultset('OldIssue')->find( $next_issue_id ); ok( $old_issue->borrower()->borrowernumber() == $borrower2->borrowernumber(), "Patron with privacy of 1 not anonymized" ); +C4::Context->set_preference( 'StoreLastBorrower', 1 ); + +$next_issue_id = $old_issue->issue_id() + 1; + +AddIssue( $borrower_1, 'barcode_1' ); +AddReturn('barcode_1'); +$old_issue = + $schema->resultset('OldIssue')->find( $next_issue_id ); +ok( $old_issue->borrower()->borrowernumber() == $borrower1->borrowernumber(), "Patron with privacy of 2 not anonymized with StoreLastBorrower enabled" ); +AddIssue( $borrower_2, 'barcode_1' ); +AddReturn('barcode_1'); +$old_issue = + $schema->resultset('OldIssue')->find( $next_issue_id ); +ok( $old_issue->borrower()->borrowernumber() == $anonymous_patron->borrowernumber(), "Patron with privacy of 2 anonymized after next return with StoreLastBorrower enabled" ); #End transaction $dbh->rollback; -- 1.7.2.5