Bug 19626: (QA follow-up) Small optimization
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Fri, 17 Nov 2017 08:23:40 +0000 (09:23 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Sun, 26 Nov 2017 16:00:03 +0000 (13:00 -0300)
We are only using $calendar when the pref is set.
Date calculation can be moved in if-else structure.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>

installer/data/mysql/updatedatabase.pl

index f12d8d0..bd60c08 100755 (executable)
@@ -14370,12 +14370,12 @@ if( CheckVersion( $DBversion ) ) {
             $requested_expiration = dt_from_string($hold->expirationdate);
         }
 
-        my $calendar = Koha::Calendar->new( branchcode => $hold->branchcode );
         my $expirationdate = dt_from_string($hold->waitingdate);
-        $expirationdate->add(days => $max_pickup_delay);
-
         if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) {
-            $expirationdate = $calendar->days_forward( dt_from_string($hold->waitingdate), $max_pickup_delay );
+            my $calendar = Koha::Calendar->new( branchcode => $hold->branchcode );
+            $expirationdate = $calendar->days_forward( $expirationdate, $max_pickup_delay );
+        } else {
+            $expirationdate->add( days => $max_pickup_delay );
         }
 
         my $cmp = $requested_expiration ? DateTime->compare($requested_expiration, $expirationdate) : 0;