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

(-)a/Koha/UploadedFiles.pm (-3 / +6 lines)
Lines 86-94 Returns true if no errors occur. (Even when no files had to be deleted.) Link Here
86
86
87
sub delete_temporary {
87
sub delete_temporary {
88
    my ( $self, $params ) = @_;
88
    my ( $self, $params ) = @_;
89
    my $days = $params->{override_pref} ||
89
    my $days = C4::Context->preference('UploadPurgeTemporaryFilesDays');
90
        C4::Context->preference('UploadPurgeTemporaryFilesDays');
90
    if( exists $params->{override_pref} ) {
91
    return 1 if !$days;
91
        $days = $params->{override_pref};
92
    } elsif( !defined($days) || $days eq '' ) { # allow 0, not NULL or ""
93
        return 1;
94
    }
92
    my $dt = dt_from_string();
95
    my $dt = dt_from_string();
93
    $dt->subtract( days => $days );
96
    $dt->subtract( days => $days );
94
    my $parser = Koha::Database->new->schema->storage->datetime_parser;
97
    my $parser = Koha::Database->new->schema->storage->datetime_parser;
(-)a/misc/cronjobs/cleanup_database.pl (-3 / +4 lines)
Lines 311-321 if ($special_holidays_days) { Link Here
311
}
311
}
312
312
313
if( $temp_uploads ) {
313
if( $temp_uploads ) {
314
    # Delete temporary uploads, governed by a pref.
314
    # Delete temporary uploads, governed by a pref (unless you override)
315
    # If the pref is empty, nothing happens (unless you override).
316
    print "Purging temporary uploads.\n" if $verbose;
315
    print "Purging temporary uploads.\n" if $verbose;
317
    Koha::UploadedFiles->delete_temporary({
316
    Koha::UploadedFiles->delete_temporary({
318
        override_pref => $temp_uploads_days,
317
        defined($temp_uploads_days)
318
            ? ( override_pref => $temp_uploads_days )
319
            : ()
319
    });
320
    });
320
    print "Done purging temporary uploads.\n" if $verbose;
321
    print "Done purging temporary uploads.\n" if $verbose;
321
}
322
}
(-)a/t/db_dependent/Upload.t (-12 / +8 lines)
Lines 245-251 subtest 'Testing allows_add_by' => sub { Link Here
245
};
245
};
246
246
247
subtest 'Testing delete_temporary' => sub {
247
subtest 'Testing delete_temporary' => sub {
248
    plan tests => 7;
248
    plan tests => 6;
249
249
250
    # Add two temporary files: result should be 3 + 3
250
    # Add two temporary files: result should be 3 + 3
251
    Koha::Uploader->new({ tmp => 1 })->cgi; # add file6 and file7
251
    Koha::Uploader->new({ tmp => 1 })->cgi; # add file6 and file7
Lines 268-288 subtest 'Testing delete_temporary' => sub { Link Here
268
    $recs[1]->dtcreated($dt)->store;
268
    $recs[1]->dtcreated($dt)->store;
269
    $recs[2]->dtcreated($dt)->store;
269
    $recs[2]->dtcreated($dt)->store;
270
270
271
    # Now call delete_temporary with 0, 6, 5 and 1 (via override)
271
    # Now call delete_temporary with 6, 5 and 0
272
    t::lib::Mocks::mock_preference('UploadPurgeTemporaryFilesDays', 0 );
273
    Koha::UploadedFiles->delete_temporary;
274
    is( Koha::UploadedFiles->search->count, 6, 'Delete with pref==0' );
275
276
    t::lib::Mocks::mock_preference('UploadPurgeTemporaryFilesDays', 6 );
272
    t::lib::Mocks::mock_preference('UploadPurgeTemporaryFilesDays', 6 );
277
    Koha::UploadedFiles->delete_temporary;
273
    Koha::UploadedFiles->delete_temporary;
278
    is( Koha::UploadedFiles->search->count, 6, 'Delete with pref==6' );
274
    is( Koha::UploadedFiles->search->count, 6, 'Delete with pref==6' );
279
275
280
    t::lib::Mocks::mock_preference('UploadPurgeTemporaryFilesDays', 5 );
276
    # use override parameter
281
    Koha::UploadedFiles->delete_temporary;
277
    Koha::UploadedFiles->delete_temporary({ override_pref => 5 });
282
    is( Koha::UploadedFiles->search->count, 4, 'Delete with pref==5 makes 4' );
278
    is( Koha::UploadedFiles->search->count, 4, 'Delete with override==5' );
283
279
284
    Koha::UploadedFiles->delete_temporary({ override_pref => 1 });
280
    t::lib::Mocks::mock_preference('UploadPurgeTemporaryFilesDays', 0 );
285
    is( Koha::UploadedFiles->search->count, 3, 'Delete override==1 makes 3' );
281
    Koha::UploadedFiles->delete_temporary;
282
    is( Koha::UploadedFiles->search->count, 3, 'Delete with pref==0 makes 3' );
286
    is( Koha::UploadedFiles->search({ permanent => 1 })->count, 3,
283
    is( Koha::UploadedFiles->search({ permanent => 1 })->count, 3,
287
        'Still 3 permanent uploads' );
284
        'Still 3 permanent uploads' );
288
};
285
};
289
- 

Return to bug 17669