Lines 27-34
use constant DEFAULT_MESSAGES_PURGEDAYS => 365;
Link Here
|
27 |
use constant DEFAULT_SEARCHHISTORY_PURGEDAYS => 30; |
27 |
use constant DEFAULT_SEARCHHISTORY_PURGEDAYS => 30; |
28 |
use constant DEFAULT_SHARE_INVITATION_EXPIRY_DAYS => 14; |
28 |
use constant DEFAULT_SHARE_INVITATION_EXPIRY_DAYS => 14; |
29 |
use constant DEFAULT_DEBARMENTS_PURGEDAYS => 30; |
29 |
use constant DEFAULT_DEBARMENTS_PURGEDAYS => 30; |
30 |
use constant DEFAULT_BGJOBS_PURGEDAYS => 1; |
30 |
use constant DEFAULT_JOBS_PURGEDAYS => 1; |
31 |
use constant DEFAULT_BGJOBS_PURGETYPES => qw{ update_elastic_index }; |
31 |
use constant DEFAULT_JOBS_PURGETYPES => qw{ update_elastic_index }; |
32 |
|
32 |
|
33 |
use Koha::Script -cron; |
33 |
use Koha::Script -cron; |
34 |
use C4::Context; |
34 |
use C4::Context; |
Lines 110-117
Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose]
Link Here
|
110 |
--cards DAY Purge card creator batches last added to more than DAYS days ago. |
110 |
--cards DAY Purge card creator batches last added to more than DAYS days ago. |
111 |
--return-claims Purge all resolved return claims older than the number of days specified in |
111 |
--return-claims Purge all resolved return claims older than the number of days specified in |
112 |
the system preference CleanUpDatabaseReturnClaims. |
112 |
the system preference CleanUpDatabaseReturnClaims. |
113 |
--bg-days DAYS Purge all finished background jobs this many days old. Defaults to 1 if no DAYS provided. |
113 |
--jobs-days DAYS Purge all finished background jobs this many days old. Defaults to 1 if no DAYS provided. |
114 |
--bg-type TYPES What type of background job to purge. Defaults to "update_elastic_index" if omitted |
114 |
--jobs-type TYPES What type of background job to purge. Defaults to "update_elastic_index" if omitted |
115 |
Specifying "all" will purge all types. Repeatable. |
115 |
Specifying "all" will purge all types. Repeatable. |
116 |
USAGE |
116 |
USAGE |
117 |
exit $_[0]; |
117 |
exit $_[0]; |
Lines 154-161
my $labels;
Link Here
|
154 |
my $cards; |
154 |
my $cards; |
155 |
my @log_modules; |
155 |
my @log_modules; |
156 |
my @preserve_logs; |
156 |
my @preserve_logs; |
157 |
my $background_days; |
157 |
my $jobs_days; |
158 |
my @background_types; |
158 |
my @jobs_types; |
159 |
|
159 |
|
160 |
my $command_line_options = join(" ",@ARGV); |
160 |
my $command_line_options = join(" ",@ARGV); |
161 |
|
161 |
|
Lines 198-205
GetOptions(
Link Here
|
198 |
'labels' => \$labels, |
198 |
'labels' => \$labels, |
199 |
'cards' => \$cards, |
199 |
'cards' => \$cards, |
200 |
'return-claims' => \$return_claims, |
200 |
'return-claims' => \$return_claims, |
201 |
'bg-type:s' => \@background_types, |
201 |
'jobs-type:s' => \@jobs_types, |
202 |
'bg-days:i' => \$background_days, |
202 |
'jobs-days:i' => \$jobs_days, |
203 |
) || usage(1); |
203 |
) || usage(1); |
204 |
|
204 |
|
205 |
# Use default values |
205 |
# Use default values |
Lines 212-219
$pSearchhistory = DEFAULT_SEARCHHISTORY_PURGEDAYS if defined($pSearchhis
Link Here
|
212 |
$pListShareInvites = DEFAULT_SHARE_INVITATION_EXPIRY_DAYS if defined($pListShareInvites) && $pListShareInvites == 0; |
212 |
$pListShareInvites = DEFAULT_SHARE_INVITATION_EXPIRY_DAYS if defined($pListShareInvites) && $pListShareInvites == 0; |
213 |
$pDebarments = DEFAULT_DEBARMENTS_PURGEDAYS if defined($pDebarments) && $pDebarments == 0; |
213 |
$pDebarments = DEFAULT_DEBARMENTS_PURGEDAYS if defined($pDebarments) && $pDebarments == 0; |
214 |
$pMessages = DEFAULT_MESSAGES_PURGEDAYS if defined($pMessages) && $pMessages == 0; |
214 |
$pMessages = DEFAULT_MESSAGES_PURGEDAYS if defined($pMessages) && $pMessages == 0; |
215 |
$background_days = DEFAULT_BGJOBS_PURGEDAYS if defined($background_days) && $background_days == 0; |
215 |
$jobs_days = DEFAULT_JOBS_PURGEDAYS if defined($jobs_days) && $jobs_days == 0; |
216 |
@background_types = (DEFAULT_BGJOBS_PURGETYPES) if $background_days && @background_types == 0; |
216 |
@jobs_types = (DEFAULT_JOBS_PURGETYPES) if $jobs_days && @jobs_types == 0; |
217 |
|
217 |
|
218 |
if ($help) { |
218 |
if ($help) { |
219 |
usage(0); |
219 |
usage(0); |
Lines 251-257
unless ( $sessions
Link Here
|
251 |
|| $labels |
251 |
|| $labels |
252 |
|| $cards |
252 |
|| $cards |
253 |
|| $return_claims |
253 |
|| $return_claims |
254 |
|| $background_days |
254 |
|| $jobs_days |
255 |
) { |
255 |
) { |
256 |
print "You did not specify any cleanup work for the script to do.\n\n"; |
256 |
print "You did not specify any cleanup work for the script to do.\n\n"; |
257 |
usage(1); |
257 |
usage(1); |
Lines 688-704
if ($cards) {
Link Here
|
688 |
} |
688 |
} |
689 |
} |
689 |
} |
690 |
|
690 |
|
691 |
if ($background_days) { |
691 |
if ($jobs_days) { |
692 |
print "Purging background jobs more than $background_days days ago.\n" if $verbose; |
692 |
print "Purging background jobs more than $jobs_days days ago.\n" |
693 |
my $params = { job_types => \@background_types , |
693 |
if $verbose; |
694 |
days => $background_days, |
694 |
my $jobs = Koha::BackgroundJobs->search( |
695 |
confirm => $confirm, |
695 |
{ |
696 |
}; |
696 |
status => 'finished', |
697 |
my $count = Koha::BackgroundJobs->purge( $params ); |
697 |
( $jobs_types[0] eq 'all' ? () : ( type => \@jobs_types ) ) |
|
|
698 |
} |
699 |
)->filter_by_last_update( |
700 |
{ |
701 |
timestamp_column_name => 'ended_on', |
702 |
days => $jobs_days, |
703 |
} |
704 |
); |
705 |
my $count = $jobs->count; |
706 |
$jobs->delete if $confirm; |
698 |
if ($verbose) { |
707 |
if ($verbose) { |
699 |
say $confirm |
708 |
say $confirm |
700 |
? sprintf "Done with purging %d background jobs of type(s): %s added more than %d days ago.\n", $count, join(',', @background_types), $background_days |
709 |
? sprintf "Done with purging %d background jobs of type(s): %s added more than %d days ago.\n", |
701 |
: sprintf "%d background jobs of type(s): %s added more than %d days ago would have been purged.", $count, join(',', @background_types), $background_days; |
710 |
$count, join( ',', @jobs_types ), $jobs_days |
|
|
711 |
: sprintf "%d background jobs of type(s): %s added more than %d days ago would have been purged.", |
712 |
$count, join( ',', @jobs_types ), $jobs_days; |
702 |
} |
713 |
} |
703 |
} |
714 |
} |
704 |
|
715 |
|