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

(-)a/Koha/Objects.pm (+13 lines)
Lines 252-257 sub update { Link Here
252
    return $self->_resultset->update($fields);
252
    return $self->_resultset->update($fields);
253
}
253
}
254
254
255
sub filter_by_last_update {
256
    my ( $self, $params ) = @_;
257
    my $timestamp_column_name = $params->{timestamp_column_name} || 'timestamp';
258
    return $self->_resultset->search(
259
        {
260
            $timestamp_column_name => {
261
                '<' =>
262
                  [ \'DATE_SUB(CURDATE(), INTERVAL ? DAY)', $params->{days} ]
263
            }
264
        }
265
    );
266
}
267
255
=head3 single
268
=head3 single
256
269
257
my $object = Koha::Objects->search({}, { rows => 1 })->single
270
my $object = Koha::Objects->search({}, { rows => 1 })->single
(-)a/misc/cronjobs/cleanup_database.pl (-57 / +23 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::Old::Checkouts;
49
use Koha::Old::Holds;
50
use Koha::Old::Patrons;
51
use Koha::Item::Transfers;
52
45
53
46
sub usage {
54
sub usage {
47
    print STDERR <<USAGE;
55
    print STDERR <<USAGE;
Lines 395-482 if ($oauth_tokens) { Link Here
395
403
396
if ($pStatistics) {
404
if ($pStatistics) {
397
    print "Purging statistics older than $pStatistics days.\n" if $verbose;
405
    print "Purging statistics older than $pStatistics days.\n" if $verbose;
398
    $sth = $dbh->prepare(
406
    Koha::Statistics->filter_by_last_update(
399
        q{
407
        { timestamp_column_name => 'datetime', days => $pStatistics } )->delete;
400
            DELETE FROM statistics
401
            WHERE datetime < DATE_SUB(CURDATE(), INTERVAL ? DAY)
402
        }
403
    );
404
    $sth->execute($pStatistics);
405
    print "Done with purging statistics.\n" if $verbose;
408
    print "Done with purging statistics.\n" if $verbose;
406
}
409
}
407
410
408
if ($pDeletedCatalog) {
411
if ($pDeletedCatalog) {
409
    print "Purging deleted catalog older than $pDeletedCatalog days.\n" if $verbose;
412
    print "Purging deleted catalog older than $pDeletedCatalog days.\n" if $verbose;
410
    my $sth1 = $dbh->prepare(
413
    Koha::Old::Items      ->filter_by_last_update( { days => $pDeletedCatalog } )->delete;
411
        q{
414
    Koha::Old::Biblioitems->filter_by_last_update( { days => $pDeletedCatalog } )->delete;
412
            DELETE FROM deleteditems
415
    Koha::Old::Biblios    ->filter_by_last_update( { days => $pDeletedCatalog } )->delete;
413
            WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY)
414
        }
415
    );
416
    my $sth2 = $dbh->prepare(
417
        q{
418
            DELETE FROM deletedbiblioitems
419
            WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY)
420
        }
421
    );
422
    my $sth3 = $dbh->prepare(
423
        q{
424
            DELETE FROM deletedbiblio
425
            WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY)
426
        }
427
    );
428
    # deletedbiblio_metadata is managed by FK with deletedbiblio
429
    $sth1->execute($pDeletedCatalog);
430
    $sth2->execute($pDeletedCatalog);
431
    $sth3->execute($pDeletedCatalog);
432
    print "Done with purging deleted catalog.\n" if $verbose;
416
    print "Done with purging deleted catalog.\n" if $verbose;
433
}
417
}
434
418
435
if ($pDeletedPatrons) {
419
if ($pDeletedPatrons) {
436
    print "Purging deleted patrons older than $pDeletedPatrons days.\n" if $verbose;
420
    print "Purging deleted patrons older than $pDeletedPatrons days.\n" if $verbose;
437
    $sth = $dbh->prepare(
421
    Koha::Old::Patrons->filter_by_last_update(
438
        q{
422
        { timestamp_column_name => 'updated_on', days => $pDeletedPatrons } )
439
            DELETE FROM deletedborrowers
423
      ->delete;
440
            WHERE updated_on < DATE_SUB(CURDATE(), INTERVAL ? DAY)
441
        }
442
    );
443
    $sth->execute($pDeletedPatrons);
444
    print "Done with purging deleted patrons.\n" if $verbose;
424
    print "Done with purging deleted patrons.\n" if $verbose;
445
}
425
}
446
426
447
if ($pOldIssues) {
427
if ($pOldIssues) {
448
    print "Purging old checkouts older than $pOldIssues days.\n" if $verbose;
428
    print "Purging old checkouts older than $pOldIssues days.\n" if $verbose;
449
    $sth = $dbh->prepare(
429
    Koha::Old::Checkouts->filter_by_last_update( { days => $pOldIssues } )->delete;
450
        q{
451
            DELETE FROM old_issues
452
            WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY)
453
        }
454
    );
455
    $sth->execute($pOldIssues);
456
    print "Done with purging old issues.\n" if $verbose;
430
    print "Done with purging old issues.\n" if $verbose;
457
}
431
}
458
432
459
if ($pOldReserves) {
433
if ($pOldReserves) {
460
    print "Purging old reserves older than $pOldReserves days.\n" if $verbose;
434
    print "Purging old reserves older than $pOldReserves days.\n" if $verbose;
461
    $sth = $dbh->prepare(
435
    Koha::Old::Holds->filter_by_last_update( { days => $pOldReserves } )->delete;
462
        q{
463
            DELETE FROM old_reserves
464
            WHERE timestamp < DATE_SUB(CURDATE(), INTERVAL ? DAY)
465
        }
466
    );
467
    $sth->execute($pOldReserves);
468
    print "Done with purging old reserves.\n" if $verbose;
436
    print "Done with purging old reserves.\n" if $verbose;
469
}
437
}
470
438
471
if ($pTransfers) {
439
if ($pTransfers) {
472
    print "Purging arrived item transfers older than $pTransfers days.\n" if $verbose;
440
    print "Purging arrived item transfers older than $pTransfers days.\n" if $verbose;
473
    $sth = $dbh->prepare(
441
    Koha::Item::Transfers->filter_by_last_update(
474
        q{
442
        {
475
            DELETE FROM branchtransfers
443
            timestamp_column_name => 'datearrived',
476
            WHERE datearrived < DATE_SUB(CURDATE(), INTERVAL ? DAY)
444
            days => $pTransfers,
477
        }
445
        }
478
    );
446
    )->delete;
479
    $sth->execute($pTransfers);
480
    print "Done with purging transfers.\n" if $verbose;
447
    print "Done with purging transfers.\n" if $verbose;
481
}
448
}
482
449
483
- 

Return to bug 24152