From 0fc15fdb7105a49a35f157c7b690b571aa8646cd 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. Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart (cherry picked from commit e708566e729239ed7857c357ee53419c44742ddd) Signed-off-by: Lucas Gass --- 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 c6e82bd843..65aa508eaf 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -898,9 +898,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 7a75277f32..9f249dc6a1 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.39.5