Bugzilla – Attachment 114057 Details for
Bug 26498
Add option to set a default expire date for holds at reservation time
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26498: Set default expiration date for holds
0001-Bug-26498-Set-default-expiration-date-for-holds.patch (text/plain), 7.80 KB, created by
Emmi Takkinen
on 2020-11-30 13:44:43 UTC
(
hide
)
Description:
Bug 26498: Set default expiration date for holds
Filename:
MIME Type:
Creator:
Emmi Takkinen
Created:
2020-11-30 13:44:43 UTC
Size:
7.80 KB
patch
obsolete
>From 1b5e646c69261c8377e31067156b99ec0f2c329a Mon Sep 17 00:00:00 2001 >From: Emmi Takkinen <emmi.takkinen@outlook.com> >Date: Thu, 26 Nov 2020 14:59:42 +0200 >Subject: [PATCH] Bug 26498: Set default expiration date for holds > >Koha doesn't automatically set expiration date for holds >so they can live in the system forever. This patch adds >new sysprefs to control setting of default expiration >date for holds. > >To test: >1. Apply patch (and update database). >2. Enable syspref "DefaultHoldExpirationdate" and set some values >to "DefaultHoldExpirationdatePeriod" and >"DefaultHoldExpirationdateUnitOfTime". >3. Add some holds for patron from staff client or OPAC. >=> Holds expiration date should be set according your settings >4. Disable "DefaultHoldExpirationdate" and add new holds. >=> Expiration date shouldn't be set. > >Also prove prove t/db_dependent/Hold.t > >Sponsored-by: Koha-Suomi Oy >--- > Koha/Hold.pm | 15 ++++++++++++ > ...Set_default_expiration_date_for_holds.perl | 12 ++++++++++ > installer/data/mysql/mandatory/sysprefs.sql | 3 +++ > .../admin/preferences/circulation.pref | 15 ++++++++++++ > t/db_dependent/Hold.t | 23 ++++++++++++++++++- > 5 files changed, 67 insertions(+), 1 deletion(-) > create mode 100644 installer/data/mysql/atomicupdate/Bug-26498-Set_default_expiration_date_for_holds.perl > >diff --git a/Koha/Hold.pm b/Koha/Hold.pm >index 7754691238..1b66321208 100644 >--- a/Koha/Hold.pm >+++ b/Koha/Hold.pm >@@ -505,6 +505,21 @@ sub cancel { > return $self; > } > >+sub store { >+ my ($self) = @_; >+ >+ if ( C4::Context->preference('DefaultHoldExpirationdate') >+ and ( not defined $self->expirationdate or $self->expirationdate eq '' ) ){ >+ >+ my $period = C4::Context->preference('DefaultHoldExpirationdatePeriod'); >+ my $timeunit = C4::Context->preference('DefaultHoldExpirationdateUnitOfTime'); >+ >+ $self->expirationdate( dt_from_string( $self->reservedate )->add( $timeunit => $period ) ); >+ } >+ >+ $self = $self->SUPER::store; >+} >+ > =head3 _move_to_old > > my $is_moved = $hold->_move_to_old; >diff --git a/installer/data/mysql/atomicupdate/Bug-26498-Set_default_expiration_date_for_holds.perl b/installer/data/mysql/atomicupdate/Bug-26498-Set_default_expiration_date_for_holds.perl >new file mode 100644 >index 0000000000..6ac2af0088 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/Bug-26498-Set_default_expiration_date_for_holds.perl >@@ -0,0 +1,12 @@ >+$DBversion = 'XXX'; # will be replaced by the RM >+if( CheckVersion( $DBversion ) ) { >+ # you can use $dbh here like: >+ # $dbh->do( "ALTER TABLE biblio ADD COLUMN badtaste int" ); >+ >+ $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('DefaultHoldExpirationdate','1','','Automatically set default expiration date for holds','YesNo') }); >+ $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('DefaultHoldExpirationdatePeriod','0','','How long into the future default expiration date is set to be.','integer') }); >+ $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('DefaultHoldExpirationdateUnitOfTime','','days|months|years','Which unit of time is used when settimg default expiration date. ','choice') }); >+ >+ # Always end with this (adjust the bug info) >+ NewVersion( $DBversion, 26498, "Bug 26498 - Add option to set a default expire date for holds at reservation time"); >+} >\ No newline at end of file >diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql >index 2ea427bdd2..adeae44830 100644 >--- a/installer/data/mysql/mandatory/sysprefs.sql >+++ b/installer/data/mysql/mandatory/sysprefs.sql >@@ -151,6 +151,9 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('decreaseLoanHighHoldsValue',NULL,'','Specifies a threshold for the minimum number of holds needed to trigger a reduction in loan duration (used with decreaseLoanHighHolds)','Integer'), > ('DefaultClassificationSource','ddc',NULL,'Default classification scheme used by the collection. E.g., Dewey, LCC, etc.','ClassSources'), > ('DefaultCountryField008','','','Fill in the default country code for field 008 Range 15-17 of MARC21 - Place of publication, production, or execution. See <a href=\"http://www.loc.gov/marc/countries/countries_code.html\">MARC Code List for Countries</a>','Free'), >+('DefaultHoldExpirationdate','1','','Automatically set expiration date for holds','YesNo'), >+('DefaultHoldExpirationdatePeriod','0','','How long into the future default expiration date is set to be.','integer'), >+('DefaultHoldExpirationdateUnitOfTime','','days|months|years','Which unit of time is used when settimg default expiration date. ','choice'), > ('DefaultLanguageField008','','','Fill in the default language for field 008 Range 35-37 of MARC21 records (e.g. eng, nor, ger, see <a href=\"http://www.loc.gov/marc/languages/language_code.html\">MARC Code List for Languages</a>)','Free'), > ('DefaultLongOverdueSkipLostStatuses', '', NULL, 'Skip these lost statuses by default in longoverdue.pl', 'Free'), > ('DefaultLongOverdueChargeValue', '', NULL, "Charge a lost item to the borrower's account when the LOST value of the item changes to n.", 'integer'), >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref >index 9bd26d5aa1..a88b6ca8a7 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref >@@ -893,6 +893,21 @@ Circulation: > - pref: UpdateItemWhenLostFromHoldList > type: textarea > syntax: text/x-yaml >+ - >+ - pref: DefaultHoldExpirationdate >+ choices: >+ yes: Set >+ no: Don't set >+ - default expiration date for holds automatically. >+ - If enabled, set expiration date >+ - pref: DefaultHoldExpirationdatePeriod >+ class: integer >+ - pref: DefaultHoldExpirationdateUnitOfTime >+ choices: >+ days: days >+ months: months >+ years: years >+ - from reserve date. > Interlibrary loans: > - > - pref: ILLModule >diff --git a/t/db_dependent/Hold.t b/t/db_dependent/Hold.t >index 5b71b64292..41496e9266 100755 >--- a/t/db_dependent/Hold.t >+++ b/t/db_dependent/Hold.t >@@ -29,7 +29,7 @@ use Koha::Item; > use Koha::DateUtils; > use t::lib::TestBuilder; > >-use Test::More tests => 33; >+use Test::More tests => 34; > use Test::Exception; > use Test::Warn; > >@@ -142,6 +142,27 @@ ok( !$hold->is_at_destination(), "Waiting hold where hold branchcode is not the > $item->holdingbranch( $branches[1]->{branchcode} ); > ok( $hold->is_at_destination(), "Waiting hold where hold branchcode is the same as the item's holdingbranch is at destination" ); > >+# Test setting expiration date >+t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdate', 1 ); >+t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdatePeriod', 2 ); >+t::lib::Mocks::mock_preference( 'DefaultHoldExpirationdateUnitOfTime', 'years' ); >+ >+my $hold_2 = Koha::Hold->new( >+ { >+ biblionumber => $biblionumber, >+ itemnumber => $item->id(), >+ reservedate => '2020-11-30', >+ waitingdate => '2020-11-30', >+ borrowernumber => $borrower->{borrowernumber}, >+ branchcode => $branches[1]->{branchcode}, >+ suspend => 0, >+ } >+); >+$hold_2->store(); >+ >+my $expected_date = dt_from_string( $hold_2->reservedate )->add( years => 2); >+is($hold_2->expirationdate->ymd, $expected_date->ymd,'Expiration date is correctly set.'); >+ > $schema->storage->txn_rollback(); > > subtest "delete() tests" => sub { >-- >2.17.1 >
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 26498
:
114057
|
114524
|
114663
|
117127
|
117472
|
117542
|
117543
|
118676
|
118677
|
118678
|
119278