From bf13ae41d8bd12badf50101e3d026148f04365f1 Mon Sep 17 00:00:00 2001 From: The Minh Luong Date: Thu, 10 Mar 2022 10:14:21 -0500 Subject: [PATCH] Bug 17015: Rebase and tests for discrete calendar This patch is a rebase of all the previous patches in order to show the discrete calendar. TEST PLAN: 1- Apply the patch 2- Run installer/data/mysql/updatedatabase.pl 3- Run misc/cronjobs/add_days_discrete_calendar.pl 4- Check that the max date is today + 1 day 5- Run t/db_dependent/DiscreteCalendar.t (All tests should pass) --- C4/Overdues.pm | 1 - Koha/DiscreteCalendar.pm | 5 ++- misc/cronjobs/add_days_discrete_calendar.pl | 4 +-- misc/cronjobs/holds/holds_reminder.pl | 4 +-- misc/cronjobs/staticfines.pl | 1 - t/db_dependent/DiscreteCalendar.t | 34 ++++++++++----------- tools/discrete_calendar.pl | 6 ++-- 7 files changed, 26 insertions(+), 29 deletions(-) diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 521e893b1d..baba72c719 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -31,7 +31,6 @@ use C4::Context; use C4::Accounts; use Koha::Logger; use C4::Log; # logaction -use C4::Debug; use Koha::DateUtils; use Koha::DiscreteCalendar; use Koha::Account::Lines; diff --git a/Koha/DiscreteCalendar.pm b/Koha/DiscreteCalendar.pm index f80916305b..17c633eab9 100644 --- a/Koha/DiscreteCalendar.pm +++ b/Koha/DiscreteCalendar.pm @@ -27,7 +27,7 @@ use Data::Dumper; use C4::Context; use C4::Output; use Koha::Database; -use Koha::DateUtils; +use Koha::DateUtils qw ( dt_from_string output_pref ); # Global variables to make code more readable our $HOLIDAYS = { @@ -502,9 +502,8 @@ sub get_week_days_holidays { branchcode => $branchcode, }, { - select => [{ DAYOFWEEK => 'date'}, 'note'], + select => \[ 'distinct DAYOFWEEK(date), note'], as => [qw/ weekday note /], - distinct => 1, where => ($exclude_past ? \[' date >= CURRENT_DATE()'] : {} ), } ); diff --git a/misc/cronjobs/add_days_discrete_calendar.pl b/misc/cronjobs/add_days_discrete_calendar.pl index 327c35c315..1c146ce44d 100755 --- a/misc/cronjobs/add_days_discrete_calendar.pl +++ b/misc/cronjobs/add_days_discrete_calendar.pl @@ -11,7 +11,7 @@ use Getopt::Long; use C4::Context; use Koha::Database; use Koha::DiscreteCalendar; -use Koha::DateUtils; +use Koha::DateUtils qw ( output_pref ); # Options my $help = 0; @@ -162,4 +162,4 @@ foreach my $branchCode (@branches) { } } # If everything went well we commit to the database -$schema->storage->txn_commit; \ No newline at end of file +$schema->storage->txn_commit; diff --git a/misc/cronjobs/holds/holds_reminder.pl b/misc/cronjobs/holds/holds_reminder.pl index c0fabb2017..469b0c5c5e 100755 --- a/misc/cronjobs/holds/holds_reminder.pl +++ b/misc/cronjobs/holds/holds_reminder.pl @@ -26,7 +26,7 @@ use C4::Context; use C4::Letters; use C4::Log qw( cronlogaction ); use Koha::DateUtils qw( dt_from_string ); -use Koha::Calendar; +use Koha::DiscreteCalendar; use Koha::Libraries; use Koha::Notice::Templates; use Koha::Patrons; @@ -244,7 +244,7 @@ foreach my $branchcode (@branchcodes) { #BEGIN BRANCH LOOP # If respecting calendar get the correct waiting since date my $waiting_date; if( $use_calendar ){ - my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => 'Calendar' ); + my $calendar = Koha::DiscreteCalendar->new( branchcode => $branchcode, days_mode => 'Calendar' ); my $duration = DateTime::Duration->new( days => -$days ); $waiting_date = $calendar->addDays($date_to_run,$duration); #Add negative of days } else { diff --git a/misc/cronjobs/staticfines.pl b/misc/cronjobs/staticfines.pl index 77e7741eb2..d162a65366 100755 --- a/misc/cronjobs/staticfines.pl +++ b/misc/cronjobs/staticfines.pl @@ -39,7 +39,6 @@ use Koha::DateUtils qw( dt_from_string output_pref ); use C4::Circulation; use Koha::DiscreteCalendar qw(); # don't need any exports from Calendar use C4::Biblio; -use C4::Debug; # supplying $debug and $cgi_debug use Koha::Patrons; my $help = 0; diff --git a/t/db_dependent/DiscreteCalendar.t b/t/db_dependent/DiscreteCalendar.t index 7bf12a31a4..1b245b8c4f 100755 --- a/t/db_dependent/DiscreteCalendar.t +++ b/t/db_dependent/DiscreteCalendar.t @@ -23,7 +23,7 @@ use Test::MockModule; use C4::Context; use C4::Output; -use Koha::DateUtils; +use Koha::DateUtils qw ( dt_from_string ); use Koha::DiscreteCalendar; @@ -127,7 +127,7 @@ $calendar->edit_holiday({ end_date=>$unique_holiday_range_end }); @unique_holidays = $calendar->get_unique_holidays(); -is(scalar @unique_holidays, 8, "Set of exception holidays at 7"); +is(scalar @unique_holidays, 7, "Set of exception holidays at 7"); my $repeatable_holiday_range_start = DateTime->today->add(days => 8); my $repeatable_holiday_range_end = DateTime->today->add(days => 13); @@ -281,15 +281,15 @@ $calendar->edit_holiday({ end_date=>$tomorrow }); -is($calendar->addDate( $today, $one_day_dur, 'days' )->ymd(), +is($calendar->addDuration( $today, $one_day_dur, 'days' )->ymd(), $today->add(days => 2)->ymd(), 'Single day add (Calendar)' ); -is($calendar->addDate( $today, $two_day_dur, 'days' )->ymd(), +is($calendar->addDuration( $today, $two_day_dur, 'days' )->ymd(), $today->add(days => 2)->ymd(), 'Two days add, skips holiday (Calendar)' ); -cmp_ok($calendar->addDate( $today, $seven_day_dur, 'days' )->ymd(), 'eq', +cmp_ok($calendar->addDuration( $today, $seven_day_dur, 'days' )->ymd(), 'eq', $today->add(days => 7)->ymd(), 'Add 7 days (Calendar)' ); #Closed Sunday @@ -300,7 +300,7 @@ $calendar->edit_holiday({ start_date=>$today, end_date=>$today }); -is( $calendar->addDate( $sunday, $one_day_dur, 'days' )->day_of_week, 1, +is( $calendar->addDuration( $sunday, $one_day_dur, 'days' )->day_of_week, 1, 'addDate skips closed Sunday (Calendar)' ); #to remove the closed sundays $today = DateTime->today; @@ -311,7 +311,7 @@ $calendar->edit_holiday({ end_date=>$delete_range_end }); -is( $calendar->addDate($today, $negative_one_day_dur , 'days')->ymd(), +is( $calendar->addDuration($today, $negative_one_day_dur , 'days')->ymd(), $today->add(days => - 1)->ymd(), 'Negative call to addDate (Calendar)' ); @@ -332,15 +332,15 @@ $calendar->edit_holiday({ end_date=>$tomorrow }); -is($calendar->addDate( $today, $one_day_dur, 'days' )->ymd(), +is($calendar->addDuration( $today, $one_day_dur, 'days' )->ymd(), $today->add(days => 2)->ymd(), 'Single day add' ); -is($calendar->addDate( $today, $two_day_dur, 'days' )->ymd(), +is($calendar->addDuration( $today, $two_day_dur, 'days' )->ymd(), $today->add(days => 2)->ymd(), 'Two days add, skips holiday (Datedue)' ); -cmp_ok($calendar->addDate( $today, $seven_day_dur, 'days' )->ymd(), 'eq', +cmp_ok($calendar->addDuration( $today, $seven_day_dur, 'days' )->ymd(), 'eq', $today->add(days => 7)->ymd(), 'Add 7 days (Datedue)' ); #Closed Sunday @@ -351,7 +351,7 @@ $calendar->edit_holiday({ start_date=>$today, end_date=>$today }); -is( $calendar->addDate( $sunday, $one_day_dur, 'days' )->day_of_week, 1, +is( $calendar->addDuration( $sunday, $one_day_dur, 'days' )->day_of_week, 1, 'addDate skips closed Sunday (Datedue)' ); #to remove the closed sundays $today = DateTime->today; @@ -362,7 +362,7 @@ $calendar->edit_holiday({ end_date=>$delete_range_end }); -is( $calendar->addDate($today, $negative_one_day_dur , 'days')->ymd(), +is( $calendar->addDuration($today, $negative_one_day_dur , 'days')->ymd(), $today->add(days => - 1)->ymd(), 'Negative call to addDate (Datedue)' ); @@ -382,15 +382,15 @@ $calendar->edit_holiday({ start_date=>$tomorrow, end_date=>$tomorrow }); -is($calendar->addDate( $today, $one_day_dur, 'days' )->ymd(), +is($calendar->addDuration( $today, $one_day_dur, 'days' )->ymd(), $today->add(days => 1)->ymd(), 'Single day add' ); -is($calendar->addDate( $today, $two_day_dur, 'days' )->ymd(), +is($calendar->addDuration( $today, $two_day_dur, 'days' )->ymd(), $today->add(days => 2)->ymd(), 'Two days add, skips holiday (Days)' ); -cmp_ok($calendar->addDate( $today, $seven_day_dur, 'days' )->ymd(), 'eq', +cmp_ok($calendar->addDuration( $today, $seven_day_dur, 'days' )->ymd(), 'eq', $today->add(days => 7)->ymd(), 'Add 7 days (Days)' ); #Closed Sunday @@ -401,10 +401,10 @@ $calendar->edit_holiday({ start_date => $today, end_date => $today }); -is( $calendar->addDate( $sunday, $one_day_dur, 'days' )->day_of_week, 1, +is( $calendar->addDuration( $sunday, $one_day_dur, 'days' )->day_of_week, 1, 'addDate skips closed Sunday (Days)' ); -is( $calendar->addDate($today, $negative_one_day_dur , 'days')->ymd(), +is( $calendar->addDuration($today, $negative_one_day_dur , 'days')->ymd(), $today->add(days => - 1)->ymd(), 'Negative call to addDate (Days)' ); diff --git a/tools/discrete_calendar.pl b/tools/discrete_calendar.pl index 1adf19b72e..f5c740e919 100755 --- a/tools/discrete_calendar.pl +++ b/tools/discrete_calendar.pl @@ -20,10 +20,10 @@ use Modern::Perl; use CGI qw ( -utf8 ); -use C4::Auth; -use C4::Output; +use C4::Auth qw ( get_template_and_user ); +use C4::Output qw ( output_html_with_http_headers ); -use Koha::DateUtils; +use Koha::DateUtils qw ( dt_from_string output_pref ); use Koha::DiscreteCalendar; my $input = CGI->new; -- 2.25.1