From 249909a178c0e8ba8849e37532a009aac99e9368 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20V=C3=A9ron?= Date: Mon, 5 Oct 2015 18:20:57 +0200 Subject: [PATCH] Bug 14960 - Remove C4::Dates from files in misc/cronjobs This patch removes C4::Dates from following files: - misc/cronjobs/batch_anonymise.pl - misc/cronjobs/cleanup_database.pl - misc/cronjobs/gather_print_notices.pl - misc/cronjobs/serialsUpdate.pl - misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl - misc/cronjobs/overdue_notices.pl - misc/cronjobs/staticfines.pl To test: - Carefully review code changes. - Verify that the cronjobs behave as before. --- misc/cronjobs/batch_anonymise.pl | 1 - misc/cronjobs/cleanup_database.pl | 1 - misc/cronjobs/gather_print_notices.pl | 1 - misc/cronjobs/overdue_notices.pl | 15 +++++++++------ misc/cronjobs/serialsUpdate.pl | 4 ++-- misc/cronjobs/staticfines.pl | 15 +++++++-------- misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl | 6 +++--- 7 files changed, 21 insertions(+), 22 deletions(-) diff --git a/misc/cronjobs/batch_anonymise.pl b/misc/cronjobs/batch_anonymise.pl index 45868dc..c90842f 100755 --- a/misc/cronjobs/batch_anonymise.pl +++ b/misc/cronjobs/batch_anonymise.pl @@ -31,7 +31,6 @@ BEGIN { use C4::Context; use C4::Circulation; -use C4::Dates; use Date::Calc qw( Today Add_Delta_Days diff --git a/misc/cronjobs/cleanup_database.pl b/misc/cronjobs/cleanup_database.pl index 0766141..0265e84 100755 --- a/misc/cronjobs/cleanup_database.pl +++ b/misc/cronjobs/cleanup_database.pl @@ -35,7 +35,6 @@ BEGIN { } use C4::Context; -use C4::Dates; use C4::Search; use Getopt::Long; use C4::Log; diff --git a/misc/cronjobs/gather_print_notices.pl b/misc/cronjobs/gather_print_notices.pl index d573f04..2e898b7 100755 --- a/misc/cronjobs/gather_print_notices.pl +++ b/misc/cronjobs/gather_print_notices.pl @@ -11,7 +11,6 @@ BEGIN { use CGI qw( utf8 ); # NOT a CGI script, this is just to keep C4::Templates::gettemplate happy use C4::Context; -use C4::Dates; use C4::Debug; use C4::Letters; use C4::Templates; diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index 482be02..9c5a889 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -38,7 +38,6 @@ use DateTime; use DateTime::Duration; use C4::Context; -use C4::Dates qw/format_date/; use C4::Debug; use C4::Letters; use C4::Overdues qw(GetFine GetOverdueMessageTransportTypes); @@ -46,6 +45,7 @@ use C4::Budgets qw(GetCurrency); use Koha::Borrower::Debarments qw(AddUniqueDebarment); use Koha::DateUtils; use Koha::Calendar; +use Koha::DateUtils; use C4::Log; =head1 NAME @@ -527,7 +527,7 @@ END_SQL my $borrowernumber; while ( my $data = $sth->fetchrow_hashref ) { - next unless ( DateTime->compare( $date_to_run, dt_from_string($data->{date_due})) ) == 1; + next unless ( DateTime->compare( $date_to_run, dt_from_string($data->{date_due})) ) == 1; # check the borrower has at least one item that matches my $days_between; @@ -536,12 +536,12 @@ END_SQL my $calendar = Koha::Calendar->new( branchcode => $branchcode ); $days_between = - $calendar->days_between( dt_from_string($data->{date_due}), + $calendar->days_between( dt_from_string($data->{date_due}), $date_to_run ); } else { $days_between = - $date_to_run->delta_days( dt_from_string($data->{date_due}) ); + $date_to_run->delta_days( dt_from_string($data->{date_due}) ); } $days_between = $days_between->in_units('days'); if ($triggered) { @@ -657,7 +657,10 @@ END_SQL last; } $j++; - my @item_info = map { $_ =~ /^date|date$/ ? format_date( $item_info->{$_} ) : $item_info->{$_} || '' } @item_content_fields; + my @item_info = map { $_ =~ /^date|date$/ ? + eval { output_pref( { dt => dt_from_string( $item_info->{$_} ), dateonly => 1 } ); } + : + $item_info->{$_} || '' } @item_content_fields; $titles .= join("\t", @item_info) . "\n"; $itemcount++; push @items, $item_info; @@ -853,7 +856,7 @@ sub parse_letter { } my $substitute = $params->{'substitute'} || {}; - $substitute->{today} ||= C4::Dates->new()->output("syspref"); + $substitute->{today} ||= output_pref( { dt => dt_from_string , dateonly => 1 } ); my %tables = ( 'borrowers' => $params->{'borrowernumber'} ); if ( my $p = $params->{'branchcode'} ) { diff --git a/misc/cronjobs/serialsUpdate.pl b/misc/cronjobs/serialsUpdate.pl index fedf064..b648554 100755 --- a/misc/cronjobs/serialsUpdate.pl +++ b/misc/cronjobs/serialsUpdate.pl @@ -29,10 +29,10 @@ BEGIN { } use C4::Context; -use C4::Dates qw/format_date format_date_in_iso/; use C4::Debug; use C4::Serials; use C4::Log; +use Koha::DateUtils; use Date::Calc qw/Date_to_Days check_date/; use Getopt::Long; @@ -119,7 +119,7 @@ while ( my $issue = $sth->fetchrow_hashref ) { if ( $subscription && $publisheddate && $publisheddate ne "0000-00-00" ) { my $nextpublisheddate = GetNextDate( $subscription, $publisheddate ); - my $today = format_date_in_iso( C4::Dates->new()->output() ); + my $today = output_pref({ dt => dt_from_string, dateformat => 'iso', dateonly => 1 }); if ( $nextpublisheddate && $today ) { my ( $year, $month, $day ) = split( /-/, $nextpublisheddate ); diff --git a/misc/cronjobs/staticfines.pl b/misc/cronjobs/staticfines.pl index eb5284c..de92c65 100755 --- a/misc/cronjobs/staticfines.pl +++ b/misc/cronjobs/staticfines.pl @@ -103,7 +103,7 @@ foreach (@pcategories) { } use vars qw(@borrower_fields @item_fields @other_fields); -use vars qw($fldir $libname $control $mode $delim $dbname $today $today_iso $today_days); +use vars qw($fldir $libname $control $mode $delim $dbname $today_iso $today_days); use vars qw($filename); CHECK { @@ -135,8 +135,7 @@ if (defined $borrowernumberlimit) { } my $overdueItemsCounted = 0; my %calendars = (); -$today = C4::Dates->new(); -$today_iso = $today->output('iso'); +$today_iso = output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } ); my ($tyear, $tmonth, $tday) = split( /-/, $today_iso ); $today_days = Date_to_Days( $tyear, $tmonth, $tday ); @@ -145,14 +144,14 @@ for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) { my $datedue; my $datedue_days; eval { - $datedue = C4::Dates->new( $data->[$i]->{'date_due'}, 'iso' ); - $datedue_days = Date_to_Days( split( /-/, $datedue->output('iso') ) ); + $datedue = eval { output_pref( { dt => dt_from_string( $data->[$i]->{'date_due'} ), dateonly => 1, dateformat => 'iso' } ); }; + $datedue_days = Date_to_Days( split( /-/, $datedue ) ); }; if ($@) { warn "Error on date for borrower " . $data->[$i]->{'borrowernumber'} . ": $@date_due: " . $data->[$i]->{'date_due'} . "\ndatedue_days: " . $datedue_days . "\nSkipping"; next; } - my $due_str = $datedue->output(); + my $due_str = eval { output_pref( { dt => dt_from_string( $datedue ), dateonly => 1 } ); }; unless ( defined $data->[$i]->{'borrowernumber'} ) { print STDERR "ERROR in Getoverdues line $i: issues.borrowernumber IS NULL. Repair 'issues' table now! Skipping record.\n"; next; # Note: this doesn't solve everything. After NULL borrowernumber, multiple issues w/ real borrowernumbers can pile up. @@ -192,8 +191,8 @@ for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) { $data->[$i], $borrower->{'categorycode'}, $branchcode, - dt_from_string($datedue->output('iso')), - dt_from_string($today->output('iso')), + dt_from_string( $datedue ), + dt_from_string( $today_iso ), ); # Reassign fine's amount if specified in command-line diff --git a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl b/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl index d4063d4..18e9f86 100755 --- a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl +++ b/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl @@ -36,8 +36,8 @@ use C4::Context; use C4::Items; use C4::Letters; use C4::Overdues; -use C4::Dates; use C4::Calendar; +use Koha::DateUtils; sub usage { pod2usage( -verbose => 2 ); @@ -124,8 +124,8 @@ foreach my $type (@types) { } foreach my $issues (@loop) { - my $date = C4::Dates->new( $issues->{'date_due'}, 'iso' ); - my $due_date = $date->output('metric'); + my $date_dt = dt_from_string ( $issues->{'date_due'} ); + my $due_date = output_pref( { dt => $date_dt, dateonly => 1, dateformat =>'metric' } ); my $letter = C4::Letters::GetPreparedLetter( module => $module, -- 1.7.10.4