From bf219ca50a929d793197c1dd392e1a8da8e379bd Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Wed, 6 Aug 2025 19:14:56 +0000 Subject: [PATCH] Bug 36506: Database update Sponsored-by: The Main Library Alliance --- .../data/mysql/atomicupdate/bug_36506.pl | 41 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 1 - 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100755 installer/data/mysql/atomicupdate/bug_36506.pl diff --git a/installer/data/mysql/atomicupdate/bug_36506.pl b/installer/data/mysql/atomicupdate/bug_36506.pl new file mode 100755 index 00000000000..20106703c04 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_36506.pl @@ -0,0 +1,41 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_success say_info); + +return { + bug_number => "36506", + description => "Move itemtype processing fees to the circulation rules", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + if ( column_exists( 'itemtypes', 'processfee' ) ) { + my $existing_fees = $dbh->selectall_arrayref( + q|SELECT itemtype, processfee FROM itemtypes WHERE processfee IS NOT NULL|, + { Slice => {} } + ); + foreach my $existing_fee ( @{$existing_fees} ) { + my $itemtype = $existing_fee->{itemtype}; + my $fee = $existing_fee->{processfee}; + my $existing_rule = $dbh->selectall_arrayref( + q|SELECT * FROM circulation_rules WHERE branchcode IS NULL AND categorycode IS NULL + AND rule_name = "lost_item_processing_fee" AND itemtype = ?|, undef, $itemtype + ); + if ( @{$existing_rule} ) { + say_warning( $out, "Existing default rule for $itemtype found, not moving value from itemtypes" ); + next; + } + $dbh->do( + q{ + INSERT INTO circulation_rules (branchcode, categorycode, itemtype, rule_name, rule_value ) + VALUES ( NULL, NULL, ?, "lost_item_processing_fee", ? ) + }, undef, $itemtype, $fee + ); + } + say $out "Moved existing processing fees from itemtypes to circulation rules"; + + $dbh->do('ALTER TABLE itemtypes DROP COLUMN processfee'); + say $out "Removed existing processfee column from itemtypes"; + } + + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index e391dc68f5d..ac6d3275efd 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -4233,7 +4233,6 @@ CREATE TABLE `itemtypes` ( `rentalcharge_hourly` decimal(28,6) DEFAULT NULL COMMENT 'the amount charged for each hour between checkout date and due date', `rentalcharge_hourly_calendar` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'controls if the hourly rental fee is calculated directly or using finesCalendar', `defaultreplacecost` decimal(28,6) DEFAULT NULL COMMENT 'default replacement cost', - `processfee` decimal(28,6) DEFAULT NULL COMMENT 'default text be recorded in the column note when the processing fee is applied', `notforloan` tinyint(1) NOT NULL DEFAULT 0 COMMENT '1 if the item is not for loan, 0 if the item is available for loan', `imageurl` varchar(200) DEFAULT NULL COMMENT 'URL for the item type icon', `summary` mediumtext DEFAULT NULL COMMENT 'information from the summary field, may include HTML', -- 2.39.5