From 538e18cc978e59733730d6a677bf569455e600ca Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Wed, 12 Jul 2017 10:55:08 -0400 Subject: [PATCH] Bug 18930: Move lost item refund rules to circulation_rules table This patch will move the list item refund rules from a dedicated table to the circulation_rules table. Test Plan: 1) Apply this patch 2) Run updatedatabase.pl 3) Verify lost item refund rules remain unchanged --- C4/Circulation.pm | 1 - Koha/RefundLostItemFeeRule.pm | 45 ---- Koha/RefundLostItemFeeRules.pm | 30 ++- Koha/Schema/Result/RefundLostItemFeeRule.pm | 66 ------ admin/smart-rules.pl | 35 +-- installer/data/mysql/atomicupdate/bug_18930.perl | 14 ++ .../prog/en/modules/admin/smart-rules.tt | 8 +- t/db_dependent/RefundLostItemFeeRule.t | 258 ++++++++++++++------- 8 files changed, 235 insertions(+), 222 deletions(-) delete mode 100644 Koha/RefundLostItemFeeRule.pm delete mode 100644 Koha/Schema/Result/RefundLostItemFeeRule.pm create mode 100644 installer/data/mysql/atomicupdate/bug_18930.perl diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 1126bdc7fa..7ee77df2af 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -54,7 +54,6 @@ use Koha::Database; use Koha::Libraries; use Koha::Account::Lines; use Koha::Holds; -use Koha::RefundLostItemFeeRule; use Koha::RefundLostItemFeeRules; use Koha::Account::Lines; use Koha::Account::Offsets; diff --git a/Koha/RefundLostItemFeeRule.pm b/Koha/RefundLostItemFeeRule.pm deleted file mode 100644 index 56e4d93f82..0000000000 --- a/Koha/RefundLostItemFeeRule.pm +++ /dev/null @@ -1,45 +0,0 @@ -package Koha::RefundLostItemFeeRule; - -# Copyright Theke Solutions 2016 -# -# 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 Koha::Database; -use Koha::Exceptions; - -use base qw(Koha::Object); - -=head1 NAME - -Koha::RefundLostItemFeeRule - Koha RefundLostItemFeeRule object class - -=head1 API - -=head2 Class Methods - -=cut - -=head3 type - -=cut - -sub _type { - return 'RefundLostItemFeeRule'; -} - -1; diff --git a/Koha/RefundLostItemFeeRules.pm b/Koha/RefundLostItemFeeRules.pm index 2e83c76f9c..b08ac1179d 100644 --- a/Koha/RefundLostItemFeeRules.pm +++ b/Koha/RefundLostItemFeeRules.pm @@ -22,9 +22,9 @@ use Modern::Perl; use Koha::Database; use Koha::Exceptions; -use Koha::RefundLostItemFeeRule; +use Koha::CirculationRule; -use base qw(Koha::Objects); +use base qw(Koha::CirculationRules); =head1 NAME @@ -41,7 +41,7 @@ Koha::RefundLostItemFeeRules - Koha RefundLostItemFeeRules object set class =cut sub _type { - return 'RefundLostItemFeeRule'; + return 'CirculationRule'; } =head3 object_class @@ -49,7 +49,7 @@ sub _type { =cut sub object_class { - return 'Koha::RefundLostItemFeeRule'; + return 'Koha::CirculationRule'; } =head3 should_refund @@ -84,10 +84,17 @@ sub _effective_branch_rule { my $self = shift; my $branch = shift; - my $specific_rule = $self->find({ branchcode => $branch }); + my $specific_rule = $self->search( + { + branchcode => $branch, + categorycode => undef, + itemtype => undef, + rule_name => 'refund', + } + )->next(); return ( defined $specific_rule ) - ? $specific_rule->refund + ? $specific_rule->rule_value : $self->_default_rule; } @@ -139,10 +146,17 @@ item fees on return. It defaults to 1 if no rule is defined. sub _default_rule { my $self = shift; - my $default_rule = $self->find({ branchcode => '*' }); + my $default_rule = $self->search( + { + branchcode => '*', + categorycode => undef, + itemtype => undef, + rule_name => 'refund', + } + )->next(); return (defined $default_rule) - ? $default_rule->refund + ? $default_rule->rule_value : 1; } diff --git a/Koha/Schema/Result/RefundLostItemFeeRule.pm b/Koha/Schema/Result/RefundLostItemFeeRule.pm deleted file mode 100644 index 30ae5804d9..0000000000 --- a/Koha/Schema/Result/RefundLostItemFeeRule.pm +++ /dev/null @@ -1,66 +0,0 @@ -use utf8; -package Koha::Schema::Result::RefundLostItemFeeRule; - -# Created by DBIx::Class::Schema::Loader -# DO NOT MODIFY THE FIRST PART OF THIS FILE - -=head1 NAME - -Koha::Schema::Result::RefundLostItemFeeRule - -=cut - -use strict; -use warnings; - -use base 'DBIx::Class::Core'; - -=head1 TABLE: C - -=cut - -__PACKAGE__->table("refund_lost_item_fee_rules"); - -=head1 ACCESSORS - -=head2 branchcode - - data_type: 'varchar' - default_value: (empty string) - is_nullable: 0 - size: 10 - -=head2 refund - - data_type: 'tinyint' - default_value: 0 - is_nullable: 0 - -=cut - -__PACKAGE__->add_columns( - "branchcode", - { data_type => "varchar", default_value => "", is_nullable => 0, size => 10 }, - "refund", - { data_type => "tinyint", default_value => 0, is_nullable => 0 }, -); - -=head1 PRIMARY KEY - -=over 4 - -=item * L - -=back - -=cut - -__PACKAGE__->set_primary_key("branchcode"); - - -# Created by DBIx::Class::Schema::Loader v0.07042 @ 2016-05-31 02:45:35 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:K+2D3R+JxrovgvjdqA8xdw - - -# You can replace this text with custom code or comments, and it will be preserved on regeneration -1; diff --git a/admin/smart-rules.pl b/admin/smart-rules.pl index ba5b923d86..adad556e51 100755 --- a/admin/smart-rules.pl +++ b/admin/smart-rules.pl @@ -29,7 +29,6 @@ use Koha::Database; use Koha::IssuingRule; use Koha::IssuingRules; use Koha::Logger; -use Koha::RefundLostItemFeeRule; use Koha::RefundLostItemFeeRules; use Koha::Libraries; use Koha::CirculationRules; @@ -510,22 +509,28 @@ elsif ( $op eq 'mod-refund-lost-item-fee-rule' ) { if ( $refund eq '*' ) { if ( $branch ne '*' ) { # only do something for $refund eq '*' if branch-specific - eval { - # Delete it so it picks the default - Koha::RefundLostItemFeeRules->find({ - branchcode => $branch - })->delete; - }; + Koha::CirculationRules->set_rules( + { + categorycode => undef, + itemtype => undef, + branchcode => $branch, + rules => { + refund => undef + } + } + ); } } else { - my $refundRule = - Koha::RefundLostItemFeeRules->find({ - branchcode => $branch - }) // Koha::RefundLostItemFeeRule->new; - $refundRule->set({ - branchcode => $branch, - refund => $refund - })->store; + Koha::CirculationRules->set_rules( + { + categorycode => undef, + itemtype => undef, + branchcode => $branch, + rules => { + refund => $refund + } + } + ); } } diff --git a/installer/data/mysql/atomicupdate/bug_18930.perl b/installer/data/mysql/atomicupdate/bug_18930.perl new file mode 100644 index 0000000000..3426d994fa --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_18930.perl @@ -0,0 +1,14 @@ +$DBversion = 'XXX'; # will be replaced by the RM +if( CheckVersion( $DBversion ) ) { + if ( column_exists( 'refund_lost_item_fee_rules', 'refund' ) ) { + $dbh->do(" + INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value ) + SELECT NULL, branchcode, NULL, 'refund', refund + FROM refund_lost_item_fee_rules + "); + $dbh->do("DROP TABLE refund_lost_item_fee_rules"); + } + + SetVersion( $DBversion ); + print "Upgrade to $DBversion done (Bug 18930 - Move lost item refund rules to circulation_rules table)\n"; +} 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 020fe1fdc7..49c260b4fb 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 @@ -633,14 +633,14 @@