From f389f8f23d18c8d8755678d933d1ebe5d380fed2 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 11 Jul 2012 18:25:54 +0200 Subject: [PATCH] Bug 8418 - single_holidays DateTime::Set We where cargo-culting code from C4::Calendar, but in the process code executed same SQL query with isexceptional flag set each time. This basically disabled all entries on calendar without it, which is somewhat of a problem, since users currently can't add entry which does have isexception bit set. There is really no need for two separate DateTime::Set objects, since code for them is same if we remove isexception from query. Signed-off-by: Kyle M Hall --- Koha/Calendar.pm | 32 ++++++++------------------------ 1 files changed, 8 insertions(+), 24 deletions(-) diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm index 2435a7f..b7cb7c7 100644 --- a/Koha/Calendar.pm +++ b/Koha/Calendar.pm @@ -49,12 +49,13 @@ sub _init { 1; } my $special = $dbh->prepare( -'SELECT day, month, year, title, description FROM special_holidays WHERE ( branchcode = ? ) AND (isexception = ?)' +'SELECT day, month, year, title, description, isexception FROM special_holidays WHERE branchcode = ?' ); - $special->execute( $branch, 1 ); + $special->execute( $branch ); my $dates = []; - while ( my ( $day, $month, $year, $title, $description ) = + while ( my ( $day, $month, $year, $title, $description, $isexception ) = $special->fetchrow ) { + # FIXME $isexception is not used since users can't enter calendar entries with it push @{$dates}, DateTime->new( day => $day, @@ -63,21 +64,8 @@ sub _init { time_zone => C4::Context->tz() )->truncate( to => 'day' ); } - $self->{exception_holidays} = + $self->{special_holidays} = DateTime::Set->from_datetimes( dates => $dates ); - $special->execute( $branch, 1 ); - $dates = []; - while ( my ( $day, $month, $year, $title, $description ) = - $special->fetchrow ) { - push @{$dates}, - DateTime->new( - day => $day, - month => $month, - year => $year, - time_zone => C4::Context->tz() - )->truncate( to => 'day' ); - } - $self->{single_holidays} = DateTime::Set->from_datetimes( dates => $dates ); $self->{days_mode} = C4::Context->preference('useDaysMode'); return; } @@ -153,10 +141,7 @@ sub is_holiday { if ( exists $self->{day_month_closed_days}->{$day}->{$month} ) { return 1; } - if ( $self->{exception_holidays}->contains($dt) ) { - return 1; - } - if ( $self->{single_holidays}->contains($dt) ) { + if ( $self->{special_holidays}->contains($dt) ) { return 1; } @@ -210,8 +195,6 @@ sub _mockinit { $self->{weekly_closed_days} = [ 1, 0, 0, 0, 0, 0, 0 ]; # Sunday only $self->{day_month_closed_days} = { 16 => { 6 => 1, } }; my $dates = []; - $self->{exception_holidays} = - DateTime::Set->from_datetimes( dates => $dates ); my $special = DateTime->new( year => 2011, month => 6, @@ -219,7 +202,8 @@ sub _mockinit { time_zone => 'Europe/London', ); push @{$dates}, $special; - $self->{single_holidays} = DateTime::Set->from_datetimes( dates => $dates ); + $self->{special_holidays} = + DateTime::Set->from_datetimes( dates => $dates ); $self->{days_mode} = 'Calendar'; return; } -- 1.7.2.5