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

(-)a/misc/cronjobs/cleanup_database.pl (-2 / +45 lines)
Lines 55-61 use Koha::Patron::Messages; Link Here
55
55
56
sub usage {
56
sub usage {
57
    print STDERR <<USAGE;
57
    print STDERR <<USAGE;
58
Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS] [--all-restrictions] [--fees DAYS] [--temp-uploads] [--temp-uploads-days DAYS] [--uploads-missing 0|1 ] [--statistics DAYS] [--deleted-catalog DAYS] [--deleted-patrons DAYS] [--old-issues DAYS] [--old-reserves DAYS] [--transfers DAYS]
58
Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] [--zebraqueue DAYS] [-m|--mail] [--merged] [--import DAYS] [--logs DAYS] [--searchhistory DAYS] [--restrictions DAYS] [--all-restrictions] [--fees DAYS] [--temp-uploads] [--temp-uploads-days DAYS] [--uploads-missing 0|1 ] [--statistics DAYS] [--deleted-catalog DAYS] [--deleted-patrons DAYS] [--old-issues DAYS] [--old-reserves DAYS] [--transfers DAYS] [--labels DAYS] [--cards DAYS]
59
59
60
   -h --help          prints this help message, and exits, ignoring all
60
   -h --help          prints this help message, and exits, ignoring all
61
                      other options
61
                      other options
Lines 107-112 Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] Link Here
107
   --pseudo-transactions DAYS   Purge the pseudonymized transactions that have been originally created more than DAYS days ago
107
   --pseudo-transactions DAYS   Purge the pseudonymized transactions that have been originally created more than DAYS days ago
108
                                DAYS is optional and can be replaced by:
108
                                DAYS is optional and can be replaced by:
109
                                    --pseudo-transactions-from YYYY-MM-DD and/or --pseudo-transactions-to YYYY-MM-DD
109
                                    --pseudo-transactions-from YYYY-MM-DD and/or --pseudo-transactions-to YYYY-MM-DD
110
   --labels DAYS           Purge item label batches last added to more than DAYS days ago.
111
   --cards DAY             Purge card creator batches last added to more than DAYS days ago.
112
110
USAGE
113
USAGE
111
    exit $_[0];
114
    exit $_[0];
112
}
115
}
Lines 142-147 my $pOldReserves; Link Here
142
my $pTransfers;
145
my $pTransfers;
143
my ( $pPseudoTransactions, $pPseudoTransactionsFrom, $pPseudoTransactionsTo );
146
my ( $pPseudoTransactions, $pPseudoTransactionsFrom, $pPseudoTransactionsTo );
144
my $pMessages;
147
my $pMessages;
148
my $labels;
149
my $cards;
145
150
146
GetOptions(
151
GetOptions(
147
    'h|help'            => \$help,
152
    'h|help'            => \$help,
Lines 177-182 GetOptions( Link Here
177
    'pseudo-transactions:i'      => \$pPseudoTransactions,
182
    'pseudo-transactions:i'      => \$pPseudoTransactions,
178
    'pseudo-transactions-from:s' => \$pPseudoTransactionsFrom,
183
    'pseudo-transactions-from:s' => \$pPseudoTransactionsFrom,
179
    'pseudo-transactions-to:s'   => \$pPseudoTransactionsTo,
184
    'pseudo-transactions-to:s'   => \$pPseudoTransactionsTo,
185
    'labels'            => \$labels,
186
    'cards'             => \$cards,
180
) || usage(1);
187
) || usage(1);
181
188
182
# Use default values
189
# Use default values
Lines 222-227 unless ( $sessions Link Here
222
    || $pPseudoTransactionsFrom
229
    || $pPseudoTransactionsFrom
223
    || $pPseudoTransactionsTo
230
    || $pPseudoTransactionsTo
224
    || $pMessages
231
    || $pMessages
232
    || $labels
233
    || $cards
225
) {
234
) {
226
    print "You did not specify any cleanup work for the script to do.\n\n";
235
    print "You did not specify any cleanup work for the script to do.\n\n";
227
    usage(1);
236
    usage(1);
Lines 598-603 if (defined $pPseudoTransactions or $pPseudoTransactionsFrom or $pPseudoTransact Link Here
598
          ? sprintf "Done with purging %d pseudonymized transactions.", $count
607
          ? sprintf "Done with purging %d pseudonymized transactions.", $count
599
          : sprintf "%d pseudonymized transactions would have been purged.", $count;
608
          : sprintf "%d pseudonymized transactions would have been purged.", $count;
600
    }
609
    }
610
611
if ($labels) {
612
    print "Purging item label batches last added to more than $labels days ago.\n" if $verbose;
613
    $sth = $dbh->prepare(
614
        q{
615
        DELETE from creator_batches
616
        WHERE batch_id in
617
            (SELECT batch_id
618
            FROM (SELECT batch_id
619
                    FROM creator_batches
620
                    WHERE creator='labels'
621
                    GROUP BY batch_id
622
                    HAVING max(timestamp) < date_sub(curdate(),interval ? day)) a)
623
        }
624
    );
625
    $sth->execute($labels) or die $dbh->errstr;
626
    print "Done with purging item label batches last added to more than $labels days ago.\n" if $verbose;
627
}
628
629
if ($cards) {
630
    print "Purging card creator batches last added to more than $cards days ago.\n" if $verbose;
631
    $sth = $dbh->prepare(
632
        q{
633
        DELETE from creator_batches
634
        WHERE batch_id in
635
            (SELECT batch_id
636
            FROM (SELECT batch_id
637
                    FROM creator_batches
638
                    WHERE creator='patroncards'
639
                    GROUP BY batch_id
640
                    HAVING max(timestamp) < date_sub(curdate(),interval ? day)) a);
641
        }
642
    );
643
    $sth->execute($cards) or die $dbh->errstr;
644
    print "Done with purging card creator batches last added to more than $cards days ago.\n" if $verbose;
601
}
645
}
602
646
603
exit(0);
647
exit(0);
604
- 

Return to bug 15563