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

(-)a/Koha/Objects.pm (+13 lines)
Lines 170-175 sub search_related { Link Here
170
    }
170
    }
171
}
171
}
172
172
173
sub filter_by_last_update {
174
    my ( $self, $params ) = @_;
175
    my $timestamp_column_name = $params->{timestamp_column_name} || 'timestamp';
176
    return $self->_resultset->search(
177
        {
178
            $timestamp_column_name => {
179
                '<' =>
180
                  [ \'DATE_SUB(CURDATE(), INTERVAL ? DAY)', $params->{days} ]
181
            }
182
        }
183
    );
184
}
185
173
=head3 single
186
=head3 single
174
187
175
my $object = Koha::Objects->search({}, { rows => 1 })->single
188
my $object = Koha::Objects->search({}, { rows => 1 })->single
(-)a/misc/cronjobs/cleanup_database.pl (-57 / +20 lines)
Lines 42-47 use Getopt::Long; Link Here
42
use C4::Log;
42
use C4::Log;
43
use C4::Accounts;
43
use C4::Accounts;
44
use Koha::UploadedFiles;
44
use Koha::UploadedFiles;
45
use Koha::Old::Biblios;
46
use Koha::Old::Items;
47
use Koha::Old::Biblioitems;
48
use Koha::Item::Transfers;
49
45
50
46
sub usage {
51
sub usage {
47
    print STDERR <<USAGE;
52
    print STDERR <<USAGE;
Lines 380-467 if ($oauth_tokens) { Link Here
380
385
381
if ($pStatistics) {
386
if ($pStatistics) {
382
    print "Purging statistics older than $pStatistics days.\n" if $verbose;
387
    print "Purging statistics older than $pStatistics days.\n" if $verbose;
383
    $sth = $dbh->prepare(
388
    Koha::Statistics->filter_by_last_update(
384
        q{
389
        { timestamp_column_name => 'datetime', days => $pStatistics } )->delete;
385
            DELETE FROM statistics
386
            WHERE datetime < DATE_SUB(CURDATE(), INTERVAL ? DAY)
387
        }
388
    );
389
    $sth->execute($pStatistics);
390
    print "Done with purging statistics.\n" if $verbose;
390
    print "Done with purging statistics.\n" if $verbose;
391
}
391
}
392
392
393
if ($pDeletedCatalog) {
393
if ($pDeletedCatalog) {
394
    print "Purging deleted catalog older than $pDeletedCatalog days.\n" if $verbose;
394
    print "Purging deleted catalog older than $pDeletedCatalog days.\n" if $verbose;
395
    my $sth1 = $dbh->prepare(
395
    Koha::Old::Items      ->filter_by_last_update( { days => $pDeletedCatalog } )->delete;
396
        q{
396
    Koha::Old::Biblioitems->filter_by_last_update( { days => $pDeletedCatalog } )->delete;
397
            DELETE FROM deleteditems
397
    Koha::Old::Biblios    ->filter_by_last_update( { days => $pDeletedCatalog } )->delete;
398
            WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY)
399
        }
400
    );
401
    my $sth2 = $dbh->prepare(
402
        q{
403
            DELETE FROM deletedbiblioitems
404
            WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY)
405
        }
406
    );
407
    my $sth3 = $dbh->prepare(
408
        q{
409
            DELETE FROM deletedbiblio
410
            WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY)
411
        }
412
    );
413
    # deletedbiblio_metadata is managed by FK with deletedbiblio
414
    $sth1->execute($pDeletedCatalog);
415
    $sth2->execute($pDeletedCatalog);
416
    $sth3->execute($pDeletedCatalog);
417
    print "Done with purging deleted catalog.\n" if $verbose;
398
    print "Done with purging deleted catalog.\n" if $verbose;
418
}
399
}
419
400
420
if ($pDeletedPatrons) {
401
if ($pDeletedPatrons) {
421
    print "Purging deleted patrons older than $pDeletedPatrons days.\n" if $verbose;
402
    print "Purging deleted patrons older than $pDeletedPatrons days.\n" if $verbose;
422
    $sth = $dbh->prepare(
403
    Koha::Old::Patrons->filter_by_last_update(
423
        q{
404
        { timestamp_column_name => 'updated_on', days => $pDeletedPatrons } )
424
            DELETE FROM deletedborrowers
405
      ->delete;
425
            WHERE updated_on < DATE_SUB(CURDATE(), INTERVAL ? DAY)
426
        }
427
    );
428
    $sth->execute($pDeletedPatrons);
429
    print "Done with purging deleted patrons.\n" if $verbose;
406
    print "Done with purging deleted patrons.\n" if $verbose;
430
}
407
}
431
408
432
if ($pOldIssues) {
409
if ($pOldIssues) {
433
    print "Purging old issues older than $pOldIssues days.\n" if $verbose;
410
    print "Purging old issues older than $pOldIssues days.\n" if $verbose;
434
    $sth = $dbh->prepare(
411
    Koha::Old::Checkouts->filter_by_last_update( { days => $pOldIssues } )->delete;
435
        q{
436
            DELETE FROM old_issues
437
            WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY)
438
        }
439
    );
440
    $sth->execute($pOldIssues);
441
    print "Done with purging old issues.\n" if $verbose;
412
    print "Done with purging old issues.\n" if $verbose;
442
}
413
}
443
414
444
if ($pOldReserves) {
415
if ($pOldReserves) {
445
    print "Purging old reserves older than $pOldReserves days.\n" if $verbose;
416
    print "Purging old reserves older than $pOldReserves days.\n" if $verbose;
446
    $sth = $dbh->prepare(
417
    Koha::Old::Holds->filter_by_last_update( { days => $pOldReserves } )->delete;
447
        q{
448
            DELETE FROM old_reserves
449
            WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY)
450
        }
451
    );
452
    $sth->execute($pOldReserves);
453
    print "Done with purging old reserves.\n" if $verbose;
418
    print "Done with purging old reserves.\n" if $verbose;
454
}
419
}
455
420
456
if ($pTransfers) {
421
if ($pTransfers) {
457
    print "Purging arrived item transfers older than $pTransfers days.\n" if $verbose;
422
    print "Purging arrived item transfers older than $pTransfers days.\n" if $verbose;
458
    $sth = $dbh->prepare(
423
    Koha::Item::Transfers->filter_by_last_update(
459
        q{
424
        {
460
            DELETE FROM branchtransfers
425
            timestamp_column_name => 'datearrived',
461
            WHERE datearrived < DATE_SUB(CURDATE(), INTERVAL ? DAY)
426
            days => $pTransfers,
462
        }
427
        }
463
    );
428
    )->delete;
464
    $sth->execute($pTransfers);
465
    print "Done with purging transfers.\n" if $verbose;
429
    print "Done with purging transfers.\n" if $verbose;
466
}
430
}
467
431
468
- 

Return to bug 24152