@@ -, +, @@ --- Koha/CirculationRule.pm | 10 + Koha/CirculationRules.pm | 30 +- Koha/Schema/Result/CirculationRule.pm | 11 +- admin/smart-rules.pl | 29 +- .../Bug_8137-add-column-has_priority.sql | 7 +- installer/data/mysql/kohastructure.sql | 11 +- .../prog/en/modules/admin/smart-rules.tt | 288 +++++++++--------- t/db_dependent/Circulation/Branch.t | 50 ++- t/db_dependent/Koha/IssuingRules.t | 22 +- 9 files changed, 259 insertions(+), 199 deletions(-) --- a/Koha/CirculationRule.pm +++ a/Koha/CirculationRule.pm @@ -71,6 +71,16 @@ sub item_type { return $self->{item_type}; } +=head3 priority + +=cut + +sub priority { + my ($self) = @_; + + return $self->has_priority; +} + =head3 clone Clone a circulation rule to another branch --- a/Koha/CirculationRules.pm +++ a/Koha/CirculationRules.pm @@ -63,9 +63,6 @@ our $RULE_KINDS = { max_holds => { scope => [ 'branchcode', 'categorycode' ], }, - has_priority => { - scope => [ 'branchcode', 'categorycode' ], - }, holdallowed => { scope => [ 'branchcode', 'itemtype' ], can_be_blank => 0, @@ -254,15 +251,12 @@ sub get_effective_rule { } my $order_by = $params->{order_by} - // { -desc => [ 'branchcode', 'categorycode', 'itemtype' ] }; + // { -desc => [ 'has_priority', 'branchcode', 'categorycode', 'itemtype' ] }; my $search_params; $search_params->{rule_name} = $rule_name; - $search_params->{categorycode} = defined $categorycode ? [ $categorycode, undef ] : undef; - $search_params->{itemtype} = defined $itemtype ? [ $itemtype, undef ] : undef; - $search_params->{branchcode} = defined $branchcode ? [ $branchcode, undef ] : undef; - $search_params->{has_priority} = defined $has_priority ? [ $has_priority, undef ] : undef; + $search_params->{has_priority} = 1; my $rule = $self->search( $search_params, @@ -272,6 +266,20 @@ sub get_effective_rule { } )->single; + return $rule if defined $rule; + + $search_params->{itemtype} = defined $itemtype ? [ $itemtype, undef ] : undef; + $search_params->{has_priority} = defined $has_priority ? [ $has_priority, undef ] : undef; + $search_params->{branchcode} = defined $branchcode ? [ $branchcode, undef ] : undef; + + $rule = $self->search( + $search_params, + { + order_by => $order_by, + rows => 1, + } + )->single; + return $rule; } @@ -376,6 +384,7 @@ sub set_rule { my $branchcode = $params->{branchcode}; my $categorycode = $params->{categorycode}; my $itemtype = $params->{itemtype}; + my $has_priority = $params->{has_priority}; my $rule_name = $params->{rule_name}; my $rule_value = $params->{rule_value}; my $can_be_blank = defined $kind_info->{can_be_blank} ? $kind_info->{can_be_blank} : 1; @@ -390,6 +399,7 @@ sub set_rule { branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype, + has_priority => $has_priority, } )->next(); @@ -409,6 +419,7 @@ sub set_rule { branchcode => $branchcode, categorycode => $categorycode, itemtype => $itemtype, + has_priority => $has_priority, rule_name => $rule_name, rule_value => $rule_value, } @@ -436,7 +447,8 @@ sub set_rules { $set_params{branchcode} = $params->{branchcode} if exists $params->{branchcode}; $set_params{categorycode} = $params->{categorycode} if exists $params->{categorycode}; $set_params{itemtype} = $params->{itemtype} if exists $params->{itemtype}; - my $rules = $params->{rules}; + $set_params{has_priority} = $params->{has_priority} if exists $params->{has_priority}; + my $rules = $params->{rules}; my $rule_objects = []; while ( my ( $rule_name, $rule_value ) = each %$rules ) { --- a/Koha/Schema/Result/CirculationRule.pm +++ a/Koha/Schema/Result/CirculationRule.pm @@ -50,6 +50,11 @@ __PACKAGE__->table("circulation_rules"); is_nullable: 1 size: 10 +=head2 has_priority + + data_type: 'integer' + is_nullable: 1 + =head2 rule_name data_type: 'varchar' @@ -73,6 +78,8 @@ __PACKAGE__->add_columns( { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 }, "itemtype", { data_type => "varchar", is_foreign_key => 1, is_nullable => 1, size => 10 }, + "has_priority", + { data_type => "integer", is_nullable => 1, is_boolean => 1 }, "rule_name", { data_type => "varchar", is_nullable => 0, size => 32 }, "rule_value", @@ -177,8 +184,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-10-05 14:29:17 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:QHMqvrtX0ohJe70PHUYZ0Q +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2020-07-22 13:19:28 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:1mg3weVQdfPTJ+jX6X5K+Q sub koha_objects_class { 'Koha::CirculationRules'; --- a/admin/smart-rules.pl +++ a/admin/smart-rules.pl @@ -70,12 +70,15 @@ $cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY ); if ($op eq 'delete') { my $itemtype = $input->param('itemtype'); my $categorycode = $input->param('categorycode'); + my $has_priority = $input->param('has_priority') ? 1 : undef; + $debug and warn "deleting $1 $2 $branch"; Koha::CirculationRules->set_rules( { categorycode => $categorycode eq '*' ? undef : $categorycode, branchcode => $branch eq '*' ? undef : $branch, itemtype => $itemtype eq '*' ? undef : $itemtype, + has_priority => $has_priority, rules => { maxissueqty => undef, maxonsiteissueqty => undef, @@ -121,12 +124,14 @@ if ($op eq 'delete') { } elsif ($op eq 'delete-branch-cat') { my $categorycode = $input->param('categorycode'); + my $has_priority = $input->param('has_priority') ? 1 : undef; if ($branch eq "*") { if ($categorycode eq "*") { Koha::CirculationRules->set_rules( { branchcode => undef, categorycode => undef, + has_priority => $has_priority, rules => { max_holds => undef, patron_maxissueqty => undef, @@ -150,6 +155,7 @@ elsif ($op eq 'delete-branch-cat') { { categorycode => $categorycode, branchcode => undef, + has_priority => $has_priority, rules => { max_holds => undef, patron_maxissueqty => undef, @@ -163,6 +169,7 @@ elsif ($op eq 'delete-branch-cat') { { branchcode => $branch, categorycode => undef, + has_priority => $has_priority, rules => { max_holds => undef, patron_maxissueqty => undef, @@ -186,6 +193,7 @@ elsif ($op eq 'delete-branch-cat') { { categorycode => $categorycode, branchcode => $branch, + has_priority => $has_priority, rules => { max_holds => undef, patron_maxissueqty => undef, @@ -254,7 +262,7 @@ elsif ($op eq 'add') { my $br = $branch; # branch my $bor = $input->param('categorycode'); # borrower category my $itemtype = $input->param('itemtype'); # item type - my $has_priority = $input->param('has_priority') ? 1 : 0; + my $has_priority = $input->param('has_priority') ? 1 : undef; my $fine = $input->param('fine'); my $finedays = $input->param('finedays'); my $maxsuspensiondays = $input->param('maxsuspensiondays') || q{}; @@ -301,7 +309,6 @@ elsif ($op eq 'add') { maxissueqty => $maxissueqty, maxonsiteissueqty => $maxonsiteissueqty, rentaldiscount => $rentaldiscount, - has_priority => $has_priority, fine => $fine, finedays => $finedays, maxsuspensiondays => $maxsuspensiondays, @@ -344,7 +351,7 @@ elsif ($op eq 'add') { categorycode => $bor eq '*' ? undef : $bor, itemtype => $itemtype eq '*' ? undef : $itemtype, branchcode => $br eq '*' ? undef : $br, - has_priority => $has_priority, + has_priority => $has_priority, rules => $rules, } ); @@ -359,12 +366,14 @@ elsif ($op eq "set-branch-defaults") { my $hold_fulfillment_policy = $input->param('hold_fulfillment_policy'); my $returnbranch = $input->param('returnbranch'); my $max_holds = strip_non_numeric( scalar $input->param('max_holds') ); + my $has_priority = $input->param('has_priority') ? 1 : undef; if ($branch eq "*") { Koha::CirculationRules->set_rules( { itemtype => undef, branchcode => undef, + has_priority => $has_priority, rules => { holdallowed => $holdallowed, hold_fulfillment_policy => $hold_fulfillment_policy, @@ -376,9 +385,11 @@ elsif ($op eq "set-branch-defaults") { { categorycode => undef, branchcode => undef, + has_priority => $has_priority, rules => { patron_maxissueqty => $patron_maxissueqty, patron_maxonsiteissueqty => $patron_maxonsiteissueqty, + patron_has_priority => $has_priority, } } ); @@ -387,6 +398,7 @@ elsif ($op eq "set-branch-defaults") { { itemtype => undef, branchcode => $branch, + has_priority => $has_priority, rules => { holdallowed => $holdallowed, hold_fulfillment_policy => $hold_fulfillment_policy, @@ -398,6 +410,7 @@ elsif ($op eq "set-branch-defaults") { { categorycode => undef, branchcode => $branch, + has_priority => $has_priority, rules => { patron_maxissueqty => $patron_maxissueqty, patron_maxonsiteissueqty => $patron_maxonsiteissueqty, @@ -430,6 +443,7 @@ elsif ($op eq "add-branch-cat") { { categorycode => undef, branchcode => undef, + has_priority => $has_priority, rules => { max_holds => $max_holds, patron_maxissueqty => $patron_maxissueqty, @@ -443,11 +457,11 @@ elsif ($op eq "add-branch-cat") { { categorycode => $categorycode, branchcode => undef, + has_priority => $has_priority, rules => { max_holds => $max_holds, patron_maxissueqty => $patron_maxissueqty, patron_maxonsiteissueqty => $patron_maxonsiteissueqty, - has_priority => $has_priority, } } ); @@ -457,11 +471,11 @@ elsif ($op eq "add-branch-cat") { { categorycode => undef, branchcode => $branch, + has_priority => $has_priority, rules => { max_holds => $max_holds, patron_maxissueqty => $patron_maxissueqty, patron_maxonsiteissueqty => $patron_maxonsiteissueqty, - has_priority => $has_priority, } } ); @@ -470,11 +484,11 @@ elsif ($op eq "add-branch-cat") { { categorycode => $categorycode, branchcode => $branch, + has_priority => $has_priority, rules => { max_holds => $max_holds, patron_maxissueqty => $patron_maxissueqty, patron_maxonsiteissueqty => $patron_maxonsiteissueqty, - has_priority => $has_priority, } } ); @@ -747,7 +761,8 @@ my $definedbranch = $all_rules->count ? 1 : 0; my $rules = {}; while ( my $r = $all_rules->next ) { $r = $r->unblessed; - $rules->{ $r->{categorycode} // q{} }->{ $r->{itemtype} // q{} }->{ $r->{rule_name} } = $r->{rule_value}; + $rules->{ $r->{categorycode} // '' }->{ $r->{itemtype} // '' }->{ $r->{rule_name} } = $r->{rule_value}; + $rules->{ $r->{categorycode} // '' }->{ $r->{itemtype} // '' }->{ 'has_priority' } = $r->{has_priority}; } $template->param(show_branch_cat_rule_form => 1); --- a/installer/data/mysql/atomicupdate/Bug_8137-add-column-has_priority.sql +++ a/installer/data/mysql/atomicupdate/Bug_8137-add-column-has_priority.sql @@ -1,5 +1,2 @@ -ALTER TABLE default_borrower_circ_rules ADD has_priority INT(1) DEFAULT 0; -ALTER TABLE default_borrower_circ_rules DROP foreign key borrower_borrower_circ_rules_ibfk_1; -ALTER TABLE default_borrower_circ_rules DROP primary key; -ALTER TABLE default_borrower_circ_rules ADD primary key(categorycode, has_priority); -ALTER TABLE default_borrower_circ_rules ADD CONSTRAINT borrower_borrower_circ_rules_ibfk_1 FOREIGN KEY (categorycode) REFERENCES categories (categorycode) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE circulation_rules ADD has_priority INT(1) DEFAULT NULL AFTER itemtype; +ALTER TABLE circulation_rules ADD KEY (branchcode , categorycode, itemtype, has_priority); --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -1782,11 +1782,12 @@ DROP TABLE IF EXISTS `circulation_rules`; /*!40101 SET character_set_client = utf8 */; CREATE TABLE `circulation_rules` ( `id` int(11) NOT NULL AUTO_INCREMENT, - `branchcode` varchar(10) DEFAULT NULL, - `categorycode` varchar(10) DEFAULT NULL, - `itemtype` varchar(10) DEFAULT NULL, - `rule_name` varchar(32) NOT NULL, - `rule_value` varchar(32) NOT NULL, + `branchcode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `categorycode` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `itemtype` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + `has_priority` tinyint(1) NULL default NULL, + `rule_name` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL, + `rule_value` varchar(32) COLLATE utf8mb4_unicode_ci NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `branchcode` (`branchcode`,`categorycode`,`itemtype`,`rule_name`), KEY `circ_rules_ibfk_2` (`categorycode`), --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt @@ -112,94 +112,79 @@
For this library, you can specify the maximum number of loans that - a patron of a given category can make, regardless of the item type. -
-If the total amount loanable for a given patron category is left blank, - no limit applies, except possibly for a limit you define for a specific item type. -
- +For this library, you can specify the maximum number of loans that + a patron of a given category can make, regardless of the item type. +
+If the total amount loanable for a given patron category is left blank, + no limit applies, except possibly for a limit you define for a specific item type. +
++ Has priority: If checked, the rule will override those for all branches. Else + it behaves like a default one: used if no rule exists for the coresponding branch. +
+