From b5690043709cd9d481d1410de57955b5c74145b9 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Sun, 30 Apr 2023 22:47:31 +0000 Subject: [PATCH] Bug 6796: Fix atomic updates Signed-off-by: Sam Lau --- ...nsiderLibraryHoursWhenIssuing_syspref.perl | 5 ---- ...ConsiderLibraryHoursWhenIssuing_syspref.pl | 14 +++++++++ .../bug_6796_-_add_branch_hours_table.perl | 20 ------------- .../bug_6796_-_add_branch_hours_table.pl | 30 +++++++++++++++++++ 4 files changed, 44 insertions(+), 25 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_6796_-_add_ConsiderLibraryHoursWhenIssuing_syspref.perl create mode 100644 installer/data/mysql/atomicupdate/bug_6796_-_add_ConsiderLibraryHoursWhenIssuing_syspref.pl delete mode 100644 installer/data/mysql/atomicupdate/bug_6796_-_add_branch_hours_table.perl create mode 100644 installer/data/mysql/atomicupdate/bug_6796_-_add_branch_hours_table.pl diff --git a/installer/data/mysql/atomicupdate/bug_6796_-_add_ConsiderLibraryHoursWhenIssuing_syspref.perl b/installer/data/mysql/atomicupdate/bug_6796_-_add_ConsiderLibraryHoursWhenIssuing_syspref.perl deleted file mode 100644 index 927ae33178..0000000000 --- a/installer/data/mysql/atomicupdate/bug_6796_-_add_ConsiderLibraryHoursWhenIssuing_syspref.perl +++ /dev/null @@ -1,5 +0,0 @@ -$DBversion = 'XXX'; -if ( CheckVersion( $DBversion ) ) { - $dbh->do(q{ INSERT IGNORE INTO systempreferences ( variable, value, options, explanation, type ) VALUES ( 'ConsiderLibraryHoursWhenIssuing', 'ignore', 'close|open|ignore', "Take library opening hours into consideration to calculate due date when issuing.", 'Choice' ) }); - NewVersion( $DBversion, 6796, "Add ConsiderLibraryHoursWhenIssuing system preference" ); -} diff --git a/installer/data/mysql/atomicupdate/bug_6796_-_add_ConsiderLibraryHoursWhenIssuing_syspref.pl b/installer/data/mysql/atomicupdate/bug_6796_-_add_ConsiderLibraryHoursWhenIssuing_syspref.pl new file mode 100644 index 0000000000..2c230febeb --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_6796_-_add_ConsiderLibraryHoursWhenIssuing_syspref.pl @@ -0,0 +1,14 @@ +use Modern::Perl; + +return { + bug_number => "6796", + description => "Overnight checkouts taking into account opening and closing hours", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + + $dbh->do(q{ INSERT IGNORE INTO systempreferences ( variable, value, options, explanation, type ) VALUES ( 'ConsiderLibraryHoursWhenIssuing', 'ignore', 'close|open|ignore', "Take library opening hours into consideration to calculate due date when issuing.", 'Choice' ) }); + + say $out "Added system preference 'ConsiderLibraryHoursWhenIssuing'"; + }, +}; diff --git a/installer/data/mysql/atomicupdate/bug_6796_-_add_branch_hours_table.perl b/installer/data/mysql/atomicupdate/bug_6796_-_add_branch_hours_table.perl deleted file mode 100644 index 964da04c61..0000000000 --- a/installer/data/mysql/atomicupdate/bug_6796_-_add_branch_hours_table.perl +++ /dev/null @@ -1,20 +0,0 @@ -$DBversion = 'XXX'; -if ( CheckVersion( $DBversion ) ) { - $dbh->do(q{ DROP TABLE IF EXISTS branch_hours }); - $dbh->do(q{ - CREATE TABLE branch_hours ( - branchcode varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL, - day int(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 0, - open_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL, - close_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL, - PRIMARY KEY (branchcode, day), - CONSTRAINT branch_hours_ibfk_1 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - }); - - my @indexes = (0..6); - for my $i (@indexes) { - $dbh->do(q{ INSERT INTO branch_hours (branchcode, day) SELECT branchcode, ? FROM branches }, undef, $i); - } - NewVersion( $DBversion, 6796, "Add branch_hours table" ); -} diff --git a/installer/data/mysql/atomicupdate/bug_6796_-_add_branch_hours_table.pl b/installer/data/mysql/atomicupdate/bug_6796_-_add_branch_hours_table.pl new file mode 100644 index 0000000000..e33503257c --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_6796_-_add_branch_hours_table.pl @@ -0,0 +1,30 @@ +use Modern::Perl; + +return { + bug_number => "6796", + description => "Overnight checkouts taking into account opening and closing hours", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + + unless( TableExists('branch_hours') ) { + $dbh->do(q{ + CREATE TABLE branch_hours ( + branchcode varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL, + day int(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 0, + open_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL, + close_time time COLLATE utf8mb4_unicode_ci DEFAULT NULL, + PRIMARY KEY (branchcode, day), + CONSTRAINT branch_hours_ibfk_1 FOREIGN KEY (branchcode) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + }); + + my @indexes = (0..6); + for my $i (@indexes) { + $dbh->do(q{ INSERT INTO branch_hours (branchcode, day) SELECT branchcode, ? FROM branches }, undef, $i); + } + + say $out "Added table `branch_hours`"; + } + }, +}; -- 2.30.2