View | Details | Raw Unified | Return to bug 23265
Collapse All | Expand All

(-)a/installer/data/mysql/updatedatabase.pl (-9 / +16 lines)
Lines 14348-14379 if( CheckVersion( $DBversion ) ) { Link Here
14348
$DBversion = '16.12.00.032';
14348
$DBversion = '16.12.00.032';
14349
if( CheckVersion( $DBversion ) ) {
14349
if( CheckVersion( $DBversion ) ) {
14350
    require Koha::Calendar;
14350
    require Koha::Calendar;
14351
    require Koha::Holds;
14352
14351
14353
    $dbh->do(q{
14352
    $dbh->do(q{
14354
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) 
14353
        INSERT IGNORE INTO systempreferences (variable,value,explanation,options,type) 
14355
        VALUES ('ExcludeHolidaysFromMaxPickUpDelay', '0', 'If ON, reserves max pickup delay takes into account the closed days.', NULL, 'Integer');
14354
        VALUES ('ExcludeHolidaysFromMaxPickUpDelay', '0', 'If ON, reserves max pickup delay takes into account the closed days.', NULL, 'Integer');
14356
    });
14355
    });
14357
14356
14358
    my $waiting_holds = Koha::Holds->search({ found => 'W', priority => 0 });
14357
    my $waiting_holds = $dbh->selectall_arrayref(q|
14358
        SELECT expirationdate, waitingdate, branchcode
14359
        FROM reserves
14360
        WHERE found = 'W' AND priority = 0
14361
    |);
14362
    my $update_sth = $dbh->prepare(q|
14363
        UPDATE reserves
14364
        SET expirationdate = ?
14365
        WHERE reserve_id = ?
14366
    |);
14359
    my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay");
14367
    my $max_pickup_delay = C4::Context->preference("ReservesMaxPickUpDelay");
14360
    while ( my $hold = $waiting_holds->next ) {
14368
    for my $hold ( @$waiting_holds ) {
14361
14369
14362
        my $requested_expiration;
14370
        my $requested_expiration;
14363
        if ($hold->expirationdate) {
14371
        if ($hold->{expirationdate}) {
14364
            $requested_expiration = dt_from_string($hold->expirationdate);
14372
            $requested_expiration = dt_from_string($hold->{expirationdate});
14365
        }
14373
        }
14366
14374
14367
        my $expirationdate = dt_from_string($hold->waitingdate);
14375
        my $expirationdate = dt_from_string($hold->{waitingdate});
14368
        if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) {
14376
        if ( C4::Context->preference("ExcludeHolidaysFromMaxPickUpDelay") ) {
14369
            my $calendar = Koha::Calendar->new( branchcode => $hold->branchcode );
14377
            my $calendar = Koha::Calendar->new( branchcode => $hold->{branchcode} );
14370
            $expirationdate = $calendar->days_forward( $expirationdate, $max_pickup_delay );
14378
            $expirationdate = $calendar->days_forward( $expirationdate, $max_pickup_delay );
14371
        } else {
14379
        } else {
14372
            $expirationdate->add( days => $max_pickup_delay );
14380
            $expirationdate->add( days => $max_pickup_delay );
14373
        }
14381
        }
14374
14382
14375
        my $cmp = $requested_expiration ? DateTime->compare($requested_expiration, $expirationdate) : 0;
14383
        my $cmp = $requested_expiration ? DateTime->compare($requested_expiration, $expirationdate) : 0;
14376
        $hold->expirationdate($cmp == -1 ? $requested_expiration->ymd : $expirationdate->ymd)->store;
14384
        $update_sth->execute($cmp == -1 ? $requested_expiration->ymd : $expirationdate->ymd, $hold->{reserve_id});
14377
    }
14385
    }
14378
14386
14379
    SetVersion( $DBversion );
14387
    SetVersion( $DBversion );
14380
- 

Return to bug 23265