From e3116297a693447314d661298a5990b8a7c763d9 Mon Sep 17 00:00:00 2001 From: David Bourgault Date: Tue, 24 Jul 2018 16:53:19 -0400 Subject: [PATCH] Bug 17015: Fixes to migration script Fixes a few errors in the migration script. When first generation the discrete_calendar table, holidays should now be correctly imported for all branches. --- .../bug_17015_part2_fill_discrete_calendar.perl | 24 ++++++++-------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/installer/data/mysql/atomicupdate/bug_17015_part2_fill_discrete_calendar.perl b/installer/data/mysql/atomicupdate/bug_17015_part2_fill_discrete_calendar.perl index 8a2485f..e29c283 100755 --- a/installer/data/mysql/atomicupdate/bug_17015_part2_fill_discrete_calendar.perl +++ b/installer/data/mysql/atomicupdate/bug_17015_part2_fill_discrete_calendar.perl @@ -41,17 +41,14 @@ my $add_default_branch = 'INSERT IGNORE INTO branches (branchname, branchcode) V my $add_Branch_Sth = $dbh->prepare($add_default_branch); $add_Branch_Sth->execute('Default', ''); # finds branches; -my $selectBranchesSt = 'SELECT branchcode FROM branches'; +my $selectBranchesSt = 'SELECT branchname, branchcode FROM branches'; my $selectBranchesSth = $dbh->prepare($selectBranchesSt); $selectBranchesSth->execute(); my @branches = (); -for my $branchCode ( $selectBranchesSth->fetchrow_array ) { - print $branchCode . "\n"; - push @branches,$branchCode; +while (my @row = $selectBranchesSth->fetchrow_array ) { + print "[$row[1]] $row[0]\n"; + push @branches, $row[1]; } -print "REACH\n"; -print Dumper(\@branches); - # finds what days are closed for each branch my %repeatableHolidaysPerBranch = (); @@ -103,9 +100,6 @@ for (my $tempDate = $startDate->clone(); $tempDate <= $endDate;$tempDate->add(da # Representation fix # DateTime object dow (1-7) where Monday is 1 # Arrays are 0-based where 0 = Sunday, not 7. - $dayOfWeek -=1 unless $dayOfWeek ==7; - $dayOfWeek =0 if $dayOfWeek ==7; - my $open_hour = "09:00:00"; my $close_hour = "17:00:00"; @@ -113,13 +107,13 @@ for (my $tempDate = $startDate->clone(); $tempDate <= $endDate;$tempDate->add(da my $is_opened =1; my $specialDescription = ""; my $holiday_type =''; - $dayOfWeek = $tempDate->day_of_week; - foreach my $holidayWeekDay (@{$repeatableHolidaysPerBranch{$branch}}){ - if($holidayWeekDay->{weekday} && $dayOfWeek == $holidayWeekDay->{weekday}){ + $dayOfWeek = $tempDate->day_of_week % 7; + foreach my $holidayWeekDay ( @{$repeatableHolidaysPerBranch{$branch}} ) { + if (defined($holidayWeekDay) && $dayOfWeek == $holidayWeekDay->{weekday}) { $is_opened = 0; $specialDescription = $holidayWeekDay->{title}; $holiday_type = 'W'; - }elsif($holidayWeekDay->{day} && $holidayWeekDay->{month}){ + } elsif ($holidayWeekDay->{day} && $holidayWeekDay->{month}) { my $date = DateTime->new( day => $holidayWeekDay->{day}, month => $holidayWeekDay->{month}, @@ -136,7 +130,7 @@ for (my $tempDate = $startDate->clone(); $tempDate <= $endDate;$tempDate->add(da } foreach my $specialDate (@{$specialHolidaysPerBranch{$branch}}){ - if($tempDate->datetime() eq $specialDate->{date}->datetime() ){ + if ($tempDate->datetime() eq $specialDate->{date}->datetime()) { $is_opened = 0; $specialDescription = $specialDate->{title}; $holiday_type = 'E'; -- 2.7.4