Bugzilla – Attachment 71638 Details for
Bug 17015
New Koha Calendar
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17015 - Remove old Koha::Calendar
Bug-17015---Remove-old-KohaCalendar.patch (text/plain), 55.52 KB, created by
David Bourgault
on 2018-02-14 19:18:48 UTC
(
hide
)
Description:
Bug 17015 - Remove old Koha::Calendar
Filename:
MIME Type:
Creator:
David Bourgault
Created:
2018-02-14 19:18:48 UTC
Size:
55.52 KB
patch
obsolete
>From d6b3e414c0661fd9715b52ca4839b62ba63223c9 Mon Sep 17 00:00:00 2001 >From: David Bourgault <david.bourgault@inlibro.com> >Date: Wed, 14 Feb 2018 14:03:33 -0500 >Subject: [PATCH] Bug 17015 - Remove old Koha::Calendar > >--- > Koha/Calendar.pm | 535 --------------------- > .../intranet-tmpl/prog/en/includes/tools-menu.inc | 2 +- > .../prog/en/modules/tools/tools-home.tt | 7 +- > t/Calendar.t | 327 ------------- > t/db_dependent/Calendar.t | 85 ---- > t/db_dependent/Holidays.t | 205 -------- > tools/copy-holidays.pl | 38 -- > tools/exceptionHolidays.pl | 123 ----- > tools/holidays.pl | 132 ----- > tools/newHolidays.pl | 147 ------ > 10 files changed, 2 insertions(+), 1599 deletions(-) > delete mode 100644 Koha/Calendar.pm > delete mode 100755 t/Calendar.t > delete mode 100644 t/db_dependent/Calendar.t > delete mode 100755 t/db_dependent/Holidays.t > delete mode 100755 tools/copy-holidays.pl > delete mode 100755 tools/exceptionHolidays.pl > delete mode 100755 tools/holidays.pl > delete mode 100755 tools/newHolidays.pl > >diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm >deleted file mode 100644 >index c66ab45..0000000 >--- a/Koha/Calendar.pm >+++ /dev/null >@@ -1,535 +0,0 @@ >-package Koha::Calendar; >-use strict; >-use warnings; >-use 5.010; >- >-use DateTime; >-use DateTime::Set; >-use DateTime::Duration; >-use C4::Context; >-use Koha::Caches; >-use Carp; >- >-sub new { >- my ( $classname, %options ) = @_; >- my $self = {}; >- bless $self, $classname; >- for my $o_name ( keys %options ) { >- my $o = lc $o_name; >- $self->{$o} = $options{$o_name}; >- } >- if ( !defined $self->{branchcode} ) { >- croak 'No branchcode argument passed to Koha::Calendar->new'; >- } >- $self->_init(); >- return $self; >-} >- >-sub _init { >- my $self = shift; >- my $branch = $self->{branchcode}; >- my $dbh = C4::Context->dbh(); >- my $weekly_closed_days_sth = $dbh->prepare( >-'SELECT weekday FROM repeatable_holidays WHERE branchcode = ? AND weekday IS NOT NULL' >- ); >- $weekly_closed_days_sth->execute( $branch ); >- $self->{weekly_closed_days} = [ 0, 0, 0, 0, 0, 0, 0 ]; >- while ( my $tuple = $weekly_closed_days_sth->fetchrow_hashref ) { >- $self->{weekly_closed_days}->[ $tuple->{weekday} ] = 1; >- } >- my $day_month_closed_days_sth = $dbh->prepare( >-'SELECT day, month FROM repeatable_holidays WHERE branchcode = ? AND weekday IS NULL' >- ); >- $day_month_closed_days_sth->execute( $branch ); >- $self->{day_month_closed_days} = {}; >- while ( my $tuple = $day_month_closed_days_sth->fetchrow_hashref ) { >- $self->{day_month_closed_days}->{ $tuple->{month} }->{ $tuple->{day} } = >- 1; >- } >- >- $self->{days_mode} = C4::Context->preference('useDaysMode'); >- $self->{test} = 0; >- return; >-} >- >-sub exception_holidays { >- my ( $self ) = @_; >- >- my $cache = Koha::Caches->get_instance(); >- my $cached = $cache->get_from_cache('exception_holidays'); >- return $cached if $cached; >- >- my $dbh = C4::Context->dbh; >- my $branch = $self->{branchcode}; >- my $exception_holidays_sth = $dbh->prepare( >-'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 1' >- ); >- $exception_holidays_sth->execute( $branch ); >- my $dates = []; >- while ( my ( $day, $month, $year ) = $exception_holidays_sth->fetchrow ) { >- push @{$dates}, >- DateTime->new( >- day => $day, >- month => $month, >- year => $year, >- time_zone => "floating", >- )->truncate( to => 'day' ); >- } >- $self->{exception_holidays} = >- DateTime::Set->from_datetimes( dates => $dates ); >- $cache->set_in_cache( 'exception_holidays', $self->{exception_holidays} ); >- return $self->{exception_holidays}; >-} >- >-sub single_holidays { >- my ( $self, $date ) = @_; >- my $branchcode = $self->{branchcode}; >- my $cache = Koha::Caches->get_instance(); >- my $single_holidays = $cache->get_from_cache('single_holidays'); >- >- # $single_holidays looks like: >- # { >- # CPL => [ >- # [0] 20131122, >- # ... >- # ], >- # ... >- # } >- >- unless ($single_holidays) { >- my $dbh = C4::Context->dbh; >- $single_holidays = {}; >- >- # push holidays for each branch >- my $branches_sth = >- $dbh->prepare('SELECT distinct(branchcode) FROM special_holidays'); >- $branches_sth->execute(); >- while ( my $br = $branches_sth->fetchrow ) { >- my $single_holidays_sth = $dbh->prepare( >-'SELECT day, month, year FROM special_holidays WHERE branchcode = ? AND isexception = 0' >- ); >- $single_holidays_sth->execute($br); >- >- my @ymd_arr; >- while ( my ( $day, $month, $year ) = >- $single_holidays_sth->fetchrow ) >- { >- my $dt = DateTime->new( >- day => $day, >- month => $month, >- year => $year, >- time_zone => 'floating', >- )->truncate( to => 'day' ); >- push @ymd_arr, $dt->ymd(''); >- } >- $single_holidays->{$br} = \@ymd_arr; >- } # br >- $cache->set_in_cache( 'single_holidays', $single_holidays, >- { expiry => 76800 } ) #24 hrs ; >- } >- my $holidays = ( $single_holidays->{$branchcode} ); >- for my $hols (@$holidays ) { >- return 1 if ( $date == $hols ) #match ymds; >- } >- return 0; >-} >- >-sub addDate { >- my ( $self, $startdate, $add_duration, $unit ) = @_; >- >- # Default to days duration (legacy support I guess) >- if ( ref $add_duration ne 'DateTime::Duration' ) { >- $add_duration = DateTime::Duration->new( days => $add_duration ); >- } >- >- $unit ||= 'days'; # default days ? >- my $dt; >- >- if ( $unit eq 'hours' ) { >- # Fixed for legacy support. Should be set as a branch parameter >- my $return_by_hour = 10; >- >- $dt = $self->addHours($startdate, $add_duration, $return_by_hour); >- } else { >- # days >- $dt = $self->addDays($startdate, $add_duration); >- } >- >- return $dt; >-} >- >-sub addHours { >- my ( $self, $startdate, $hours_duration, $return_by_hour ) = @_; >- my $base_date = $startdate->clone(); >- >- $base_date->add_duration($hours_duration); >- >- # If we are using the calendar behave for now as if Datedue >- # was the chosen option (current intended behaviour) >- >- if ( $self->{days_mode} ne 'Days' && >- $self->is_holiday($base_date) ) { >- >- if ( $hours_duration->is_negative() ) { >- $base_date = $self->prev_open_day($base_date); >- } else { >- $base_date = $self->next_open_day($base_date); >- } >- >- $base_date->set_hour($return_by_hour); >- >- } >- >- return $base_date; >-} >- >-sub addDays { >- my ( $self, $startdate, $days_duration ) = @_; >- my $base_date = $startdate->clone(); >- >- $self->{days_mode} ||= q{}; >- >- if ( $self->{days_mode} eq 'Calendar' ) { >- # use the calendar to skip all days the library is closed >- # when adding >- my $days = abs $days_duration->in_units('days'); >- >- if ( $days_duration->is_negative() ) { >- while ($days) { >- $base_date = $self->prev_open_day($base_date); >- --$days; >- } >- } else { >- while ($days) { >- $base_date = $self->next_open_day($base_date); >- --$days; >- } >- } >- >- } else { # Days or Datedue >- # use straight days, then use calendar to push >- # the date to the next open day if Datedue >- $base_date->add_duration($days_duration); >- >- if ( $self->{days_mode} eq 'Datedue' ) { >- # Datedue, then use the calendar to push >- # the date to the next open day if holiday >- if ( $self->is_holiday($base_date) ) { >- >- if ( $days_duration->is_negative() ) { >- $base_date = $self->prev_open_day($base_date); >- } else { >- $base_date = $self->next_open_day($base_date); >- } >- } >- } >- } >- >- return $base_date; >-} >- >-sub is_holiday { >- my ( $self, $dt ) = @_; >- >- my $localdt = $dt->clone(); >- my $day = $localdt->day; >- my $month = $localdt->month; >- >- #Change timezone to "floating" before doing any calculations or comparisons >- $localdt->set_time_zone("floating"); >- $localdt->truncate( to => 'day' ); >- >- >- if ( $self->exception_holidays->contains($localdt) ) { >- # exceptions are not holidays >- return 0; >- } >- >- my $dow = $localdt->day_of_week; >- # Representation fix >- # DateTime object dow (1-7) where Monday is 1 >- # Arrays are 0-based where 0 = Sunday, not 7. >- if ( $dow == 7 ) { >- $dow = 0; >- } >- >- if ( $self->{weekly_closed_days}->[$dow] == 1 ) { >- return 1; >- } >- >- if ( exists $self->{day_month_closed_days}->{$month}->{$day} ) { >- return 1; >- } >- >- my $ymd = $localdt->ymd('') ; >- if ($self->single_holidays( $ymd ) == 1 ) { >- return 1; >- } >- >- # damn have to go to work after all >- return 0; >-} >- >-sub next_open_day { >- my ( $self, $dt ) = @_; >- my $base_date = $dt->clone(); >- >- $base_date->add(days => 1); >- >- while ($self->is_holiday($base_date)) { >- $base_date->add(days => 1); >- } >- >- return $base_date; >-} >- >-sub prev_open_day { >- my ( $self, $dt ) = @_; >- my $base_date = $dt->clone(); >- >- $base_date->add(days => -1); >- >- while ($self->is_holiday($base_date)) { >- $base_date->add(days => -1); >- } >- >- return $base_date; >-} >- >-sub days_forward { >- my $self = shift; >- my $start_dt = shift; >- my $num_days = shift; >- >- return $start_dt unless $num_days > 0; >- >- my $base_dt = $start_dt->clone(); >- >- while ($num_days--) { >- $base_dt = $self->next_open_day($base_dt); >- } >- >- return $base_dt; >-} >- >-sub days_between { >- my $self = shift; >- my $start_dt = shift; >- my $end_dt = shift; >- >- # Change time zone for date math and swap if needed >- $start_dt = $start_dt->clone->set_time_zone('floating'); >- $end_dt = $end_dt->clone->set_time_zone('floating'); >- if( $start_dt->compare($end_dt) > 0 ) { >- ( $start_dt, $end_dt ) = ( $end_dt, $start_dt ); >- } >- >- # start and end should not be closed days >- my $days = $start_dt->delta_days($end_dt)->delta_days; >- while( $start_dt->compare($end_dt) < 1 ) { >- $days-- if $self->is_holiday($start_dt); >- $start_dt->add( days => 1 ); >- } >- return DateTime::Duration->new( days => $days ); >-} >- >-sub hours_between { >- my ($self, $start_date, $end_date) = @_; >- my $start_dt = $start_date->clone()->set_time_zone('floating'); >- my $end_dt = $end_date->clone()->set_time_zone('floating'); >- my $duration = $end_dt->delta_ms($start_dt); >- $start_dt->truncate( to => 'day' ); >- $end_dt->truncate( to => 'day' ); >- # NB this is a kludge in that it assumes all days are 24 hours >- # However for hourly loans the logic should be expanded to >- # take into account open/close times then it would be a duration >- # of library open hours >- my $skipped_days = 0; >- for (my $dt = $start_dt->clone(); >- $dt <= $end_dt; >- $dt->add(days => 1) >- ) { >- if ($self->is_holiday($dt)) { >- ++$skipped_days; >- } >- } >- if ($skipped_days) { >- $duration->subtract_duration(DateTime::Duration->new( hours => 24 * $skipped_days)); >- } >- >- return $duration; >- >-} >- >-sub set_daysmode { >- my ( $self, $mode ) = @_; >- >- # if not testing this is a no op >- if ( $self->{test} ) { >- $self->{days_mode} = $mode; >- } >- >- return; >-} >- >-sub clear_weekly_closed_days { >- my $self = shift; >- $self->{weekly_closed_days} = [ 0, 0, 0, 0, 0, 0, 0 ]; # Sunday only >- return; >-} >- >-1; >-__END__ >- >-=head1 NAME >- >-Koha::Calendar - Object containing a branches calendar >- >-=head1 SYNOPSIS >- >- use Koha::Calendar >- >- my $c = Koha::Calendar->new( branchcode => 'MAIN' ); >- my $dt = DateTime->now(); >- >- # are we open >- $open = $c->is_holiday($dt); >- # when will item be due if loan period = $dur (a DateTime::Duration object) >- $duedate = $c->addDate($dt,$dur,'days'); >- >- >-=head1 DESCRIPTION >- >- Implements those features of C4::Calendar needed for Staffs Rolling Loans >- >-=head1 METHODS >- >-=head2 new : Create a calendar object >- >-my $calendar = Koha::Calendar->new( branchcode => 'MAIN' ); >- >-The option branchcode is required >- >- >-=head2 addDate >- >- my $dt = $calendar->addDate($date, $dur, $unit) >- >-C<$date> is a DateTime object representing the starting date of the interval. >- >-C<$offset> is a DateTime::Duration to add to it >- >-C<$unit> is a string value 'days' or 'hours' toflag granularity of duration >- >-Currently unit is only used to invoke Staffs return Monday at 10 am rule this >-parameter will be removed when issuingrules properly cope with that >- >- >-=head2 addHours >- >- my $dt = $calendar->addHours($date, $dur, $return_by_hour ) >- >-C<$date> is a DateTime object representing the starting date of the interval. >- >-C<$offset> is a DateTime::Duration to add to it >- >-C<$return_by_hour> is an integer value representing the opening hour for the branch >- >- >-=head2 addDays >- >- my $dt = $calendar->addDays($date, $dur) >- >-C<$date> is a DateTime object representing the starting date of the interval. >- >-C<$offset> is a DateTime::Duration to add to it >- >-C<$unit> is a string value 'days' or 'hours' toflag granularity of duration >- >-Currently unit is only used to invoke Staffs return Monday at 10 am rule this >-parameter will be removed when issuingrules properly cope with that >- >- >-=head2 single_holidays >- >-my $rc = $self->single_holidays( $ymd ); >- >-Passed a $date in Ymd (yyyymmdd) format - returns 1 if date is a single_holiday, or 0 if not. >- >- >-=head2 is_holiday >- >-$yesno = $calendar->is_holiday($dt); >- >-passed a DateTime object returns 1 if it is a closed day >-0 if not according to the calendar >- >-=head2 days_between >- >-$duration = $calendar->days_between($start_dt, $end_dt); >- >-Passed two dates returns a DateTime::Duration object measuring the length between them >-ignoring closed days. Always returns a positive number irrespective of the >-relative order of the parameters >- >-=head2 next_open_day >- >-$datetime = $calendar->next_open_day($duedate_dt) >- >-Passed a Datetime returns another Datetime representing the next open day. It is >-intended for use to calculate the due date when useDaysMode syspref is set to either >-'Datedue' or 'Calendar'. >- >-=head2 prev_open_day >- >-$datetime = $calendar->prev_open_day($duedate_dt) >- >-Passed a Datetime returns another Datetime representing the previous open day. It is >-intended for use to calculate the due date when useDaysMode syspref is set to either >-'Datedue' or 'Calendar'. >- >-=head2 set_daysmode >- >-For testing only allows the calling script to change days mode >- >-=head2 clear_weekly_closed_days >- >-In test mode changes the testing set of closed days to a new set with >-no closed days. TODO passing an array of closed days to this would >-allow testing of more configurations >- >-=head2 add_holiday >- >-Passed a datetime object this will add it to the calendar's list of >-closed days. This is for testing so that we can alter the Calenfar object's >-list of specified dates >- >-=head1 DIAGNOSTICS >- >-Will croak if not passed a branchcode in new >- >-=head1 BUGS AND LIMITATIONS >- >-This only contains a limited subset of the functionality in C4::Calendar >-Only enough to support Staffs Rolling loans >- >-=head1 AUTHOR >- >-Colin Campbell colin.campbell@ptfs-europe.com >- >-=head1 LICENSE AND COPYRIGHT >- >-Copyright (c) 2011 PTFS-Europe Ltd All rights reserved >- >-This program is free software: you can redistribute it and/or modify >-it under the terms of the GNU General Public License as published by >-the Free Software Foundation, either version 2 of the License, or >-(at your option) any later version. >- >-This program is distributed in the hope that it will be useful, >-but WITHOUT ANY WARRANTY; without even the implied warranty of >-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-GNU General Public License for more details. >- >-You should have received a copy of the GNU General Public License >-along with this program. If not, see <http://www.gnu.org/licenses/>. >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc >index 50e52f7..146c1d6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-menu.inc >@@ -85,7 +85,7 @@ > <h5>Additional tools</h5> > <ul> > [% IF ( CAN_user_tools_edit_calendar ) %] >- <li><a href="/cgi-bin/koha/tools/holidays.pl">Calendar</a></li> >+ <li><a href="/cgi-bin/koha/tools/discrete_calendar.pl">Calendar</a></li> > [% END %] > [% IF ( CAN_user_tools_manage_csv_profiles ) %] > <li><a href="/cgi-bin/koha/tools/csv-profiles.pl">CSV profiles</a></li> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt >index 3642d4f..2f5d66c 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/tools-home.tt >@@ -75,12 +75,7 @@ > <h3>Additional tools</h3> > <dl> > [% IF ( CAN_user_tools_edit_calendar ) %] >- <dt><a href="/cgi-bin/koha/tools/holidays.pl">Calendar</a></dt> >- <dd>Define days when the library is closed</dd> >- [% END %] >- >- [% IF ( CAN_user_tools_edit_calendar ) %] >- <dt><a href="/cgi-bin/koha/tools/discrete_calendar.pl">Discrete Calendar</a></dt> >+ <dt><a href="/cgi-bin/koha/tools/discrete_calendar.pl">Calendar</a></dt> > <dd>Define days when the library is closed</dd> > [% END %] > >diff --git a/t/Calendar.t b/t/Calendar.t >deleted file mode 100755 >index 1c3f194..0000000 >--- a/t/Calendar.t >+++ /dev/null >@@ -1,327 +0,0 @@ >-#!/usr/bin/perl >- >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >- >-use Test::More; >-use Test::MockModule; >- >-use DateTime; >-use DateTime::Duration; >-use Koha::Caches; >-use Koha::DateUtils; >- >-use Module::Load::Conditional qw/check_install/; >- >-BEGIN { >- if ( check_install( module => 'Test::DBIx::Class' ) ) { >- plan tests => 38; >- } else { >- plan skip_all => "Need Test::DBIx::Class" >- } >-} >- >-use_ok('Koha::Calendar'); >- >-use Test::DBIx::Class; >- >-my $db = Test::MockModule->new('Koha::Database'); >-$db->mock( >- _new_schema => sub { return Schema(); } >-); >- >-# We need to mock the C4::Context->preference method for >-# simplicity and re-usability of the session definition. Any >-# syspref fits for syspref-agnostic tests. >-my $module_context = new Test::MockModule('C4::Context'); >-$module_context->mock( >- 'preference', >- sub { >- return 'Calendar'; >- } >-); >- >-fixtures_ok [ >- # weekly holidays >- RepeatableHoliday => [ >- [ qw( branchcode day month weekday title description) ], >- [ 'MPL', undef, undef, 0, '', '' ], # sundays >- [ 'MPL', undef, undef, 6, '', '' ],# saturdays >- [ 'MPL', 1, 1, undef, '', ''], # new year's day >- [ 'MPL', 25, 12, undef, '', ''], # chrismas >- ], >- # exception holidays >- SpecialHoliday => [ >- [qw( branchcode day month year title description isexception )], >- [ 'MPL', 11, 11, 2012, '', '', 1 ], # sunday exception >- [ 'MPL', 1, 6, 2011, '', '', 0 ], >- [ 'MPL', 4, 7, 2012, '', '', 0 ], >- [ 'CPL', 6, 8, 2012, '', '', 0 ], >- ], >-], "add fixtures"; >- >-my $cache = Koha::Caches->get_instance(); >-$cache->clear_from_cache( 'single_holidays' ) ; >-$cache->clear_from_cache( 'exception_holidays' ) ; >- >-# 'MPL' branch is arbitrary, is not used at all but is needed for initialization >-my $cal = Koha::Calendar->new( branchcode => 'MPL' ); >- >-isa_ok( $cal, 'Koha::Calendar', 'Calendar class returned' ); >- >-my $saturday = DateTime->new( >- year => 2012, >- month => 11, >- day => 24, >-); >- >-my $sunday = DateTime->new( >- year => 2012, >- month => 11, >- day => 25, >-); >- >-my $monday = DateTime->new( >- year => 2012, >- month => 11, >- day => 26, >-); >- >-my $new_year = DateTime->new( >- year => 2013, >- month => 1, >- day => 1, >-); >- >-my $single_holiday = DateTime->new( >- year => 2011, >- month => 6, >- day => 1, >-); # should be a holiday >- >-my $notspecial = DateTime->new( >- year => 2011, >- month => 6, >- day => 2 >-); # should NOT be a holiday >- >-my $sunday_exception = DateTime->new( >- year => 2012, >- month => 11, >- day => 11 >-); >- >-my $day_after_christmas = DateTime->new( >- year => 2012, >- month => 12, >- day => 26 >-); # for testing negative addDate >- >-my $holiday_for_another_branch = DateTime->new( >- year => 2012, >- month => 8, >- day => 6, # This is a monday >-); >- >-{ # Syspref-agnostic tests >- is ( $saturday->day_of_week, 6, '\'$saturday\' is actually a saturday (6th day of week)'); >- is ( $sunday->day_of_week, 7, '\'$sunday\' is actually a sunday (7th day of week)'); >- is ( $monday->day_of_week, 1, '\'$monday\' is actually a monday (1st day of week)'); >- is ( $cal->is_holiday($saturday), 1, 'Saturday is a closed day' ); >- is ( $cal->is_holiday($sunday), 1, 'Sunday is a closed day' ); >- is ( $cal->is_holiday($monday), 0, 'Monday is not a closed day' ); >- is ( $cal->is_holiday($new_year), 1, 'Month/Day closed day test (New year\'s day)' ); >- is ( $cal->is_holiday($single_holiday), 1, 'Single holiday closed day test' ); >- is ( $cal->is_holiday($notspecial), 0, 'Fixed single date that is not a holiday test' ); >- is ( $cal->is_holiday($sunday_exception), 0, 'Exception holiday is not a closed day test' ); >- is ( $cal->is_holiday($holiday_for_another_branch), 0, 'Holiday defined for another branch should not be defined as an holiday' ); >-} >- >-{ # Bugzilla #8966 - is_holiday truncates referenced date >- my $later_dt = DateTime->new( # Monday >- year => 2012, >- month => 9, >- day => 17, >- hour => 17, >- minute => 30, >- time_zone => 'Europe/London', >- ); >- >- >- is( $cal->is_holiday($later_dt), 0, 'bz-8966 (1/2) Apply is_holiday for the next test' ); >- cmp_ok( $later_dt, 'eq', '2012-09-17T17:30:00', 'bz-8966 (2/2) Date should be the same after is_holiday' ); >-} >- >-{ # Bugzilla #8800 - is_holiday should use truncated date for 'contains' call >- my $single_holiday_time = DateTime->new( >- year => 2011, >- month => 6, >- day => 1, >- hour => 11, >- minute => 2 >- ); >- >- is( $cal->is_holiday($single_holiday_time), >- $cal->is_holiday($single_holiday) , >- 'bz-8800 is_holiday should truncate the date for holiday validation' ); >-} >- >- my $one_day_dur = DateTime::Duration->new( days => 1 ); >- my $two_day_dur = DateTime::Duration->new( days => 2 ); >- my $seven_day_dur = DateTime::Duration->new( days => 7 ); >- >- my $dt = dt_from_string( '2012-07-03','iso' ); #tuesday >- >- my $test_dt = DateTime->new( # Monday >- year => 2012, >- month => 7, >- day => 23, >- hour => 11, >- minute => 53, >- ); >- >- my $later_dt = DateTime->new( # Monday >- year => 2012, >- month => 9, >- day => 17, >- hour => 17, >- minute => 30, >- time_zone => 'Europe/London', >- ); >- >-{ ## 'Datedue' tests >- >- $module_context->unmock('preference'); >- $module_context->mock( >- 'preference', >- sub { >- return 'Datedue'; >- } >- ); >- >- $cal = Koha::Calendar->new( branchcode => 'MPL' ); >- >- is($cal->addDate( $dt, $one_day_dur, 'days' ), # tuesday >- dt_from_string('2012-07-05','iso'), >- 'Single day add (Datedue, matches holiday, shift)' ); >- >- is($cal->addDate( $dt, $two_day_dur, 'days' ), >- dt_from_string('2012-07-05','iso'), >- 'Two days add, skips holiday (Datedue)' ); >- >- cmp_ok($cal->addDate( $test_dt, $seven_day_dur, 'days' ), 'eq', >- '2012-07-30T11:53:00', >- 'Add 7 days (Datedue)' ); >- >- is( $cal->addDate( $saturday, $one_day_dur, 'days' )->day_of_week, 1, >- 'addDate skips closed Sunday (Datedue)' ); >- >- is( $cal->addDate($day_after_christmas, -1, 'days')->ymd(), '2012-12-24', >- 'Negative call to addDate (Datedue)' ); >- >- ## Note that the days_between API says closed days are not considered. >- ## This tests are here as an API test. >- cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'), >- '==', 40, 'days_between calculates correctly (Days)' ); >- >- cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'), >- '==', 40, 'Test parameter order not relevant (Days)' ); >-} >- >-{ ## 'Calendar' tests' >- >- $module_context->unmock('preference'); >- $module_context->mock( >- 'preference', >- sub { >- return 'Calendar'; >- } >- ); >- >- $cal = Koha::Calendar->new( branchcode => 'MPL' ); >- >- $dt = dt_from_string('2012-07-03','iso'); >- >- is($cal->addDate( $dt, $one_day_dur, 'days' ), >- dt_from_string('2012-07-05','iso'), >- 'Single day add (Calendar)' ); >- >- cmp_ok($cal->addDate( $test_dt, $seven_day_dur, 'days' ), 'eq', >- '2012-08-01T11:53:00', >- 'Add 7 days (Calendar)' ); >- >- is( $cal->addDate( $saturday, $one_day_dur, 'days' )->day_of_week, 1, >- 'addDate skips closed Sunday (Calendar)' ); >- >- is( $cal->addDate($day_after_christmas, -1, 'days')->ymd(), '2012-12-24', >- 'Negative call to addDate (Calendar)' ); >- >- cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'), >- '==', 40, 'days_between calculates correctly (Calendar)' ); >- >- cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'), >- '==', 40, 'Test parameter order not relevant (Calendar)' ); >-} >- >- >-{ ## 'Days' tests >- $module_context->unmock('preference'); >- $module_context->mock( >- 'preference', >- sub { >- return 'Days'; >- } >- ); >- >- $cal = Koha::Calendar->new( branchcode => 'MPL' ); >- >- $dt = dt_from_string('2012-07-03','iso'); >- >- is($cal->addDate( $dt, $one_day_dur, 'days' ), >- dt_from_string('2012-07-04','iso'), >- 'Single day add (Days)' ); >- >- cmp_ok($cal->addDate( $test_dt, $seven_day_dur, 'days' ),'eq', >- '2012-07-30T11:53:00', >- 'Add 7 days (Days)' ); >- >- is( $cal->addDate( $saturday, $one_day_dur, 'days' )->day_of_week, 7, >- 'addDate doesn\'t skip closed Sunday (Days)' ); >- >- is( $cal->addDate($day_after_christmas, -1, 'days')->ymd(), '2012-12-25', >- 'Negative call to addDate (Days)' ); >- >- ## Note that the days_between API says closed days are not considered. >- ## This tests are here as an API test. >- cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'), >- '==', 40, 'days_between calculates correctly (Days)' ); >- >- cmp_ok( $cal->days_between( $later_dt, $test_dt )->in_units('days'), >- '==', 40, 'Test parameter order not relevant (Days)' ); >- >-} >- >-{ >- $cal = Koha::Calendar->new( branchcode => 'CPL' ); >- is ( $cal->is_holiday($single_holiday), 0, 'Single holiday for MPL, not CPL' ); >- is ( $cal->is_holiday($holiday_for_another_branch), 1, 'Holiday defined for CPL should be defined as an holiday' ); >-} >- >-END { >- $cache->clear_from_cache( 'single_holidays' ) ; >- $cache->clear_from_cache( 'exception_holidays' ) ; >-}; >diff --git a/t/db_dependent/Calendar.t b/t/db_dependent/Calendar.t >deleted file mode 100644 >index 3cfe961..0000000 >--- a/t/db_dependent/Calendar.t >+++ /dev/null >@@ -1,85 +0,0 @@ >-#!/usr/bin/perl >- >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >- >-use Test::More tests => 6; >-use t::lib::TestBuilder; >- >-use DateTime; >-use Koha::Caches; >-use Koha::DateUtils; >- >-use_ok('Koha::Calendar'); >- >-my $schema = Koha::Database->new->schema; >-$schema->storage->txn_begin; >- >-my $today = dt_from_string(); >-my $holiday_dt = $today->clone; >-$holiday_dt->add(days => 15); >- >-Koha::Caches->get_instance()->flush_all(); >- >-my $builder = t::lib::TestBuilder->new(); >-my $holiday = $builder->build({ >- source => 'SpecialHoliday', >- value => { >- branchcode => 'LIB1', >- day => $holiday_dt->day, >- month => $holiday_dt->month, >- year => $holiday_dt->year, >- title => 'My holiday', >- isexception => 0 >- }, >-}); >- >-my $calendar = Koha::Calendar->new( branchcode => 'LIB1'); >-my $forwarded_dt = $calendar->days_forward($today, 10); >- >-my $expected = $today->clone; >-$expected->add(days => 10); >-is($forwarded_dt->ymd, $expected->ymd, 'With no holiday on the perioddays_forward should add 10 days'); >- >-$forwarded_dt = $calendar->days_forward($today, 20); >- >-$expected->add(days => 11); >-is($forwarded_dt->ymd, $expected->ymd, 'With holiday on the perioddays_forward should add 20 days + 1 day for holiday'); >- >-$forwarded_dt = $calendar->days_forward($today, 0); >-is($forwarded_dt->ymd, $today->ymd, '0 day should return start dt'); >- >-$forwarded_dt = $calendar->days_forward($today, -2); >-is($forwarded_dt->ymd, $today->ymd, 'negative day should return start dt'); >- >-subtest 'crossing_DST' => sub { >- >- plan tests => 3; >- >- my $tz = DateTime::TimeZone->new( name => 'America/New_York' ); >- my $start_date = dt_from_string( "2016-03-09 02:29:00",undef,$tz ); >- my $end_date = dt_from_string( "2017-01-01 00:00:00", undef, $tz ); >- my $days_between = $calendar->days_between($start_date,$end_date); >- is( $days_between->delta_days, 298, "Days calculated correctly" ); >- $days_between = $calendar->days_between($end_date,$start_date); >- is( $days_between->delta_days, 298, "Swapping returns the same" ); >- my $hours_between = $calendar->hours_between($start_date,$end_date); >- is( $hours_between->delta_minutes, 298 * 24 * 60 - 149, "Hours (in minutes) calculated correctly" ); >- >-}; >- >-$schema->storage->txn_rollback(); >diff --git a/t/db_dependent/Holidays.t b/t/db_dependent/Holidays.t >deleted file mode 100755 >index 70c71d4..0000000 >--- a/t/db_dependent/Holidays.t >+++ /dev/null >@@ -1,205 +0,0 @@ >-#!/usr/bin/perl >- >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >- >-use Test::More tests => 16; >- >-use DateTime; >-use DateTime::TimeZone; >- >-use t::lib::TestBuilder; >-use C4::Context; >-use Koha::Database; >-use Koha::DateUtils; >- >- >-BEGIN { >- use_ok('Koha::Calendar'); >- use_ok('C4::Calendar'); >-} >- >-my $schema = Koha::Database->new->schema; >-my $dbh = C4::Context->dbh; >-my $builder = t::lib::TestBuilder->new; >- >-subtest 'exception_holidays() tests' => sub { >- >- plan tests => 1; >- >- $schema->storage->txn_begin; >- >- $dbh->do("DELETE FROM special_holidays"); >- # Clear cache >- Koha::Caches->get_instance->flush_all; >- >- # Artificially set timezone >- my $timezone = 'America/Santiago'; >- $ENV{TZ} = $timezone; >- use POSIX qw(tzset); >- tzset; >- >- my $branch = $builder->build( { source => 'Branch' } )->{branchcode}; >- my $calendar = Koha::Calendar->new( branchcode => $branch ); >- >- C4::Calendar->new( branchcode => $branch )->insert_exception_holiday( >- day => 6, >- month => 9, >- year => 2015, >- title => 'Invalid date', >- description => 'Invalid date description', >- ); >- >- my $exception_holiday = $calendar->exception_holidays->iterator->next; >- my $now_dt = DateTime->now; >- >- my $diff; >- eval { $diff = $calendar->days_between( $now_dt, $exception_holiday ) }; >- unlike( >- $@, >- qr/Invalid local time for date in time zone: America\/Santiago/, >- 'Avoid invalid datetime due to DST' >- ); >- >- $schema->storage->txn_rollback; >-}; >- >-$schema->storage->txn_begin; >- >-# Create two fresh branches for the tests >-my $branch_1 = $builder->build({ source => 'Branch' })->{ branchcode }; >-my $branch_2 = $builder->build({ source => 'Branch' })->{ branchcode }; >- >-C4::Calendar->new( branchcode => $branch_1 )->insert_week_day_holiday( >- weekday => 0, >- title => '', >- description => 'Sundays', >-); >- >-my $holiday2add = dt_from_string("2015-01-01"); >-C4::Calendar->new( branchcode => $branch_1 )->insert_day_month_holiday( >- day => $holiday2add->day(), >- month => $holiday2add->month(), >- year => $holiday2add->year(), >- title => '', >- description => "New Year's Day", >-); >-$holiday2add = dt_from_string("2014-12-25"); >-C4::Calendar->new( branchcode => $branch_1 )->insert_day_month_holiday( >- day => $holiday2add->day(), >- month => $holiday2add->month(), >- year => $holiday2add->year(), >- title => '', >- description => 'Christmas', >-); >- >-my $koha_calendar = Koha::Calendar->new( branchcode => $branch_1 ); >-my $c4_calendar = C4::Calendar->new( branchcode => $branch_1 ); >- >-isa_ok( $koha_calendar, 'Koha::Calendar', 'Koha::Calendar class returned' ); >-isa_ok( $c4_calendar, 'C4::Calendar', 'C4::Calendar class returned' ); >- >-my $sunday = DateTime->new( >- year => 2011, >- month => 6, >- day => 26, >-); >-my $monday = DateTime->new( >- year => 2011, >- month => 6, >- day => 27, >-); >-my $christmas = DateTime->new( >- year => 2032, >- month => 12, >- day => 25, >-); >-my $newyear = DateTime->new( >- year => 2035, >- month => 1, >- day => 1, >-); >- >-is( $koha_calendar->is_holiday($sunday), 1, 'Sunday is a closed day' ); >-is( $koha_calendar->is_holiday($monday), 0, 'Monday is not a closed day' ); >-is( $koha_calendar->is_holiday($christmas), 1, 'Christmas is a closed day' ); >-is( $koha_calendar->is_holiday($newyear), 1, 'New Years day is a closed day' ); >- >-$dbh->do("DELETE FROM repeatable_holidays"); >-$dbh->do("DELETE FROM special_holidays"); >- >-my $custom_holiday = DateTime->new( >- year => 2013, >- month => 11, >- day => 12, >-); >- >-my $today = dt_from_string(); >-C4::Calendar->new( branchcode => $branch_2 )->insert_single_holiday( >- day => $today->day(), >- month => $today->month(), >- year => $today->year(), >- title => "$today", >- description => "$today", >-); >- >-is( Koha::Calendar->new( branchcode => $branch_2 )->is_holiday( $today ), 1, "Today is a holiday for $branch_2" ); >-is( Koha::Calendar->new( branchcode => $branch_1 )->is_holiday( $today ), 0, "Today is not a holiday for $branch_1"); >- >-# Few tests for exception holidays >-my ( $diff, $cal, $special ); >-$dbh->do("DELETE FROM special_holidays"); >-_add_exception( $today, $branch_1, 'Today' ); >-$cal = Koha::Calendar->new( branchcode => $branch_1 ); >-$special = $cal->exception_holidays; >-is( $special->count, 1, 'One exception holiday added' ); >- >-my $tomorrow= dt_from_string(); >-$tomorrow->add_duration( DateTime::Duration->new(days => 1) ); >-_add_exception( $tomorrow, $branch_1, 'Tomorrow' ); >-$cal = Koha::Calendar->new( branchcode => $branch_1 ); >-$special = $cal->exception_holidays; >-is( $special->count, 2, 'Set of exception holidays contains two dates' ); >- >-$diff = $today->delta_days( $special->min )->in_units('days'); >-is( $diff, 0, 'Lowest exception holiday is today' ); >-$diff = $tomorrow->delta_days( $special->max )->in_units('days'); >-is( $diff, 0, 'Highest exception holiday is tomorrow' ); >- >-C4::Calendar->new( branchcode => $branch_1 )->delete_holiday( >- weekday => $tomorrow->day_of_week, >- day => $tomorrow->day, >- month => $tomorrow->month, >- year => $tomorrow->year, >-); >-$cal = Koha::Calendar->new( branchcode => $branch_1 ); >-$special = $cal->exception_holidays; >-is( $special->count, 1, 'Set of exception holidays back to one' ); >- >-sub _add_exception { >- my ( $dt, $branch, $descr ) = @_; >- C4::Calendar->new( branchcode => $branch )->insert_exception_holiday( >- day => $dt->day, >- month => $dt->month, >- year => $dt->year, >- title => $descr, >- description => $descr, >- ); >-} >- >-$schema->storage->txn_rollback; >- >diff --git a/tools/copy-holidays.pl b/tools/copy-holidays.pl >deleted file mode 100755 >index 309f488..0000000 >--- a/tools/copy-holidays.pl >+++ /dev/null >@@ -1,38 +0,0 @@ >-#!/usr/bin/perl >- >-# Copyright 2012 Catalyst IT >-# >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >- >-use CGI qw ( -utf8 ); >- >-use C4::Auth; >-use C4::Output; >- >- >-use C4::Calendar; >- >-my $input = new CGI; >-my $dbh = C4::Context->dbh(); >- >-my $branchcode = $input->param('branchcode'); >-my $from_branchcode = $input->param('from_branchcode'); >- >-C4::Calendar->new(branchcode => $from_branchcode)->copy_to_branch($branchcode) if $from_branchcode && $branchcode; >- >-print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=".($branchcode || $from_branchcode)); >diff --git a/tools/exceptionHolidays.pl b/tools/exceptionHolidays.pl >deleted file mode 100755 >index 90b17bc..0000000 >--- a/tools/exceptionHolidays.pl >+++ /dev/null >@@ -1,123 +0,0 @@ >-#!/usr/bin/perl >- >-use Modern::Perl; >- >-use CGI qw ( -utf8 ); >- >-use C4::Auth; >-use C4::Output; >-use DateTime; >- >-use C4::Calendar; >-use Koha::DateUtils; >- >-my $input = new CGI; >-my $dbh = C4::Context->dbh(); >- >-my $branchcode = $input->param('showBranchName'); >-my $weekday = $input->param('showWeekday'); >-my $day = $input->param('showDay'); >-my $month = $input->param('showMonth'); >-my $year = $input->param('showYear'); >-my $title = $input->param('showTitle'); >-my $description = $input->param('showDescription'); >-my $holidaytype = $input->param('showHolidayType'); >-my $datecancelrange_dt = eval { dt_from_string( scalar $input->param('datecancelrange') ) }; >-my $calendardate = sprintf("%04d-%02d-%02d", $year, $month, $day); >- >-my $calendar = C4::Calendar->new(branchcode => $branchcode); >- >-$title || ($title = ''); >-if ($description) { >- $description =~ s/\r/\\r/g; >- $description =~ s/\n/\\n/g; >-} else { >- $description = ''; >-} >- >-# We make an array with holiday's days >-my @holiday_list; >-if ($datecancelrange_dt){ >- my $first_dt = DateTime->new(year => $year, month => $month, day => $day); >- >- for (my $dt = $first_dt->clone(); >- $dt <= $datecancelrange_dt; >- $dt->add(days => 1) ) >- { >- push @holiday_list, $dt->clone(); >- } >-} >-if ($input->param('showOperation') eq 'exception') { >- $calendar->insert_exception_holiday(day => $day, >- month => $month, >- year => $year, >- title => $title, >- description => $description); >-} elsif ($input->param('showOperation') eq 'exceptionrange' ) { >- if (@holiday_list){ >- foreach my $date (@holiday_list){ >- $calendar->insert_exception_holiday( >- day => $date->{local_c}->{day}, >- month => $date->{local_c}->{month}, >- year => $date->{local_c}->{year}, >- title => $title, >- description => $description >- ); >- } >- } >-} elsif ($input->param('showOperation') eq 'edit') { >- if($holidaytype eq 'weekday') { >- $calendar->ModWeekdayholiday(weekday => $weekday, >- title => $title, >- description => $description); >- } elsif ($holidaytype eq 'daymonth') { >- $calendar->ModDaymonthholiday(day => $day, >- month => $month, >- title => $title, >- description => $description); >- } elsif ($holidaytype eq 'ymd') { >- $calendar->ModSingleholiday(day => $day, >- month => $month, >- year => $year, >- title => $title, >- description => $description); >- } elsif ($holidaytype eq 'exception') { >- $calendar->ModExceptionholiday(day => $day, >- month => $month, >- year => $year, >- title => $title, >- description => $description); >- } >-} elsif ($input->param('showOperation') eq 'delete') { >- $calendar->delete_holiday(weekday => $weekday, >- day => $day, >- month => $month, >- year => $year); >-}elsif ($input->param('showOperation') eq 'deleterange') { >- if (@holiday_list){ >- foreach my $date (@holiday_list){ >- $calendar->delete_holiday_range(weekday => $weekday, >- day => $date->{local_c}->{day}, >- month => $date->{local_c}->{month}, >- year => $date->{local_c}->{year}); >- } >- } >-}elsif ($input->param('showOperation') eq 'deleterangerepeat') { >- if (@holiday_list){ >- foreach my $date (@holiday_list){ >- $calendar->delete_holiday_range_repeatable(weekday => $weekday, >- day => $date->{local_c}->{day}, >- month => $date->{local_c}->{month}); >- } >- } >-}elsif ($input->param('showOperation') eq 'deleterangerepeatexcept') { >- if (@holiday_list){ >- foreach my $date (@holiday_list){ >- $calendar->delete_exception_holiday_range(weekday => $weekday, >- day => $date->{local_c}->{day}, >- month => $date->{local_c}->{month}, >- year => $date->{local_c}->{year}); >- } >- } >-} >-print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$branchcode&calendardate=$calendardate"); >diff --git a/tools/holidays.pl b/tools/holidays.pl >deleted file mode 100755 >index 207439b..0000000 >--- a/tools/holidays.pl >+++ /dev/null >@@ -1,132 +0,0 @@ >-#!/usr/bin/perl >- >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-#####Sets holiday periods for each branch. Datedues will be extended if branch is closed -TG >-use Modern::Perl; >- >-use CGI qw ( -utf8 ); >- >-use C4::Auth; >-use C4::Output; >- >-use C4::Calendar; >-use Koha::DateUtils; >- >-my $input = new CGI; >- >-my $dbh = C4::Context->dbh(); >-# Get the template to use >-my ($template, $loggedinuser, $cookie) >- = get_template_and_user({template_name => "tools/holidays.tt", >- type => "intranet", >- query => $input, >- authnotrequired => 0, >- flagsrequired => {tools => 'edit_calendar'}, >- debug => 1, >- }); >- >-# calendardate - date passed in url for human readability (syspref) >-# if the url has an invalid date default to 'now.' >-my $calendarinput_dt = eval { dt_from_string( scalar $input->param('calendardate') ); } || dt_from_string; >-my $calendardate = output_pref( { dt => $calendarinput_dt, dateonly => 1 } ); >- >-# keydate - date passed to calendar.js. calendar.js does not process dashes within a date. >-my $keydate = output_pref( { dt => $calendarinput_dt, dateonly => 1, dateformat => 'iso' } ); >-$keydate =~ s/-/\//g; >- >-my $branch= $input->param('branch') || C4::Context->userenv->{'branch'}; >- >-# Get all the holidays >- >-my $calendar = C4::Calendar->new(branchcode => $branch); >-my $week_days_holidays = $calendar->get_week_days_holidays(); >-my @week_days; >-foreach my $weekday (keys %$week_days_holidays) { >-# warn "WEEK DAY : $weekday"; >- my %week_day; >- %week_day = (KEY => $weekday, >- TITLE => $week_days_holidays->{$weekday}{title}, >- DESCRIPTION => $week_days_holidays->{$weekday}{description}); >- push @week_days, \%week_day; >-} >- >-my $day_month_holidays = $calendar->get_day_month_holidays(); >-my @day_month_holidays; >-foreach my $monthDay (keys %$day_month_holidays) { >- # Determine date format on month and day. >- my $day_monthdate; >- my $day_monthdate_sort; >- if (C4::Context->preference("dateformat") eq "metric") { >- $day_monthdate_sort = "$day_month_holidays->{$monthDay}{month}-$day_month_holidays->{$monthDay}{day}"; >- $day_monthdate = "$day_month_holidays->{$monthDay}{day}/$day_month_holidays->{$monthDay}{month}"; >- } elsif (C4::Context->preference("dateformat") eq "dmydot") { >- $day_monthdate_sort = "$day_month_holidays->{$monthDay}{month}.$day_month_holidays->{$monthDay}{day}"; >- $day_monthdate = "$day_month_holidays->{$monthDay}{day}.$day_month_holidays->{$monthDay}{month}"; >- }elsif (C4::Context->preference("dateformat") eq "us") { >- $day_monthdate = "$day_month_holidays->{$monthDay}{month}/$day_month_holidays->{$monthDay}{day}"; >- $day_monthdate_sort = $day_monthdate; >- } else { >- $day_monthdate = "$day_month_holidays->{$monthDay}{month}-$day_month_holidays->{$monthDay}{day}"; >- $day_monthdate_sort = $day_monthdate; >- } >- my %day_month; >- %day_month = (KEY => $monthDay, >- DATE_SORT => $day_monthdate_sort, >- DATE => $day_monthdate, >- TITLE => $day_month_holidays->{$monthDay}{title}, >- DESCRIPTION => $day_month_holidays->{$monthDay}{description}); >- push @day_month_holidays, \%day_month; >-} >- >-my $exception_holidays = $calendar->get_exception_holidays(); >-my @exception_holidays; >-foreach my $yearMonthDay (keys %$exception_holidays) { >- my $exceptiondate = eval { dt_from_string( $exception_holidays->{$yearMonthDay}{date} ) }; >- my %exception_holiday; >- %exception_holiday = (KEY => $yearMonthDay, >- DATE_SORT => $exception_holidays->{$yearMonthDay}{date}, >- DATE => output_pref( { dt => $exceptiondate, dateonly => 1 } ), >- TITLE => $exception_holidays->{$yearMonthDay}{title}, >- DESCRIPTION => $exception_holidays->{$yearMonthDay}{description}); >- push @exception_holidays, \%exception_holiday; >-} >- >-my $single_holidays = $calendar->get_single_holidays(); >-my @holidays; >-foreach my $yearMonthDay (keys %$single_holidays) { >- my $holidaydate_dt = eval { dt_from_string( $single_holidays->{$yearMonthDay}{date} ) }; >- my %holiday; >- %holiday = (KEY => $yearMonthDay, >- DATE_SORT => $single_holidays->{$yearMonthDay}{date}, >- DATE => output_pref( { dt => $holidaydate_dt, dateonly => 1 } ), >- TITLE => $single_holidays->{$yearMonthDay}{title}, >- DESCRIPTION => $single_holidays->{$yearMonthDay}{description}); >- push @holidays, \%holiday; >-} >- >-$template->param( >- WEEK_DAYS_LOOP => \@week_days, >- HOLIDAYS_LOOP => \@holidays, >- EXCEPTION_HOLIDAYS_LOOP => \@exception_holidays, >- DAY_MONTH_HOLIDAYS_LOOP => \@day_month_holidays, >- calendardate => $calendardate, >- keydate => $keydate, >- branch => $branch, >-); >- >-# Shows the template with the real values replaced >-output_html_with_http_headers $input, $cookie, $template->output; >diff --git a/tools/newHolidays.pl b/tools/newHolidays.pl >deleted file mode 100755 >index a161eaf..0000000 >--- a/tools/newHolidays.pl >+++ /dev/null >@@ -1,147 +0,0 @@ >-#!/usr/bin/perl >-#FIXME: perltidy this file >- >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public Lic# along with Koha; if not, see <http://www.gnu.org/licenses>. >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >- >-use Modern::Perl; >- >-use CGI qw ( -utf8 ); >- >-use C4::Auth; >-use C4::Output; >- >-use Koha::Caches; >- >-use C4::Calendar; >-use DateTime; >-use Koha::DateUtils; >- >-my $input = new CGI; >-my $dbh = C4::Context->dbh(); >- >-our $branchcode = $input->param('newBranchName'); >-my $originalbranchcode = $branchcode; >-our $weekday = $input->param('newWeekday'); >-our $day = $input->param('newDay'); >-our $month = $input->param('newMonth'); >-our $year = $input->param('newYear'); >-my $dateofrange = $input->param('dateofrange'); >-our $title = $input->param('newTitle'); >-our $description = $input->param('newDescription'); >-our $newoperation = $input->param('newOperation'); >-my $allbranches = $input->param('allBranches'); >- >- >-my $first_dt = DateTime->new(year => $year, month => $month, day => $day); >-my $end_dt = eval { dt_from_string( $dateofrange ); }; >- >-my $calendardate = output_pref( { dt => $first_dt, dateonly => 1, dateformat => 'iso' } ); >- >-$title || ($title = ''); >-if ($description) { >- $description =~ s/\r/\\r/g; >- $description =~ s/\n/\\n/g; >-} else { >- $description = ''; >-} >- >-# We make an array with holiday's days >-our @holiday_list; >-if ($end_dt){ >- for (my $dt = $first_dt->clone(); >- $dt <= $end_dt; >- $dt->add(days => 1) ) >- { >- push @holiday_list, $dt->clone(); >- } >-} >- >-if($allbranches) { >- my $libraries = Koha::Libraries->search; >- while ( my $library = $libraries->next ) { >- add_holiday($newoperation, $library->branchcode, $weekday, $day, $month, $year, $title, $description); >- } >-} else { >- add_holiday($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description); >-} >- >-print $input->redirect("/cgi-bin/koha/tools/holidays.pl?branch=$originalbranchcode&calendardate=$calendardate"); >- >-#FIXME: move add_holiday() to a better place >-sub add_holiday { >- ($newoperation, $branchcode, $weekday, $day, $month, $year, $title, $description) = @_; >- my $calendar = C4::Calendar->new(branchcode => $branchcode); >- >- if ($newoperation eq 'weekday') { >- unless ( $weekday && ($weekday ne '') ) { >- # was dow calculated by javascript? original code implies it was supposed to be. >- # if not, we need it. >- $weekday = &Date::Calc::Day_of_Week($year, $month, $day) % 7 unless($weekday); >- } >- unless($calendar->isHoliday($day, $month, $year)) { >- $calendar->insert_week_day_holiday(weekday => $weekday, >- title => $title, >- description => $description); >- } >- } elsif ($newoperation eq 'repeatable') { >- unless($calendar->isHoliday($day, $month, $year)) { >- $calendar->insert_day_month_holiday(day => $day, >- month => $month, >- title => $title, >- description => $description); >- } >- } elsif ($newoperation eq 'holiday') { >- unless($calendar->isHoliday($day, $month, $year)) { >- $calendar->insert_single_holiday(day => $day, >- month => $month, >- year => $year, >- title => $title, >- description => $description); >- } >- >- } elsif ( $newoperation eq 'holidayrange' ) { >- if (@holiday_list){ >- foreach my $date (@holiday_list){ >- unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) { >- $calendar->insert_single_holiday( >- day => $date->{local_c}->{day}, >- month => $date->{local_c}->{month}, >- year => $date->{local_c}->{year}, >- title => $title, >- description => $description >- ); >- } >- } >- } >- } elsif ( $newoperation eq 'holidayrangerepeat' ) { >- if (@holiday_list){ >- foreach my $date (@holiday_list){ >- unless ( $calendar->isHoliday( $date->{local_c}->{day}, $date->{local_c}->{month}, $date->{local_c}->{year} ) ) { >- $calendar->insert_day_month_holiday( >- day => $date->{local_c}->{day}, >- month => $date->{local_c}->{month}, >- title => $title, >- description => $description >- ); >- } >- } >- } >- } >- # we updated the single_holidays table, so wipe its cache >- my $cache = Koha::Caches->get_instance(); >- $cache->clear_from_cache( 'single_holidays') ; >-} >-- >2.7.4
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17015
:
53859
|
54318
|
54419
|
59166
|
59167
|
59168
|
59169
|
59170
|
59171
|
59267
|
59268
|
59269
|
59270
|
59271
|
59463
|
59516
|
59517
|
59518
|
59519
|
59520
|
59561
|
59562
|
59586
|
59587
|
59888
|
59889
|
60902
|
60903
|
60904
|
60905
|
60906
|
60986
|
61737
|
62375
|
62376
|
62380
|
63257
|
63282
|
63362
|
63363
|
63364
|
63365
|
63366
|
63367
|
64235
|
65073
|
65074
|
65075
|
65076
|
65077
|
67721
|
67722
|
67723
|
67724
|
67725
|
67879
|
67929
|
67930
|
67931
|
67932
|
67933
|
67934
|
68392
|
68393
|
68394
|
68395
|
68396
|
68397
|
71634
|
71635
|
71636
|
71637
|
71638
|
72890
|
73145
|
74859
|
74860
|
74861
|
74862
|
74863
|
74864
|
74865
|
74866
|
75444
|
75479
|
76594
|
77249
|
77250
|
77607
|
77608
|
77609
|
77610
|
77611
|
77612
|
77613
|
77770
|
77771
|
77772
|
77773
|
77774
|
79035
|
80523
|
80524
|
80525
|
80526
|
80527
|
80528
|
80529
|
80530
|
80531
|
80532
|
80533
|
80534
|
80535
|
83547
|
85394
|
85677
|
85678
|
85679
|
85680
|
85681
|
85682
|
85683
|
85684
|
85685
|
85686
|
85687
|
85688
|
85689
|
85690
|
85691
|
92595
|
92596
|
92597
|
92598
|
100079
|
110383
|
110384
|
110386
|
110387
|
110388
|
110389
|
113541
|
113905
|
115501
|
115502
|
115503
|
115504
|
115505
|
115506
|
115507
|
115508
|
115509
|
115510
|
115511
|
118554
|
118555
|
118556
|
118557
|
118558
|
118559
|
119095
|
119097
|
119099
|
119100
|
119101
|
119102
|
131619
|
131620
|
131621
|
131622
|
131623
|
131624
|
131625
|
131626
|
131634
|
131635
|
131636
|
131637
|
131638
|
131639
|
131640
|
131641
|
131667
|
132199
|
133596
|
133597
|
133598
|
133599
|
133600
|
133601
|
133602
|
133603
|
133604
|
133605
|
133678
|
137219
|
137220
|
137221
|
137222
|
137223
|
137224
|
137225
|
137226
|
137227
|
137228
|
137229
|
139378
|
139379
|
139380
|
139381
|
139382
|
139599
|
139600
|
139601
|
139602
|
139603
|
139851
|
140150
|
141176
|
144257
|
144258
|
144259
|
144260
|
144261
|
144262
|
144264
|
144268
|
144269
|
144270
|
144271
|
144272
|
144273
|
151438
|
151439
|
151440
|
151441
|
151442
|
151443
|
151444
|
151445
|
151446
|
151447
|
151448
|
151449
|
151450
|
156340
|
156341
|
156342
|
156343
|
156344
|
156345
|
156346
|
156347
|
156348
|
156349
|
156350
|
156351
|
156352
|
156353
|
156354
|
156355
|
157656
|
157657
|
157658
|
157659
|
157660
|
157661
|
157662
|
157663
|
157664
|
157665
|
157666
|
157667
|
157668
|
157669
|
157670
|
157671
|
157672
|
167805
|
167806
|
167807
|
167808
|
167809