Bugzilla – Attachment 72225 Details for
Bug 18925
Move maxissueqty and maxonsiteissueqty to circulation_rules
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 18925: Move maxissueqty and maxonsiteissueqty to circulation_rules
Bug-18925-Move-maxissueqty-and-maxonsiteissueqty-t.patch (text/plain), 59.34 KB, created by
Jesse Weaver
on 2018-02-26 18:29:46 UTC
(
hide
)
Description:
Bug 18925: Move maxissueqty and maxonsiteissueqty to circulation_rules
Filename:
MIME Type:
Creator:
Jesse Weaver
Created:
2018-02-26 18:29:46 UTC
Size:
59.34 KB
patch
obsolete
>From 1308166a7aac8a45f48b47f9d91de46d2ce9f6a9 Mon Sep 17 00:00:00 2001 >From: Kyle M Hall <kyle@bywatersolutions.com> >Date: Mon, 10 Jul 2017 11:00:44 -0400 >Subject: [PATCH] Bug 18925: Move maxissueqty and maxonsiteissueqty to > circulation_rules > >This patch set moves maxissueqty and maxonsiteissueqty to the >circulation_rules table. > >Test Plan: >1) Apply this patch >2) Run updatedatabase >3) prove t/db_dependent/Circulation.t >4) prove t/db_dependent/Circulation/Branch.t >5) prove t/db_dependent/Circulation/GetHardDueDate.t >6) prove t/db_dependent/Circulation/Returns.t >7) prove t/db_dependent/Circulation/SwitchOnSiteCheckouts.t >8) prove t/db_dependent/Circulation/TooMany.t >9) prove t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t >10) prove t/db_dependent/Reserves.t >11) Note no changes in circulation behavior related to check out limis > both on and off site >--- > C4/Circulation.pm | 125 ++++++----- > Koha/CirculationRules.pm | 12 +- > admin/smart-rules.pl | 246 +++++++-------------- > installer/data/mysql/atomicupdate/bug_18925.perl | 75 +++++++ > installer/data/mysql/kohastructure.sql | 37 ---- > .../prog/en/modules/admin/smart-rules.tt | 79 ++++--- > t/db_dependent/Circulation.t | 26 ++- > t/db_dependent/Circulation/Branch.t | 60 +++-- > t/db_dependent/Circulation/GetHardDueDate.t | 20 +- > t/db_dependent/Circulation/Returns.t | 1 - > t/db_dependent/Circulation/SwitchOnSiteCheckouts.t | 38 ++-- > t/db_dependent/Circulation/TooMany.t | 105 +++++---- > .../Holds/DisallowHoldIfItemsAvailable.t | 1 - > t/db_dependent/Reserves.t | 14 +- > 14 files changed, 441 insertions(+), 398 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_18925.perl > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index d583e5372c..8d995f6149 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -386,10 +386,20 @@ sub TooMany { > > # given branch, patron category, and item type, determine > # applicable issuing rule >- my $issuing_rule = Koha::IssuingRules->get_effective_issuing_rule( >- { categorycode => $cat_borrower, >+ my $maxissueqty_rule = Koha::CirculationRules->get_effective_rule( >+ { >+ categorycode => $cat_borrower, >+ itemtype => $type, >+ branchcode => $branch, >+ rule_name => 'maxissueqty', >+ } >+ ); >+ my $maxonsiteissueqty_rule = Koha::CirculationRules->get_effective_rule( >+ { >+ categorycode => $cat_borrower, > itemtype => $type, >- branchcode => $branch >+ branchcode => $branch, >+ rule_name => 'maxonsiteissueqty', > } > ); > >@@ -397,7 +407,7 @@ sub TooMany { > # if a rule is found and has a loan limit set, count > # how many loans the patron already has that meet that > # rule >- if (defined($issuing_rule) and defined($issuing_rule->maxissueqty)) { >+ if (defined($maxissueqty_rule) and defined($maxissueqty_rule->rule_value)) { > my @bind_params; > my $count_query = q| > SELECT COUNT(*) AS total, COALESCE(SUM(onsite_checkout), 0) AS onsite_checkouts >@@ -405,7 +415,7 @@ sub TooMany { > JOIN items USING (itemnumber) > |; > >- my $rule_itemtype = $issuing_rule->itemtype; >+ my $rule_itemtype = $maxissueqty_rule->itemtype; > if ($rule_itemtype eq "*") { > # matching rule has the default item type, so count only > # those existing loans that don't fall under a more >@@ -426,8 +436,8 @@ sub TooMany { > AND itemtype <> '*' > ) "; > } >- push @bind_params, $issuing_rule->branchcode; >- push @bind_params, $issuing_rule->categorycode; >+ push @bind_params, $maxissueqty_rule->branchcode; >+ push @bind_params, $maxissueqty_rule->categorycode; > push @bind_params, $cat_borrower; > } else { > # rule has specific item type, so count loans of that >@@ -443,7 +453,7 @@ sub TooMany { > > $count_query .= " AND borrowernumber = ? "; > push @bind_params, $borrower->{'borrowernumber'}; >- my $rule_branch = $issuing_rule->branchcode; >+ my $rule_branch = $maxissueqty_rule->branchcode; > if ($rule_branch ne "*") { > if (C4::Context->preference('CircControl') eq 'PickupLibrary') { > $count_query .= " AND issues.branchcode = ? "; >@@ -458,8 +468,8 @@ sub TooMany { > > my ( $checkout_count, $onsite_checkout_count ) = $dbh->selectrow_array( $count_query, {}, @bind_params ); > >- my $max_checkouts_allowed = $issuing_rule->maxissueqty; >- my $max_onsite_checkouts_allowed = $issuing_rule->maxonsiteissueqty; >+ my $max_checkouts_allowed = $maxissueqty_rule ? $maxissueqty_rule->rule_value : 0; >+ my $max_onsite_checkouts_allowed = $maxonsiteissueqty_rule ? $maxonsiteissueqty_rule->rule_value : 0; > > if ( $onsite_checkout and defined $max_onsite_checkouts_allowed ) { > if ( $onsite_checkout_count >= $max_onsite_checkouts_allowed ) { >@@ -544,7 +554,7 @@ sub TooMany { > } > } > >- if ( not defined( $issuing_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) { >+ if ( not defined( $maxissueqty_rule ) and not defined($branch_borrower_circ_rule->{maxissueqty}) ) { > return { reason => 'NO_RULE_DEFINED', max_allowed => 0 }; > } > >@@ -1570,14 +1580,11 @@ maxonsiteissueqty - maximum of on-site checkouts that a > patron of the given category can have at the given > branch. If the value is undef, no limit. > >-This will first check for a specific branch and >-category match from branch_borrower_circ_rules. >- >-If no rule is found, it will then check default_branch_circ_rules >-(same branch, default category). If no rule is found, >-it will then check default_borrower_circ_rules (default >-branch, same category), then failing that, default_circ_rules >-(default branch, default category). >+This will check for different branch/category combinations in the following order: >+branch and category >+branch only >+category only >+default branch and category > > If no rule has been found in the database, it will default to > the buillt in rule: >@@ -1594,44 +1601,54 @@ wildcards. > sub GetBranchBorrowerCircRule { > my ( $branchcode, $categorycode ) = @_; > >- my $rules; >- my $dbh = C4::Context->dbh(); >- $rules = $dbh->selectrow_hashref( q| >- SELECT maxissueqty, maxonsiteissueqty >- FROM branch_borrower_circ_rules >- WHERE branchcode = ? >- AND categorycode = ? >- |, {}, $branchcode, $categorycode ) ; >- return $rules if $rules; >- >- # try same branch, default borrower category >- $rules = $dbh->selectrow_hashref( q| >- SELECT maxissueqty, maxonsiteissueqty >- FROM default_branch_circ_rules >- WHERE branchcode = ? >- |, {}, $branchcode ) ; >- return $rules if $rules; >- >- # try default branch, same borrower category >- $rules = $dbh->selectrow_hashref( q| >- SELECT maxissueqty, maxonsiteissueqty >- FROM default_borrower_circ_rules >- WHERE categorycode = ? >- |, {}, $categorycode ) ; >- return $rules if $rules; >- >- # try default branch, default borrower category >- $rules = $dbh->selectrow_hashref( q| >- SELECT maxissueqty, maxonsiteissueqty >- FROM default_circ_rules >- |, {} ); >- return $rules if $rules; >+ # Set search prededences >+ my @params = ( >+ { >+ branchcode => $branchcode, >+ categorycode => $categorycode, >+ itemtype => undef, >+ }, >+ { >+ branchcode => $branchcode, >+ categorycode => undef, >+ itemtype => undef, >+ }, >+ { >+ branchcode => undef, >+ categorycode => $categorycode, >+ itemtype => undef, >+ }, >+ { >+ branchcode => undef, >+ categorycode => undef, >+ itemtype => undef, >+ }, >+ ); > >- # built-in default circulation rule >- return { >- maxissueqty => undef, >+ # Initialize default values >+ my $rules = { >+ maxissueqty => undef, > maxonsiteissueqty => undef, > }; >+ >+ # Search for rules! >+ foreach my $rule_name (qw( maxissueqty maxonsiteissueqty )) { >+ foreach my $params (@params) { >+ my $rule = Koha::CirculationRules->search( >+ { >+ rule_name => $rule_name, >+ %$params, >+ } >+ )->next(); >+ >+ if ( $rule ) { >+ $rules->{$rule_name} = $rule->rule_value; >+ last; >+ } >+ } >+ } >+ >+ return $rules; > } > > =head2 GetBranchItemRule >diff --git a/Koha/CirculationRules.pm b/Koha/CirculationRules.pm >index 054eb00858..2ab806bef4 100644 >--- a/Koha/CirculationRules.pm >+++ b/Koha/CirculationRules.pm >@@ -142,17 +142,21 @@ sub set_rules { > my $itemtype = $params->{itemtype}; > my $rules = $params->{rules}; > >- foreach my $rule (@$rules) { >- Koha::CirculationRules->set_rule( >+ my $rule_objects = []; >+ while ( my ( $rule_name, $rule_value ) = each %$rules ) { >+ my $rule_object = Koha::CirculationRules->set_rule( > { > branchcode => $branchcode, > categorycode => $categorycode, > itemtype => $itemtype, >- rule_name => $rule->{rule_name}, >- rule_value => $rule->{rule_value}, >+ rule_name => $rule_name, >+ rule_value => $rule_value, > } > ); >+ push( @$rule_objects, $rule_object ); > } >+ >+ return $rule_objects; > } > > =head3 type >diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl >index 79e9d38030..11ab21d3b7 100755 >--- a/admin/smart-rules.pl >+++ b/admin/smart-rules.pl >@@ -79,28 +79,22 @@ elsif ($op eq 'delete-branch-cat') { > if ($categorycode eq "*") { > my $sth_delete = $dbh->prepare("DELETE FROM default_circ_rules"); > $sth_delete->execute(); >- } else { >- my $sth_delete = $dbh->prepare("DELETE FROM default_borrower_circ_rules >- WHERE categorycode = ?"); >- $sth_delete->execute($categorycode); > } > } elsif ($categorycode eq "*") { > my $sth_delete = $dbh->prepare("DELETE FROM default_branch_circ_rules > WHERE branchcode = ?"); > $sth_delete->execute($branch); >- } else { >- my $sth_delete = $dbh->prepare("DELETE FROM branch_borrower_circ_rules >- WHERE branchcode = ? >- AND categorycode = ?"); >- $sth_delete->execute($branch, $categorycode); > } >- Koha::CirculationRules->set_rule( >+ Koha::CirculationRules->set_rules( > { >- branchcode => $branch, >- categorycode => $categorycode, >+ categorycode => $categorycode eq '*' ? undef : $categorycode, >+ branchcode => $branch eq '*' ? undef : $branch, > itemtype => undef, >- rule_name => 'max_holds', >- rule_value => undef, >+ rules => { >+ max_holds => undef, >+ maxissueqty => undef, >+ maxonsiteissueqty => undef, >+ } > } > ); > } >@@ -181,8 +175,6 @@ elsif ($op eq 'add') { > firstremind => $firstremind, > chargeperiod => $chargeperiod, > chargeperiod_charge_at => $chargeperiod_charge_at, >- maxissueqty => $maxissueqty, >- maxonsiteissueqty => $maxonsiteissueqty, > renewalsallowed => $renewalsallowed, > renewalperiod => $renewalperiod, > norenewalbefore => $norenewalbefore, >@@ -210,6 +202,18 @@ elsif ($op eq 'add') { > Koha::IssuingRule->new()->set($params)->store(); > } > >+ Koha::CirculationRules->set_rules( >+ { >+ categorycode => $bor, >+ itemtype => $itemtype, >+ branchcode => $br, >+ rules => { >+ maxissueqty => $maxissueqty, >+ maxonsiteissueqty => $maxonsiteissueqty, >+ } >+ } >+ ); >+ > } > elsif ($op eq "set-branch-defaults") { > my $categorycode = $input->param('categorycode'); >@@ -232,35 +236,59 @@ elsif ($op eq "set-branch-defaults") { > my $sth_search = $dbh->prepare("SELECT count(*) AS total > FROM default_circ_rules"); > my $sth_insert = $dbh->prepare("INSERT INTO default_circ_rules >- (maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch) >- VALUES (?, ?, ?, ?, ?)"); >+ (holdallowed, hold_fulfillment_policy, returnbranch) >+ VALUES (?, ?, ?)"); > my $sth_update = $dbh->prepare("UPDATE default_circ_rules >- SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?"); >+ SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ?"); > > $sth_search->execute(); > my $res = $sth_search->fetchrow_hashref(); > if ($res->{total}) { >- $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); >+ $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch); > } else { >- $sth_insert->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); >+ $sth_insert->execute($holdallowed, $hold_fulfillment_policy, $returnbranch); > } >+ >+ Koha::CirculationRules->set_rules( >+ { >+ categorycode => undef, >+ itemtype => undef, >+ branchcode => undef, >+ rules => { >+ maxissueqty => $maxissueqty, >+ maxonsiteissueqty => $maxonsiteissueqty, >+ } >+ } >+ ); > } else { > my $sth_search = $dbh->prepare("SELECT count(*) AS total > FROM default_branch_circ_rules > WHERE branchcode = ?"); > my $sth_insert = $dbh->prepare("INSERT INTO default_branch_circ_rules >- (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, hold_fulfillment_policy, returnbranch) >- VALUES (?, ?, ?, ?, ?, ?)"); >+ (branchcode, holdallowed, hold_fulfillment_policy, returnbranch) >+ VALUES (?, ?, ?, ?)"); > my $sth_update = $dbh->prepare("UPDATE default_branch_circ_rules >- SET maxissueqty = ?, maxonsiteissueqty = ?, holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ? >+ SET holdallowed = ?, hold_fulfillment_policy = ?, returnbranch = ? > WHERE branchcode = ?"); > $sth_search->execute($branch); > my $res = $sth_search->fetchrow_hashref(); > if ($res->{total}) { >- $sth_update->execute($maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch, $branch); >+ $sth_update->execute($holdallowed, $hold_fulfillment_policy, $returnbranch, $branch); > } else { >- $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty, $holdallowed, $hold_fulfillment_policy, $returnbranch); >+ $sth_insert->execute($branch, $holdallowed, $hold_fulfillment_policy, $returnbranch); > } >+ >+ Koha::CirculationRules->set_rules( >+ { >+ categorycode => undef, >+ itemtype => undef, >+ branchcode => $branch, >+ rules => { >+ maxissueqty => $maxissueqty, >+ maxonsiteissueqty => $maxonsiteissueqty, >+ } >+ } >+ ); > } > Koha::CirculationRules->set_rule( > { >@@ -285,124 +313,56 @@ elsif ($op eq "add-branch-cat") { > > if ($branch eq "*") { > if ($categorycode eq "*") { >- my $sth_search = $dbh->prepare("SELECT count(*) AS total >- FROM default_circ_rules"); >- my $sth_insert = $dbh->prepare(q| >- INSERT INTO default_circ_rules >- (maxissueqty, maxonsiteissueqty) >- VALUES (?, ?) >- |); >- my $sth_update = $dbh->prepare(q| >- UPDATE default_circ_rules >- SET maxissueqty = ?, >- maxonsiteissueqty = ? >- |); >- >- $sth_search->execute(); >- my $res = $sth_search->fetchrow_hashref(); >- if ($res->{total}) { >- $sth_update->execute( $maxissueqty, $maxonsiteissueqty ); >- } else { >- $sth_insert->execute( $maxissueqty, $maxonsiteissueqty ); >- } >- >- Koha::CirculationRules->set_rule( >+ Koha::CirculationRules->set_rules( > { >- branchcode => undef, > categorycode => undef, > itemtype => undef, >- rule_name => 'max_holds', >- rule_value => $max_holds, >+ branchcode => undef, >+ rules => { >+ max_holds => $max_holds, >+ maxissueqty => $maxissueqty, >+ maxonsiteissueqty => $maxonsiteissueqty, >+ } > } > ); > } else { >- my $sth_search = $dbh->prepare("SELECT count(*) AS total >- FROM default_borrower_circ_rules >- WHERE categorycode = ?"); >- my $sth_insert = $dbh->prepare(q| >- INSERT INTO default_borrower_circ_rules >- (categorycode, maxissueqty, maxonsiteissueqty) >- VALUES (?, ?, ?) >- |); >- my $sth_update = $dbh->prepare(q| >- UPDATE default_borrower_circ_rules >- SET maxissueqty = ?, >- maxonsiteissueqty = ? >- WHERE categorycode = ? >- |); >- $sth_search->execute($categorycode); >- my $res = $sth_search->fetchrow_hashref(); >- if ($res->{total}) { >- $sth_update->execute( $maxissueqty, $maxonsiteissueqty, $categorycode ); >- } else { >- $sth_insert->execute( $categorycode, $maxissueqty, $maxonsiteissueqty ); >- } >- >- Koha::CirculationRules->set_rule( >+ Koha::CirculationRules->set_rules( > { > branchcode => '*', > categorycode => $categorycode, > itemtype => undef, >- rule_name => 'max_holds', >- rule_value => $max_holds, >+ rules => { >+ max_holds => $max_holds, >+ maxissueqty => $maxissueqty, >+ maxonsiteissueqty => $maxonsiteissueqty, >+ } > } > ); > } > } elsif ($categorycode eq "*") { >- my $sth_search = $dbh->prepare("SELECT count(*) AS total >- FROM default_branch_circ_rules >- WHERE branchcode = ?"); >- my $sth_insert = $dbh->prepare(q| >- INSERT INTO default_branch_circ_rules >- (branchcode, maxissueqty, maxonsiteissueqty) >- VALUES (?, ?, ?) >- |); >- my $sth_update = $dbh->prepare(q| >- UPDATE default_branch_circ_rules >- SET maxissueqty = ?, >- maxonsiteissueqty = ? >- WHERE branchcode = ? >- |); >- $sth_search->execute($branch); >- my $res = $sth_search->fetchrow_hashref(); >- if ($res->{total}) { >- $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch); >- } else { >- $sth_insert->execute($branch, $maxissueqty, $maxonsiteissueqty); >- } >- } else { >- my $sth_search = $dbh->prepare("SELECT count(*) AS total >- FROM branch_borrower_circ_rules >- WHERE branchcode = ? >- AND categorycode = ?"); >- my $sth_insert = $dbh->prepare(q| >- INSERT INTO branch_borrower_circ_rules >- (branchcode, categorycode, maxissueqty, maxonsiteissueqty) >- VALUES (?, ?, ?, ?) >- |); >- my $sth_update = $dbh->prepare(q| >- UPDATE branch_borrower_circ_rules >- SET maxissueqty = ?, >- maxonsiteissueqty = ? >- WHERE branchcode = ? >- AND categorycode = ? >- |); >- >- $sth_search->execute($branch, $categorycode); >- my $res = $sth_search->fetchrow_hashref(); >- if ($res->{total}) { >- $sth_update->execute($maxissueqty, $maxonsiteissueqty, $branch, $categorycode); >- } else { >- $sth_insert->execute($branch, $categorycode, $maxissueqty, $maxonsiteissueqty); >- } >- >- Koha::CirculationRules->set_rule( >+ Koha::CirculationRules->set_rules( > { >+ categorycode => undef, >+ itemtype => undef, > branchcode => $branch, >+ rules => { >+ max_holds => $max_holds, >+ maxissueqty => $maxissueqty, >+ maxonsiteissueqty => $maxonsiteissueqty, >+ } >+ } >+ ); >+ } else { >+ Koha::CirculationRules->set_rules( >+ { > categorycode => $categorycode, > itemtype => undef, >- rule_name => 'max_holds', >- rule_value => $max_holds, >+ branchcode => $branch, >+ rules => { >+ max_holds => $max_holds, >+ maxissueqty => $maxissueqty, >+ maxonsiteissueqty => $maxonsiteissueqty, >+ } > } > ); > } >@@ -570,39 +530,6 @@ while (my $row = $sth2->fetchrow_hashref) { > > my @sorted_row_loop = sort by_category_and_itemtype @row_loop; > >-my $sth_branch_cat; >-if ($branch eq "*") { >- $sth_branch_cat = $dbh->prepare(" >- SELECT default_borrower_circ_rules.*, categories.description AS humancategorycode >- FROM default_borrower_circ_rules >- JOIN categories USING (categorycode) >- >- "); >- $sth_branch_cat->execute(); >-} else { >- $sth_branch_cat = $dbh->prepare(" >- SELECT branch_borrower_circ_rules.*, categories.description AS humancategorycode >- FROM branch_borrower_circ_rules >- JOIN categories USING (categorycode) >- WHERE branch_borrower_circ_rules.branchcode = ? >- "); >- $sth_branch_cat->execute($branch); >-} >- >-my @branch_cat_rules = (); >-while (my $row = $sth_branch_cat->fetchrow_hashref) { >- push @branch_cat_rules, $row; >-} >-my @sorted_branch_cat_rules = sort { $a->{'humancategorycode'} cmp $b->{'humancategorycode'} } @branch_cat_rules; >- >-# note undef maxissueqty so that template can deal with them >-foreach my $entry (@sorted_branch_cat_rules, @sorted_row_loop) { >- $entry->{unlimited_maxissueqty} = 1 unless defined($entry->{maxissueqty}); >- $entry->{unlimited_maxonsiteissueqty} = 1 unless defined($entry->{maxonsiteissueqty}); >-} >- >-@sorted_row_loop = sort by_category_and_itemtype @row_loop; >- > my $sth_branch_item; > if ($branch eq "*") { > $sth_branch_item = $dbh->prepare(" >@@ -643,7 +570,6 @@ foreach my $entry (@sorted_branch_item_rules) { > > $template->param(show_branch_cat_rule_form => 1); > $template->param(branch_item_rule_loop => \@sorted_branch_item_rules); >-$template->param(branch_cat_rule_loop => \@sorted_branch_cat_rules); > > my $sth_defaults; > if ($branch eq "*") { >diff --git a/installer/data/mysql/atomicupdate/bug_18925.perl b/installer/data/mysql/atomicupdate/bug_18925.perl >new file mode 100644 >index 0000000000..b80dd29d65 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_18925.perl >@@ -0,0 +1,75 @@ >+$DBversion = 'XXX'; # will be replaced by the RM >+if( CheckVersion( $DBversion ) ) { >+ if ( column_exists( 'branch_borrower_circ_rules', 'maxissueqty' ) ) { >+ $dbh->do(" >+ INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) >+ SELECT categorycode, branchcode, NULL, 'maxissueqty', maxissueqty >+ FROM branch_borrower_circ_rules >+ "); >+ $dbh->do(" >+ INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) >+ SELECT categorycode, branchcode, NULL, 'maxonsiteissueqty', maxonsiteissueqty >+ FROM branch_borrower_circ_rules >+ "); >+ $dbh->do("DROP TABLE branch_borrower_circ_rules"); >+ } >+ >+ if ( column_exists( 'default_borrower_circ_rules', 'maxissueqty' ) ) { >+ $dbh->do(" >+ INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) >+ SELECT categorycode, NULL, NULL, 'maxissueqty', maxissueqty >+ FROM default_borrower_circ_rules >+ "); >+ $dbh->do(" >+ INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) >+ SELECT categorycode, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty >+ FROM default_borrower_circ_rules >+ "); >+ $dbh->do("DROP TABLE default_borrower_circ_rules"); >+ } >+ >+ if ( column_exists( 'default_circ_rules', 'maxissueqty' ) ) { >+ $dbh->do(" >+ INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) >+ SELECT NULL, NULL, NULL, 'maxissueqty', maxissueqty >+ FROM default_circ_rules >+ "); >+ $dbh->do(" >+ INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) >+ SELECT NULL, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty >+ FROM default_circ_rules >+ "); >+ $dbh->do("ALTER TABLE default_circ_rules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty"); >+ } >+ >+ if ( column_exists( 'default_branch_circ_rules', 'maxissueqty' ) ) { >+ $dbh->do(" >+ INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) >+ SELECT NULL, branchcode, NULL, 'maxissueqty', maxissueqty >+ FROM default_branch_circ_rules >+ "); >+ $dbh->do(" >+ INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) >+ SELECT NULL, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty >+ FROM default_branch_circ_rules >+ "); >+ $dbh->do("ALTER TABLE default_branch_circ_rules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty"); >+ } >+ >+ if ( column_exists( 'issuingrules', 'maxissueqty' ) ) { >+ $dbh->do(" >+ INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) >+ SELECT categorycode, branchcode, itemtype, 'maxissueqty', maxissueqty >+ FROM issuingrules >+ "); >+ $dbh->do(" >+ INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) >+ SELECT categorycode, branchcode, itemtype, 'maxonsiteissueqty', maxonsiteissueqty >+ FROM issuingrules >+ "); >+ $dbh->do("ALTER TABLE issuingrules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty"); >+ } >+ >+ SetVersion( $DBversion ); >+ print "Upgrade to $DBversion done (Bug 18925 - Move maxissueqty and maxonsiteissueqty to circulation_rules)\n"; >+} >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index 8b967187dd..65dc4bd7c0 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -339,37 +339,6 @@ CREATE TABLE collections_tracking ( > PRIMARY KEY (collections_tracking_id) > ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; > >--- >--- Table structure for table `branch_borrower_circ_rules` >--- >- >-DROP TABLE IF EXISTS `branch_borrower_circ_rules`; >-CREATE TABLE `branch_borrower_circ_rules` ( -- includes default circulation rules for patron categories found under "Checkout limit by patron category" >- `branchcode` VARCHAR(10) NOT NULL, -- the branch this rule applies to (branches.branchcode) >- `categorycode` VARCHAR(10) NOT NULL, -- the patron category this rule applies to (categories.categorycode) >- `maxissueqty` int(4) default NULL, -- the maximum number of checkouts this patron category can have at this branch >- `maxonsiteissueqty` int(4) default NULL, -- the maximum number of on-site checkouts this patron category can have at this branch >- PRIMARY KEY (`categorycode`, `branchcode`), >- CONSTRAINT `branch_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) >- ON DELETE CASCADE ON UPDATE CASCADE, >- CONSTRAINT `branch_borrower_circ_rules_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) >- ON DELETE CASCADE ON UPDATE CASCADE >-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; >- >--- >--- Table structure for table `default_borrower_circ_rules` >--- >- >-DROP TABLE IF EXISTS `default_borrower_circ_rules`; >-CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found under "Default checkout, hold and return policy" >- `categorycode` VARCHAR(10) NOT NULL, -- patron category this rul >- `maxissueqty` int(4) default NULL, >- `maxonsiteissueqty` int(4) default NULL, >- PRIMARY KEY (`categorycode`), >- CONSTRAINT `borrower_borrower_circ_rules_ibfk_1` FOREIGN KEY (`categorycode`) REFERENCES `categories` (`categorycode`) >- ON DELETE CASCADE ON UPDATE CASCADE >-) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; >- > -- > -- Table structure for table `default_branch_circ_rules` > -- >@@ -377,8 +346,6 @@ CREATE TABLE `default_borrower_circ_rules` ( -- default checkout rules found und > DROP TABLE IF EXISTS `default_branch_circ_rules`; > CREATE TABLE `default_branch_circ_rules` ( > `branchcode` VARCHAR(10) NOT NULL, >- `maxissueqty` int(4) default NULL, >- `maxonsiteissueqty` int(4) default NULL, > `holdallowed` tinyint(1) default NULL, > hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode > `returnbranch` varchar(15) default NULL, >@@ -394,8 +361,6 @@ CREATE TABLE `default_branch_circ_rules` ( > DROP TABLE IF EXISTS `default_circ_rules`; > CREATE TABLE `default_circ_rules` ( > `singleton` enum('singleton') NOT NULL default 'singleton', >- `maxissueqty` int(4) default NULL, >- `maxonsiteissueqty` int(4) default NULL, > `holdallowed` int(1) default NULL, > hold_fulfillment_policy ENUM('any', 'homebranch', 'holdingbranch') NOT NULL DEFAULT 'any', -- limit trapping of holds by branchcode > `returnbranch` varchar(15) default NULL, >@@ -841,8 +806,6 @@ CREATE TABLE `issuingrules` ( -- circulation and fine rules > `chargeperiod_charge_at` tinyint(1) NOT NULL DEFAULT '0', -- Should fine be given at the start ( 1 ) or the end ( 0 ) of the period > `accountsent` int(11) default NULL, -- not used? always NULL > `chargename` varchar(100) default NULL, -- not used? always NULL >- `maxissueqty` int(4) default NULL, -- total number of checkouts allowed >- `maxonsiteissueqty` int(4) default NULL, -- total number of on-site checkouts allowed > `issuelength` int(4) default NULL, -- length of checkout in the unit set in issuingrules.lengthunit > `lengthunit` varchar(10) default 'days', -- unit of checkout length (days, hours) > `hardduedate` date default NULL, -- hard due date >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt >index a6211592d5..3a35214550 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt >@@ -1,6 +1,15 @@ > [% USE Branches %] >+[% USE Categories %] > [% USE CirculationRules %] > [% SET footerjs = 1 %] >+ >+[% SET branchcode = humanbranch %] >+ >+[% SET categorycodes = ['*'] %] >+[% FOREACH pc IN patron_categories %] >+ [% categorycodes.push( pc.id ) %] >+[% END %] >+ > [% INCLUDE 'doc-head-open.inc' %] > <title>Koha › Administration › Circulation and fine rules</title> > [% INCLUDE 'doc-head-close.inc' %] >@@ -114,18 +123,22 @@ > <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete&itemtype=[% rule.itemtype %]&categorycode=[% rule.categorycode %]&branch=[% rule.current_branch %]"><i class="fa fa-trash"></i> Delete</a> > </td> > >- <td>[% IF ( rule.unlimited_maxissueqty ) %] >- Unlimited >- [% ELSE %] >- [% rule.maxissueqty %] >- [% END %] >- </td> >- <td>[% IF rule.unlimited_maxonsiteissueqty %] >+ <td> >+ [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxissueqty' ) %] >+ [% IF rule_value %] >+ [% rule_value %] >+ [% ELSE %] > Unlimited >+ [% END %] >+ </td> >+ <td> >+ [% SET rule_value = CirculationRules.Get( rule.branchcode, rule.categorycode, rule.itemtype, 'maxonsiteissueqty' ) %] >+ [% IF rule_value %] >+ [% rule_value %] > [% ELSE %] >- [% rule.maxonsiteissueqty %] >+ Unlimited > [% END %] >- </td> >+ </td> > <td>[% rule.issuelength %]</td> > <td> > [% rule.lengthunit %] >@@ -356,8 +369,14 @@ > </tr> > <tr> > <td><em>Defaults[% UNLESS ( default_rules ) %] (not set)[% END %]</em></td> >- <td><input type="text" name="maxissueqty" size="3" value="[% default_maxissueqty %]"/></td> >- <td><input type="text" name="maxonsiteissueqty" size="3" value="[% default_maxonsiteissueqty %]"/></td> >+ <td> >+ [% SET maxissueqty = CirculationRules.Get( branchcode, undef, undef, 'maxissueqty' ) %] >+ <input type="text" name="maxissueqty" size="3" value="[% maxissueqty %]"/> >+ </td> >+ <td> >+ [% SET maxonsiteissueqty = CirculationRules.Get( branchcode, undef, undef, 'maxonsiteissueqty' ) %] >+ <input type="text" name="maxonsiteissueqty" size="3" value="[% maxonsiteissueqty %]"/> >+ </td> > <td> > [% SET rule_value = CirculationRules.Get( current_branch, '*', undef, 'max_holds' ) %] > <input name="max_holds" size="3" value="[% rule_value %]" /> >@@ -472,43 +491,47 @@ > <th>Total current on-site checkouts allowed</th> > <th> </th> > </tr> >- [% FOREACH branch_cat_rule_loo IN branch_cat_rule_loop %] >- [% UNLESS ( loop.odd ) %] >- <tr class="highlight"> >- [% ELSE %] >+ [% FOREACH c IN categorycodes %] >+ [% SET maxissueqty = CirculationRules.Get( branchcode, c, undef, 'maxissueqty' ) %] >+ [% SET maxonsiteissueqty = CirculationRules.Get( branchcode, c, undef, 'maxonsiteissueqty' ) %] >+ [% SET max_holds = CirculationRules.Get( branchcode, c, undef, 'max_holds' ) %] >+ >+ [% IF maxissueqty || maxissueqty || max_holds %] > <tr> >- [% END %] >- <td>[% IF ( branch_cat_rule_loo.default_humancategorycode ) %] >+ <td> >+ [% IF c == '*'%] > <em>Default</em> > [% ELSE %] >- [% branch_cat_rule_loo.humancategorycode %] >+ [% Categories.GetName(c) %] > [% END %] > </td> >- <td>[% IF ( branch_cat_rule_loo.unlimited_maxissueqty ) %] >- Unlimited >+ <td> >+ [% IF maxissueqty %] >+ [% maxissueqty %] > [% ELSE %] >- [% branch_cat_rule_loo.maxissueqty %] >+ Unlimited > [% END %] > </td> >- <td>[% IF ( branch_cat_rule_loo.unlimited_maxonsiteissueqty ) %] >- Unlimited >+ <td> >+ [% IF maxonsiteissueqty %] >+ [% maxonsiteissueqty %] > [% ELSE %] >- [% branch_cat_rule_loo.maxonsiteissueqty %] >+ Unlimited > [% END %] > </td> > <td> >- [% SET rule_value = CirculationRules.Get( branch_cat_rule_loo.branchcode, branch_cat_rule_loo.categorycode, branch_cat_rule_loo.itemtype, 'max_holds' ) %] >- [% IF rule_value.defined && rule_value != '' %] >- [% rule_value %] >+ [% IF max_holds.defined && max_holds != '' %] >+ [% max_holds %] > [% ELSE %] > Unlimited > [% END %] > </td> > > <td class="actions"> >- <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&categorycode=[% branch_cat_rule_loo.categorycode %]&branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a> >+ <a class="btn btn-default btn-xs delete" href="/cgi-bin/koha/admin/smart-rules.pl?op=delete-branch-cat&categorycode=[% c %]&branch=[% current_branch %]"><i class="fa fa-trash"></i> Delete</a> > </td> > </tr> >+ [% END %] > [% END %] > <tr> > <td> >diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t >index f4ff1778f0..acd8af3dd4 100755 >--- a/t/db_dependent/Circulation.t >+++ b/t/db_dependent/Circulation.t >@@ -36,6 +36,7 @@ use Koha::Database; > use Koha::IssuingRules; > use Koha::Checkouts; > use Koha::Patrons; >+use Koha::CirculationRules; > use Koha::Subscriptions; > use Koha::Account::Lines; > use Koha::Account::Offsets; >@@ -180,14 +181,15 @@ is( > > # Set a simple circ policy > $dbh->do('DELETE FROM issuingrules'); >+Koha::CirculationRules->search()->delete(); > $dbh->do( > q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed, >- maxissueqty, issuelength, lengthunit, >+ issuelength, lengthunit, > renewalsallowed, renewalperiod, > norenewalbefore, auto_renew, > fine, chargeperiod) > VALUES (?, ?, ?, ?, >- ?, ?, ?, >+ ?, ?, > ?, ?, > ?, ?, > ?, ? >@@ -195,7 +197,7 @@ $dbh->do( > }, > {}, > '*', '*', '*', 25, >- 20, 14, 'days', >+ 14, 'days', > 1, 7, > undef, 0, > .10, 1 >@@ -1030,18 +1032,29 @@ C4::Context->dbh->do("DELETE FROM accountlines"); > $dbh->do('DELETE FROM issues'); > $dbh->do('DELETE FROM items'); > $dbh->do('DELETE FROM issuingrules'); >+ Koha::CirculationRules->search()->delete(); > $dbh->do( > q{ >- INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, maxissueqty, issuelength, lengthunit, renewalsallowed, renewalperiod, >- norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) >+ INSERT INTO issuingrules ( categorycode, branchcode, itemtype, reservesallowed, issuelength, lengthunit, renewalsallowed, renewalperiod, >+ norenewalbefore, auto_renew, fine, chargeperiod ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) > }, > {}, > '*', '*', '*', 25, >- 20, 14, 'days', >+ 14, 'days', > 1, 7, > undef, 0, > .10, 1 > ); >+ Koha::CirculationRules->set_rules( >+ { >+ categorycode => '*', >+ itemtype => '*', >+ branchcode => '*', >+ rules => { >+ maxissueqty => 20 >+ } >+ } >+ ); > my ( $biblionumber, $biblioitemnumber ) = add_biblio(); > > my $barcode1 = '1234'; >@@ -1666,7 +1679,6 @@ subtest 'AddReturn + CumulativeRestrictionPeriods' => sub { > categorycode => '*', > itemtype => '*', > branchcode => '*', >- maxissueqty => 99, > issuelength => 1, > firstremind => 1, # 1 day of grace > finedays => 2, # 2 days of fine per day of overdue >diff --git a/t/db_dependent/Circulation/Branch.t b/t/db_dependent/Circulation/Branch.t >index 1be07d98a3..8576097ce0 100644 >--- a/t/db_dependent/Circulation/Branch.t >+++ b/t/db_dependent/Circulation/Branch.t >@@ -22,6 +22,7 @@ use C4::Members; > use C4::Circulation; > use C4::Items; > use C4::Context; >+use Koha::CirculationRules; > > use Test::More tests => 14; > use t::lib::Mocks; >@@ -52,7 +53,6 @@ $dbh->do(q|DELETE FROM categories|); > $dbh->do(q|DELETE FROM accountlines|); > $dbh->do(q|DELETE FROM itemtypes|); > $dbh->do(q|DELETE FROM branch_item_rules|); >-$dbh->do(q|DELETE FROM branch_borrower_circ_rules|); > $dbh->do(q|DELETE FROM default_branch_circ_rules|); > $dbh->do(q|DELETE FROM default_circ_rules|); > $dbh->do(q|DELETE FROM default_branch_item_rules|); >@@ -151,31 +151,53 @@ is_deeply( > "Without parameter, GetBranchBorrower returns undef (unilimited) for maxissueqty and maxonsiteissueqty if no rules defined" > ); > >-my $query = q| >- INSERT INTO branch_borrower_circ_rules >- (branchcode, categorycode, maxissueqty, maxonsiteissueqty) >- VALUES( ?, ?, ?, ? ) >-|; >- >-$dbh->do( >- $query, {}, >- $samplebranch1->{branchcode}, >- $samplecat->{categorycode}, 5, 6 >+Koha::CirculationRules->set_rules( >+ { >+ branchcode => $samplebranch1->{branchcode}, >+ categorycode => $samplecat->{categorycode}, >+ itemtype => undef, >+ rules => { >+ maxissueqty => 5, >+ maxonsiteissueqty => 6, >+ } >+ } > ); > >-$query = q| >+my $query = q| > INSERT INTO default_branch_circ_rules >- (branchcode, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch) >- VALUES( ?, ?, ?, ?, ? ) >+ (branchcode, holdallowed, returnbranch) >+ VALUES( ?, ?, ? ) > |; >-$dbh->do( $query, {}, $samplebranch2->{branchcode}, >- 3, 2, 1, 'holdingbranch' ); >+$dbh->do( $query, {}, $samplebranch2->{branchcode}, 1, 'holdingbranch' ); >+Koha::CirculationRules->set_rules( >+ { >+ branchcode => $samplebranch2->{branchcode}, >+ categorycode => undef, >+ itemtype => undef, >+ rules => { >+ maxissueqty => 3, >+ maxonsiteissueqty => 2, >+ } >+ } >+); >+ > $query = q| > INSERT INTO default_circ_rules >- (singleton, maxissueqty, maxonsiteissueqty, holdallowed, returnbranch) >- VALUES( ?, ?, ?, ?, ? ) >+ (singleton, holdallowed, returnbranch) >+ VALUES( ?, ?, ? ) > |; >-$dbh->do( $query, {}, 'singleton', 4, 5, 3, 'homebranch' ); >+$dbh->do( $query, {}, 'singleton', 3, 'homebranch' ); >+Koha::CirculationRules->set_rules( >+ { >+ branchcode => undef, >+ categorycode => undef, >+ itemtype => undef, >+ rules => { >+ maxissueqty => 4, >+ maxonsiteissueqty => 5, >+ } >+ } >+); > > $query = > "INSERT INTO branch_item_rules (branchcode,itemtype,holdallowed,returnbranch) VALUES( ?,?,?,?)"; >diff --git a/t/db_dependent/Circulation/GetHardDueDate.t b/t/db_dependent/Circulation/GetHardDueDate.t >index b5a571b589..c36ec8872d 100644 >--- a/t/db_dependent/Circulation/GetHardDueDate.t >+++ b/t/db_dependent/Circulation/GetHardDueDate.t >@@ -117,8 +117,6 @@ my $sampleissuingrule1 = { > chargename => undef, > restrictedtype => 0, > accountsent => 0, >- maxissueqty => 5, >- maxonsiteissueqty => 4, > finedays => 0, > lengthunit => 'days', > renewalperiod => 5, >@@ -151,9 +149,7 @@ my $sampleissuingrule2 = { > branchcode => $samplebranch2->{branchcode}, > categorycode => $samplecat->{categorycode}, > itemtype => 'BOOK', >- maxissueqty => 2, >- maxonsiteissueqty => 1, >- renewalsallowed => 0, >+ renewalsallowed => 'Null', > renewalperiod => 2, > norenewalbefore => 7, > auto_renew => 0, >@@ -184,9 +180,7 @@ my $sampleissuingrule3 = { > branchcode => $samplebranch1->{branchcode}, > categorycode => $samplecat->{categorycode}, > itemtype => 'DVD', >- maxissueqty => 3, >- maxonsiteissueqty => 2, >- renewalsallowed => 0, >+ renewalsallowed => 'Null', > renewalperiod => 3, > norenewalbefore => 8, > auto_renew => 0, >@@ -218,8 +212,6 @@ $query = 'INSERT INTO issuingrules ( > branchcode, > categorycode, > itemtype, >- maxissueqty, >- maxonsiteissueqty, > renewalsallowed, > renewalperiod, > norenewalbefore, >@@ -245,14 +237,12 @@ $query = 'INSERT INTO issuingrules ( > opacitemholds, > cap_fine_to_replacement_price, > article_requests >- ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'; >+ ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'; > my $sth = $dbh->prepare($query); > $sth->execute( > $sampleissuingrule1->{branchcode}, > $sampleissuingrule1->{categorycode}, > $sampleissuingrule1->{itemtype}, >- $sampleissuingrule1->{maxissueqty}, >- $sampleissuingrule1->{maxonsiteissueqty}, > $sampleissuingrule1->{renewalsallowed}, > $sampleissuingrule1->{renewalperiod}, > $sampleissuingrule1->{norenewalbefore}, >@@ -283,8 +273,6 @@ $sth->execute( > $sampleissuingrule2->{branchcode}, > $sampleissuingrule2->{categorycode}, > $sampleissuingrule2->{itemtype}, >- $sampleissuingrule2->{maxissueqty}, >- $sampleissuingrule2->{maxonsiteissueqty}, > $sampleissuingrule2->{renewalsallowed}, > $sampleissuingrule2->{renewalperiod}, > $sampleissuingrule2->{norenewalbefore}, >@@ -315,8 +303,6 @@ $sth->execute( > $sampleissuingrule3->{branchcode}, > $sampleissuingrule3->{categorycode}, > $sampleissuingrule3->{itemtype}, >- $sampleissuingrule3->{maxissueqty}, >- $sampleissuingrule3->{maxonsiteissueqty}, > $sampleissuingrule3->{renewalsallowed}, > $sampleissuingrule3->{renewalperiod}, > $sampleissuingrule3->{norenewalbefore}, >diff --git a/t/db_dependent/Circulation/Returns.t b/t/db_dependent/Circulation/Returns.t >index e97ebe3bde..14534fdc7c 100644 >--- a/t/db_dependent/Circulation/Returns.t >+++ b/t/db_dependent/Circulation/Returns.t >@@ -54,7 +54,6 @@ my $rule = Koha::IssuingRule->new( > categorycode => '*', > itemtype => '*', > branchcode => '*', >- maxissueqty => 99, > issuelength => 1, > } > ); >diff --git a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t b/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t >index 837ed7d068..77ff701876 100644 >--- a/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t >+++ b/t/db_dependent/Circulation/SwitchOnSiteCheckouts.t >@@ -27,6 +27,7 @@ use C4::Context; > use Koha::DateUtils qw( dt_from_string ); > use Koha::Database; > use Koha::Checkouts; >+use Koha::CirculationRules; > > use t::lib::TestBuilder; > use t::lib::Mocks; >@@ -38,7 +39,6 @@ our $dbh = C4::Context->dbh; > > $dbh->do(q|DELETE FROM branch_item_rules|); > $dbh->do(q|DELETE FROM issues|); >-$dbh->do(q|DELETE FROM branch_borrower_circ_rules|); > $dbh->do(q|DELETE FROM default_branch_circ_rules|); > $dbh->do(q|DELETE FROM default_circ_rules|); > $dbh->do(q|DELETE FROM default_branch_item_rules|); >@@ -85,12 +85,22 @@ my $issuingrule = $builder->build({ > branchcode => $branch->{branchcode}, > categorycode => '*', > itemtype => '*', >- maxissueqty => 2, >- maxonsiteissueqty => 1, > lengthunit => 'days', > issuelength => 5, > }, > }); >+Koha::CirculationRules->search()->delete(); >+Koha::CirculationRules->set_rules( >+ { >+ branchcode => $branch->{branchcode}, >+ categorycode => '*', >+ itemtype => '*', >+ rules => { >+ maxissueqty => 2, >+ maxonsiteissueqty => 1, >+ } >+ } >+); > > C4::Context->_new_userenv ('DUMMY_SESSION_ID'); > C4::Context->set_userenv($patron->borrowernumber, $patron->userid, 'usercnum', 'First name', 'Surname', $branch->{branchcode}, 'My Library', 0); >@@ -148,16 +158,18 @@ my $yet_another_item = $builder->build({ > ( $impossible, undef, undef, undef ) = C4::Circulation::CanBookBeIssued( $patron, $yet_another_item->{barcode} ); > is( $impossible->{TOO_MANY}, 'TOO_MANY_CHECKOUTS', 'Not a specific case, $delta should not be incremented' ); > >-$dbh->do(q|DELETE FROM issuingrules|); >-my $borrower_circ_rule = $builder->build({ >- source => 'DefaultCircRule', >- value => { >- branchcode => $branch->{branchcode}, >- categorycode => '*', >- maxissueqty => 2, >- maxonsiteissueqty => 1, >- }, >-}); >+Koha::CirculationRules->search()->delete(); >+Koha::CirculationRules->set_rules( >+ { >+ branchcode => $branch->{branchcode}, >+ categorycode => '*', >+ itemtype => '*', >+ rules => { >+ maxissueqty => 2, >+ maxonsiteissueqty => 1, >+ } >+ } >+); > ( $impossible, undef, undef, $messages ) = C4::Circulation::CanBookBeIssued( $patron, $another_item->{barcode} ); > is( $messages->{ONSITE_CHECKOUT_WILL_BE_SWITCHED}, 1, 'Specific case 2 - Switch is allowed' ); > is( exists $impossible->{TOO_MANY}, '', 'Specific case 2 - Switch is allowed' ); >diff --git a/t/db_dependent/Circulation/TooMany.t b/t/db_dependent/Circulation/TooMany.t >index 193752ff26..3796aa3455 100644 >--- a/t/db_dependent/Circulation/TooMany.t >+++ b/t/db_dependent/Circulation/TooMany.t >@@ -26,6 +26,7 @@ use C4::Context; > > use Koha::DateUtils qw( dt_from_string ); > use Koha::Database; >+use Koha::CirculationRules; > > use t::lib::TestBuilder; > use t::lib::Mocks; >@@ -43,11 +44,11 @@ $dbh->do(q|DELETE FROM categories|); > $dbh->do(q|DELETE FROM accountlines|); > $dbh->do(q|DELETE FROM itemtypes|); > $dbh->do(q|DELETE FROM branch_item_rules|); >-$dbh->do(q|DELETE FROM branch_borrower_circ_rules|); > $dbh->do(q|DELETE FROM default_branch_circ_rules|); > $dbh->do(q|DELETE FROM default_circ_rules|); > $dbh->do(q|DELETE FROM default_branch_item_rules|); > $dbh->do(q|DELETE FROM issuingrules|); >+Koha::CirculationRules->search()->delete(); > > my $builder = t::lib::TestBuilder->new(); > t::lib::Mocks::mock_preference('item-level_itypes', 1); # Assuming the item type is defined at item level >@@ -106,16 +107,17 @@ subtest 'no rules exist' => sub { > > subtest '1 Issuingrule exist 0 0: no issue allowed' => sub { > plan tests => 4; >- my $issuingrule = $builder->build({ >- source => 'Issuingrule', >- value => { >- branchcode => $branch->{branchcode}, >- categorycode => $category->{categorycode}, >- itemtype => '*', >- maxissueqty => 0, >- maxonsiteissueqty => 0, >+ Koha::CirculationRules->set_rules( >+ { >+ branchcode => $branch->{branchcode}, >+ categorycode => $category->{categorycode}, >+ itemtype => '*', >+ rules => { >+ maxissueqty => 0, >+ maxonsiteissueqty => 0, >+ } > }, >- }); >+ ); > t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0); > is_deeply( > C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ), >@@ -214,16 +216,17 @@ subtest '1 Issuingrule exist with onsiteissueqty=unlimited' => sub { > > subtest '1 Issuingrule exist 1 1: issue is allowed' => sub { > plan tests => 4; >- my $issuingrule = $builder->build({ >- source => 'Issuingrule', >- value => { >- branchcode => $branch->{branchcode}, >- categorycode => $category->{categorycode}, >- itemtype => '*', >- maxissueqty => 1, >- maxonsiteissueqty => 1, >- }, >- }); >+ Koha::CirculationRules->set_rules( >+ { >+ branchcode => $branch->{branchcode}, >+ categorycode => $category->{categorycode}, >+ itemtype => '*', >+ rules => { >+ maxissueqty => 1, >+ maxonsiteissueqty => 1, >+ } >+ } >+ ); > t::lib::Mocks::mock_preference('ConsiderOnSiteCheckoutsAsNormalCheckouts', 0); > is( > C4::Circulation::TooMany( $patron, $biblio->{biblionumber}, $item ), >@@ -253,16 +256,17 @@ subtest '1 Issuingrule exist 1 1: issue is allowed' => sub { > > subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { > plan tests => 5; >- my $issuingrule = $builder->build({ >- source => 'Issuingrule', >- value => { >- branchcode => $branch->{branchcode}, >- categorycode => $category->{categorycode}, >- itemtype => '*', >- maxissueqty => 1, >- maxonsiteissueqty => 1, >- }, >- }); >+ Koha::CirculationRules->set_rules( >+ { >+ branchcode => $branch->{branchcode}, >+ categorycode => $category->{categorycode}, >+ itemtype => '*', >+ rules => { >+ maxissueqty => 1, >+ maxonsiteissueqty => 1, >+ } >+ } >+ ); > > my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string() ); > like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' ); >@@ -308,16 +312,17 @@ subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed. Do a CO' => sub { > > subtest '1 Issuingrule exist: 1 CO allowed, 1 OSCO allowed, Do a OSCO' => sub { > plan tests => 5; >- my $issuingrule = $builder->build({ >- source => 'Issuingrule', >- value => { >- branchcode => $branch->{branchcode}, >- categorycode => $category->{categorycode}, >- itemtype => '*', >- maxissueqty => 1, >- maxonsiteissueqty => 1, >- }, >- }); >+ Koha::CirculationRules->set_rules( >+ { >+ branchcode => $branch->{branchcode}, >+ categorycode => $category->{categorycode}, >+ itemtype => '*', >+ rules => { >+ maxissueqty => 1, >+ maxonsiteissueqty => 1, >+ } >+ } >+ ); > > my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef, { onsite_checkout => 1 } ); > like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' ); >@@ -366,15 +371,17 @@ subtest '1 BranchBorrowerCircRule exist: 1 CO allowed, 1 OSCO allowed' => sub { > # DefaultBorrowerCircRule, DefaultBranchCircRule, DefaultBranchItemRule ans DefaultCircRule.pm > > plan tests => 10; >- my $issuingrule = $builder->build({ >- source => 'BranchBorrowerCircRule', >- value => { >- branchcode => $branch->{branchcode}, >- categorycode => $category->{categorycode}, >- maxissueqty => 1, >- maxonsiteissueqty => 1, >- }, >- }); >+ Koha::CirculationRules->set_rules( >+ { >+ branchcode => $branch->{branchcode}, >+ categorycode => $category->{categorycode}, >+ itemtype => undef, >+ rules => { >+ maxissueqty => 1, >+ maxonsiteissueqty => 1, >+ } >+ } >+ ); > > my $issue = C4::Circulation::AddIssue( $patron, $item->{barcode}, dt_from_string(), undef, undef, undef ); > like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' ); >diff --git a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t b/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t >index 1a9edd882e..82905b4de3 100755 >--- a/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t >+++ b/t/db_dependent/Holds/DisallowHoldIfItemsAvailable.t >@@ -98,7 +98,6 @@ my $rule = Koha::IssuingRule->new( > categorycode => '*', > itemtype => '*', > branchcode => '*', >- maxissueqty => 99, > issuelength => 7, > lengthunit => 8, > reservesallowed => 99, >diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t >index 57de1ddd8f..dd598713b6 100755 >--- a/t/db_dependent/Reserves.t >+++ b/t/db_dependent/Reserves.t >@@ -198,8 +198,6 @@ $requesters{$branch_3} = AddMember( > > $dbh->do('DELETE FROM issuingrules'); > $dbh->do('DELETE FROM branch_item_rules'); >-$dbh->do('DELETE FROM branch_borrower_circ_rules'); >-$dbh->do('DELETE FROM default_borrower_circ_rules'); > $dbh->do('DELETE FROM default_branch_item_rules'); > $dbh->do('DELETE FROM default_branch_circ_rules'); > $dbh->do('DELETE FROM default_circ_rules'); >@@ -212,18 +210,18 @@ $dbh->do( > > # CPL allows only its own patrons to request its items > $dbh->do( >- q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch) >- VALUES (?, ?, ?, ?)}, >+ q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch) >+ VALUES (?, ?, ?)}, > {}, >- $branch_1, 10, 1, 'homebranch', >+ $branch_1, 1, 'homebranch', > ); > > # ... while FPL allows anybody to request its items > $dbh->do( >- q{INSERT INTO default_branch_circ_rules (branchcode, maxissueqty, holdallowed, returnbranch) >- VALUES (?, ?, ?, ?)}, >+ q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, returnbranch) >+ VALUES (?, ?, ?)}, > {}, >- $branch_2, 10, 2, 'homebranch', >+ $branch_2, 2, 'homebranch', > ); > > # helper biblio for the bug 10272 regression test >-- >2.15.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 18925
:
65238
|
65239
|
65240
|
67024
|
67025
|
67026
|
67621
|
70992
|
70993
|
70994
|
70995
|
70996
|
71032
|
71033
|
71043
|
71044
|
71045
|
71046
|
71047
|
72225
|
72226
|
72227
|
72228
|
72229
|
77225
|
77226
|
77227
|
77228
|
77229
|
78881
|
78882
|
78883
|
78884
|
78885
|
78886
|
79642
|
79643
|
79644
|
79645
|
79646
|
81091
|
81092
|
81093
|
81094
|
81095
|
82927
|
82928
|
82929
|
82930
|
82931
|
85480
|
85481
|
85482
|
85483
|
85484
|
85485
|
85486
|
85939
|
85940
|
85941
|
85942
|
85943
|
85944
|
85945
|
85946
|
85947
|
85948
|
85949
|
85950
|
85951
|
85953
|
85954
|
85955
|
85956
|
85957
|
85958
|
85959
|
85960
|
85961
|
85962
|
85963
|
85964
|
85965
|
86068
|
86069
|
86070
|
86071
|
86072
|
86073
|
86074
|
86075
|
86076
|
86077
|
86078
|
86079
|
86080
|
86081
|
86121
|
86165
|
86206
|
86207