From bf1f04371e90cb515bc571f3cfdf5a47917cceb8 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 12 Feb 2024 15:21:08 +0000 Subject: [PATCH] Bug 6796: Merge and correct database update Sponsored-by: PTFS Europe Signed-off-by: Martin Renvoize --- ...nsiderLibraryHoursInCirculation_syspref.pl | 16 ------------- .../bug_6796_-_add_library_hours_table.pl | 24 ++++++++++++++----- 2 files changed, 18 insertions(+), 22 deletions(-) delete mode 100755 installer/data/mysql/atomicupdate/bug_6796_-_add_ConsiderLibraryHoursInCirculation_syspref.pl diff --git a/installer/data/mysql/atomicupdate/bug_6796_-_add_ConsiderLibraryHoursInCirculation_syspref.pl b/installer/data/mysql/atomicupdate/bug_6796_-_add_ConsiderLibraryHoursInCirculation_syspref.pl deleted file mode 100755 index 823504319ae..00000000000 --- a/installer/data/mysql/atomicupdate/bug_6796_-_add_ConsiderLibraryHoursInCirculation_syspref.pl +++ /dev/null @@ -1,16 +0,0 @@ -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 ( 'ConsiderLibraryHoursInCirculation', 'ignore', 'close|open|ignore', "Take library opening hours into consideration to calculate due date when circulating.", 'Choice' ) } - ); - - say $out "Added system preference 'ConsiderLibraryHoursInCirculation'"; - }, -}; diff --git a/installer/data/mysql/atomicupdate/bug_6796_-_add_library_hours_table.pl b/installer/data/mysql/atomicupdate/bug_6796_-_add_library_hours_table.pl index f3a506c806d..68320352556 100755 --- a/installer/data/mysql/atomicupdate/bug_6796_-_add_library_hours_table.pl +++ b/installer/data/mysql/atomicupdate/bug_6796_-_add_library_hours_table.pl @@ -21,15 +21,27 @@ return { } ); - my @indexes = ( 0 .. 6 ); - for my $i (@indexes) { - $dbh->do( - q{ INSERT INTO library_hours (library_id, day) SELECT branchcode, ? FROM branches }, undef, - $i - ); + my $branches = + $dbh->selectall_arrayref( "SELECT branchcode FROM branches", { Slice => {} } ); + for my $branch (@$branches) { + my $branchcode = $branch->{branchcode}; + + my @indexes = ( 0 .. 6 ); + for my $i (@indexes) { + $dbh->do( + q{ INSERT INTO library_hours (library_id, day) VALUES ( ?, ? ) }, undef, $branchcode, + $i + ); + } } say $out "Added table `library_hours`"; + + $dbh->do( + q{ INSERT IGNORE INTO systempreferences ( variable, value, options, explanation, type ) VALUES ( 'ConsiderLibraryHoursInCirculation', 'ignore', 'close|open|ignore', "Take library opening hours into consideration to calculate due date when circulating.", 'Choice' ) } + ); + + say $out "Added system preference 'ConsiderLibraryHoursInCirculation'"; } }, }; -- 2.43.0