From a440802ae33a5de3d84336dda63eb55b8c3001d5 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 8 Apr 2020 10:43:54 +0100 Subject: [PATCH] Bug 24840: Catch some further cases of DateTime->now This patch corrects a few additional cases where DateTime->now is called directly instead of via Koha::DateUtils. Signed-off-by: Jonathan Druart --- Koha/Illrequest.pm | 3 ++- Koha/StockRotationItem.pm | 12 ++++++------ misc/cronjobs/update_totalissues.pl | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm index bc39152d58..5ab0adc210 100644 --- a/Koha/Illrequest.pm +++ b/Koha/Illrequest.pm @@ -27,6 +27,7 @@ use Try::Tiny; use DateTime; use Koha::Database; +use Koha::DateUtils qw/ dt_from_string /; use Koha::Email; use Koha::Exceptions::Ill; use Koha::Illcomments; @@ -688,7 +689,7 @@ Mark a request as completed (status = COMP). sub mark_completed { my ( $self ) = @_; $self->status('COMP')->store; - $self->completed(DateTime->now)->store; + $self->completed(dt_from_string())->store; return { error => 0, status => '', diff --git a/Koha/StockRotationItem.pm b/Koha/StockRotationItem.pm index 430dfcb00f..b46dc3cc88 100644 --- a/Koha/StockRotationItem.pm +++ b/Koha/StockRotationItem.pm @@ -129,7 +129,7 @@ sub needs_advancing { ); my $duration = DateTime::Duration ->new( days => $self->stage->duration ); - if ( $arrival + $duration le DateTime->now ) { + if ( $arrival + $duration le dt_from_string() ) { return 1; } else { return 0; @@ -155,7 +155,7 @@ sub repatriate { 'itemnumber' => $self->itemnumber_id, 'frombranch' => $self->itemnumber->holdingbranch, 'tobranch' => $self->stage->branchcode_id, - 'datesent' => DateTime->now, + 'datesent' => dt_from_string(), 'comments' => $msg, 'reason' => "StockrotationRepatriation" })->store; @@ -185,14 +185,14 @@ sub advance { my $transfer = Koha::Item::Transfer->new({ 'itemnumber' => $self->itemnumber_id, 'frombranch' => $item->holdingbranch, - 'datesent' => DateTime->now, + 'datesent' => dt_from_string(), 'reason' => "StockrotationAdvance" }); if ( $self->indemand && !$self->fresh ) { $self->indemand(0)->store; # De-activate indemand $transfer->tobranch($self->stage->branchcode_id); - $transfer->datearrived(DateTime->now); + $transfer->datearrived(dt_from_string()); } else { # Find and update our stage. my $stage = $self->stage; @@ -200,7 +200,7 @@ sub advance { if ( $self->fresh ) { # Just added to rota $new_stage = $self->stage->first_sibling || $self->stage; $transfer->tobranch($new_stage->branchcode_id); - $transfer->datearrived(DateTime->now) # Already at first branch + $transfer->datearrived(dt_from_string()) # Already at first branch if $item->holdingbranch eq $new_stage->branchcode_id; $self->fresh(0)->store; # Reset fresh } elsif ( !$stage->last_sibling ) { # Last stage @@ -208,7 +208,7 @@ sub advance { # Revert to first stage. $new_stage = $stage->first_sibling || $stage; $transfer->tobranch($new_stage->branchcode_id); - $transfer->datearrived(DateTime->now); + $transfer->datearrived(dt_from_string()); } else { $self->delete; # StockRotationItem is done. return 1; diff --git a/misc/cronjobs/update_totalissues.pl b/misc/cronjobs/update_totalissues.pl index 7e24d0788d..6421779d16 100755 --- a/misc/cronjobs/update_totalissues.pl +++ b/misc/cronjobs/update_totalissues.pl @@ -32,6 +32,7 @@ use Getopt::Long; use Pod::Usage; use Koha::Script -cron; +use Koha::DateUtils qw/ dt_from_string /; use C4::Context; use C4::Biblio; use C4::Log; @@ -122,7 +123,7 @@ sub process_items { sub process_stats { if ($interval) { - my $dt = DateTime->now; + my $dt = dt_from_string(); my %units = ( h => 'hours', -- 2.20.1