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

(-)a/misc/cronjobs/cleanup_database.pl (-1 / +21 lines)
Lines 23-28 use constant DEFAULT_ZEBRAQ_PURGEDAYS => 30; Link Here
23
use constant DEFAULT_MAIL_PURGEDAYS               => 30;
23
use constant DEFAULT_MAIL_PURGEDAYS               => 30;
24
use constant DEFAULT_IMPORT_PURGEDAYS             => 60;
24
use constant DEFAULT_IMPORT_PURGEDAYS             => 60;
25
use constant DEFAULT_LOGS_PURGEDAYS               => 180;
25
use constant DEFAULT_LOGS_PURGEDAYS               => 180;
26
use constant DEFAULT_MESSAGES_PURGEDAYS           => 365;
26
use constant DEFAULT_SEARCHHISTORY_PURGEDAYS      => 30;
27
use constant DEFAULT_SEARCHHISTORY_PURGEDAYS      => 30;
27
use constant DEFAULT_SHARE_INVITATION_EXPIRY_DAYS => 14;
28
use constant DEFAULT_SHARE_INVITATION_EXPIRY_DAYS => 14;
28
use constant DEFAULT_DEBARMENTS_PURGEDAYS         => 30;
29
use constant DEFAULT_DEBARMENTS_PURGEDAYS         => 30;
Lines 50-55 use Koha::Old::Holds; Link Here
50
use Koha::Old::Patrons;
51
use Koha::Old::Patrons;
51
use Koha::Item::Transfers;
52
use Koha::Item::Transfers;
52
use Koha::PseudonymizedTransactions;
53
use Koha::PseudonymizedTransactions;
54
use Koha::Patron::Messages;
53
55
54
sub usage {
56
sub usage {
55
    print STDERR <<USAGE;
57
    print STDERR <<USAGE;
Lines 68-73 Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose] Link Here
68
   -m --mail DAYS     purge items from the mail queue that are older than DAYS days.
70
   -m --mail DAYS     purge items from the mail queue that are older than DAYS days.
69
                      Defaults to 30 days if no days specified.
71
                      Defaults to 30 days if no days specified.
70
   --merged           purged completed entries from need_merge_authorities.
72
   --merged           purged completed entries from need_merge_authorities.
73
   --messages DAYS    purge entries from messages table older than DAYS days.
74
                      Defaults to 365 days if no days specified.
71
   --import DAYS      purge records from import tables older than DAYS days.
75
   --import DAYS      purge records from import tables older than DAYS days.
72
                      Defaults to 60 days if no days specified.
76
                      Defaults to 60 days if no days specified.
73
   --z3950            purge records from import tables that are the result
77
   --z3950            purge records from import tables that are the result
Lines 137-142 my $pOldIssues; Link Here
137
my $pOldReserves;
141
my $pOldReserves;
138
my $pTransfers;
142
my $pTransfers;
139
my ( $pPseudoTransactions, $pPseudoTransactionsFrom, $pPseudoTransactionsTo );
143
my ( $pPseudoTransactions, $pPseudoTransactionsFrom, $pPseudoTransactionsTo );
144
my $pMessages;
140
145
141
GetOptions(
146
GetOptions(
142
    'h|help'            => \$help,
147
    'h|help'            => \$help,
Lines 150-155 GetOptions( Link Here
150
    'import:i'          => \$pImport,
155
    'import:i'          => \$pImport,
151
    'z3950'             => \$pZ3950,
156
    'z3950'             => \$pZ3950,
152
    'logs:i'            => \$pLogs,
157
    'logs:i'            => \$pLogs,
158
    'messages:i'        => \$pMessages,
153
    'fees:i'            => \$fees_days,
159
    'fees:i'            => \$fees_days,
154
    'searchhistory:i'   => \$pSearchhistory,
160
    'searchhistory:i'   => \$pSearchhistory,
155
    'list-invites:i'    => \$pListShareInvites,
161
    'list-invites:i'    => \$pListShareInvites,
Lines 182-187 $mail = DEFAULT_MAIL_PURGEDAYS if defined($mail) Link Here
182
$pSearchhistory    = DEFAULT_SEARCHHISTORY_PURGEDAYS      if defined($pSearchhistory)    && $pSearchhistory == 0;
188
$pSearchhistory    = DEFAULT_SEARCHHISTORY_PURGEDAYS      if defined($pSearchhistory)    && $pSearchhistory == 0;
183
$pListShareInvites = DEFAULT_SHARE_INVITATION_EXPIRY_DAYS if defined($pListShareInvites) && $pListShareInvites == 0;
189
$pListShareInvites = DEFAULT_SHARE_INVITATION_EXPIRY_DAYS if defined($pListShareInvites) && $pListShareInvites == 0;
184
$pDebarments       = DEFAULT_DEBARMENTS_PURGEDAYS         if defined($pDebarments)       && $pDebarments == 0;
190
$pDebarments       = DEFAULT_DEBARMENTS_PURGEDAYS         if defined($pDebarments)       && $pDebarments == 0;
191
$pMessages         = DEFAULT_MESSAGES_PURGEDAYS           if defined($pMessages)         && $pMessages == 0;
185
192
186
if ($help) {
193
if ($help) {
187
    usage(0);
194
    usage(0);
Lines 214-219 unless ( $sessions Link Here
214
    || defined $pPseudoTransactions
221
    || defined $pPseudoTransactions
215
    || $pPseudoTransactionsFrom
222
    || $pPseudoTransactionsFrom
216
    || $pPseudoTransactionsTo
223
    || $pPseudoTransactionsTo
224
    || $pMessages
217
) {
225
) {
218
    print "You did not specify any cleanup work for the script to do.\n\n";
226
    print "You did not specify any cleanup work for the script to do.\n\n";
219
    usage(1);
227
    usage(1);
Lines 334-339 if ($pLogs) { Link Here
334
    print "Done with purging action_logs.\n" if $verbose;
342
    print "Done with purging action_logs.\n" if $verbose;
335
}
343
}
336
344
345
if ($pMessages) {
346
    print "Purging messages older than $pMessages days.\n" if $verbose;
347
    my $messages = Koha::Patron::Messages->filter_by_last_update(
348
        { timestamp_column_name => 'message_date', days => $pMessages } );
349
    my $count = $messages->count;
350
    $messages->delete if $confirm;
351
    if ( $verbose ) {
352
        say $confirm
353
          ? sprintf( "Done with purging %d messages", $count )
354
          : sprintf( "%d messages would have been removed", $count );
355
    }
356
}
357
337
if ($fees_days) {
358
if ($fees_days) {
338
    print "Purging records from accountlines.\n" if $verbose;
359
    print "Purging records from accountlines.\n" if $verbose;
339
    purge_zero_balance_fees( $fees_days ) if $confirm;
360
    purge_zero_balance_fees( $fees_days ) if $confirm;
340
- 

Return to bug 24541