From 8bb9ba3465ff966b9e4eb219557b6516f92670b0 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 1 Sep 2020 10:42:47 -0400 Subject: [PATCH] Bug 26341: Database update for bug 21443 is not idempotent and will destroy settings If the database update for bug 21443 is run, and the library changes any of the hourly or daily rental fees following the calendar, a second run of the database update will overwrite those changes. --- installer/data/mysql/kohastructure.sql | 4 ++-- installer/data/mysql/updatedatabase.pl | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 0316e4be19..bfae55f0e4 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -904,9 +904,9 @@ CREATE TABLE `itemtypes` ( -- defines the item types description LONGTEXT, -- a plain text explanation of the item type rentalcharge decimal(28,6) default NULL, -- the amount charged when this item is checked out/issued rentalcharge_daily decimal(28,6) default NULL, -- the amount charged for each day between checkout date and due date - rentalcharge_daily_calendar tinyint(1) NOT NULL DEFAULT 1, -- controls if the daily retnal fee is calculated directly or using finesCalendar + rentalcharge_daily_calendar tinyint(1) NOT NULL DEFAULT 1, -- controls if the daily rental fee is calculated directly or using finesCalendar rentalcharge_hourly decimal(28,6) default NULL, -- the amount charged for each hour between checkout date and due date - rentalcharge_hourly_calendar tinyint(1) NOT NULL DEFAULT 1, -- controls if the hourly retnal fee is calculated directly or using finesCalendar + rentalcharge_hourly_calendar tinyint(1) NOT NULL DEFAULT 1, -- controls if the hourly rental fee is calculated directly or using finesCalendar defaultreplacecost decimal(28,6) default NULL, -- default replacement cost processfee decimal(28,6) default NULL, -- default text be recorded in the column note when the processing fee is applied notforloan smallint(6) default NULL, -- 1 if the item is not for loan, 0 if the item is available for loan diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 0a068f3f46..66b5cabc04 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -21260,12 +21260,17 @@ if( CheckVersion( $DBversion ) ) { $DBversion = '19.12.00.052'; if( CheckVersion( $DBversion ) ) { + my $finesCalendar = C4::Context->preference('finesCalendar'); + my $value = $finesCalendar eq 'noFinesWhenClosed' ? 1 : 0; + if( !column_exists( 'itemtypes', 'rentalcharge_daily_calendar' ) ) { $dbh->do(q{ ALTER TABLE itemtypes ADD COLUMN rentalcharge_daily_calendar tinyint(1) NOT NULL DEFAULT 1 AFTER rentalcharge_daily; }); + + $dbh->do("UPDATE itemtypes SET rentalcharge_daily_calendar = $value"); } if( !column_exists( 'itemtypes', 'rentalcharge_hourly_calendar' ) ) { @@ -21274,11 +21279,9 @@ if( CheckVersion( $DBversion ) ) { rentalcharge_hourly_calendar tinyint(1) NOT NULL DEFAULT 1 AFTER rentalcharge_hourly; }); - } - my $finesCalendar = C4::Context->preference('finesCalendar'); - my $value = $finesCalendar eq 'noFinesWhenClosed' ? 1 : 0; - $dbh->do("UPDATE itemtypes SET rentalcharge_hourly_calendar = $value, rentalcharge_daily_calendar = $value"); + $dbh->do("UPDATE itemtypes SET rentalcharge_hourly_calendar = $value"); + } NewVersion( $DBversion, 21443, "Add ability to exclude holidays when calculating rentals fees by time period"); } -- 2.24.1 (Apple Git-126)