Lines 29-34
use constant DEFAULT_SHARE_INVITATION_EXPIRY_DAYS => 14;
Link Here
|
29 |
use constant DEFAULT_DEBARMENTS_PURGEDAYS => 30; |
29 |
use constant DEFAULT_DEBARMENTS_PURGEDAYS => 30; |
30 |
use constant DEFAULT_JOBS_PURGEDAYS => 1; |
30 |
use constant DEFAULT_JOBS_PURGEDAYS => 1; |
31 |
use constant DEFAULT_JOBS_PURGETYPES => qw{ update_elastic_index }; |
31 |
use constant DEFAULT_JOBS_PURGETYPES => qw{ update_elastic_index }; |
|
|
32 |
use constant DEFAULT_EDIFACT_MSG_PURGEDAYS => 365; |
32 |
|
33 |
|
33 |
use Koha::Script -cron; |
34 |
use Koha::Script -cron; |
34 |
use C4::Context; |
35 |
use C4::Context; |
Lines 49-58
use Koha::Item::Transfers;
Link Here
|
49 |
use Koha::PseudonymizedTransactions; |
50 |
use Koha::PseudonymizedTransactions; |
50 |
use Koha::Patron::Messages; |
51 |
use Koha::Patron::Messages; |
51 |
use Koha::Patron::Debarments qw( DelDebarment ); |
52 |
use Koha::Patron::Debarments qw( DelDebarment ); |
|
|
53 |
use Koha::Database; |
52 |
|
54 |
|
53 |
sub usage { |
55 |
sub usage { |
54 |
print STDERR <<USAGE; |
56 |
print STDERR <<USAGE; |
55 |
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] [--bg-days DAYS [--bg-type TYPE] ] |
57 |
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] [--bg-days DAYS [--bg-type TYPE] ] [--edifact-messages DAYS] |
56 |
|
58 |
|
57 |
-h --help prints this help message, and exits, ignoring all |
59 |
-h --help prints this help message, and exits, ignoring all |
58 |
other options |
60 |
other options |
Lines 113-118
Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose]
Link Here
|
113 |
--jobs-days DAYS Purge all finished background jobs this many days old. Defaults to 1 if no DAYS provided. |
115 |
--jobs-days DAYS Purge all finished background jobs this many days old. Defaults to 1 if no DAYS provided. |
114 |
--jobs-type TYPES What type of background job to purge. Defaults to "update_elastic_index" if omitted |
116 |
--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. |
117 |
Specifying "all" will purge all types. Repeatable. |
|
|
118 |
--edifact-messages DAYS Purge entries from edifact_messages table older than DAYS days. |
119 |
Defaults to 365 days if no days specified. |
116 |
USAGE |
120 |
USAGE |
117 |
exit $_[0]; |
121 |
exit $_[0]; |
118 |
} |
122 |
} |
Lines 156-161
my @log_modules;
Link Here
|
156 |
my @preserve_logs; |
160 |
my @preserve_logs; |
157 |
my $jobs_days; |
161 |
my $jobs_days; |
158 |
my @jobs_types; |
162 |
my @jobs_types; |
|
|
163 |
my $edifact_msg_days; |
159 |
|
164 |
|
160 |
my $command_line_options = join(" ",@ARGV); |
165 |
my $command_line_options = join(" ",@ARGV); |
161 |
|
166 |
|
Lines 200-205
GetOptions(
Link Here
|
200 |
'return-claims' => \$return_claims, |
205 |
'return-claims' => \$return_claims, |
201 |
'jobs-type:s' => \@jobs_types, |
206 |
'jobs-type:s' => \@jobs_types, |
202 |
'jobs-days:i' => \$jobs_days, |
207 |
'jobs-days:i' => \$jobs_days, |
|
|
208 |
'edifact-messages:i' => \$edifact_msg_days, |
203 |
) || usage(1); |
209 |
) || usage(1); |
204 |
|
210 |
|
205 |
# Use default values |
211 |
# Use default values |
Lines 214-219
$pDebarments = DEFAULT_DEBARMENTS_PURGEDAYS if defined($pDebarment
Link Here
|
214 |
$pMessages = DEFAULT_MESSAGES_PURGEDAYS if defined($pMessages) && $pMessages == 0; |
220 |
$pMessages = DEFAULT_MESSAGES_PURGEDAYS if defined($pMessages) && $pMessages == 0; |
215 |
$jobs_days = DEFAULT_JOBS_PURGEDAYS if defined($jobs_days) && $jobs_days == 0; |
221 |
$jobs_days = DEFAULT_JOBS_PURGEDAYS if defined($jobs_days) && $jobs_days == 0; |
216 |
@jobs_types = (DEFAULT_JOBS_PURGETYPES) if $jobs_days && @jobs_types == 0; |
222 |
@jobs_types = (DEFAULT_JOBS_PURGETYPES) if $jobs_days && @jobs_types == 0; |
|
|
223 |
$edifact_msg_days = DEFAULT_EDIFACT_MSG_PURGEDAYS if defined($edifact_msg_days) && $edifact_msg_days == 0; |
217 |
|
224 |
|
218 |
if ($help) { |
225 |
if ($help) { |
219 |
usage(0); |
226 |
usage(0); |
Lines 252-257
unless ( $sessions
Link Here
|
252 |
|| $cards |
259 |
|| $cards |
253 |
|| $return_claims |
260 |
|| $return_claims |
254 |
|| $jobs_days |
261 |
|| $jobs_days |
|
|
262 |
|| $edifact_msg_days |
255 |
) { |
263 |
) { |
256 |
print "You did not specify any cleanup work for the script to do.\n\n"; |
264 |
print "You did not specify any cleanup work for the script to do.\n\n"; |
257 |
usage(1); |
265 |
usage(1); |
Lines 713-718
if ($jobs_days) {
Link Here
|
713 |
} |
721 |
} |
714 |
} |
722 |
} |
715 |
|
723 |
|
|
|
724 |
if($edifact_msg_days) { |
725 |
print "Purging edifact messages older than $edifact_msg_days days.\n" if $verbose; |
726 |
my $count = PurgeEdifactMessages($edifact_msg_days, $confirm); |
727 |
if ( $verbose ) { |
728 |
say $confirm |
729 |
? sprintf( "Done with purging %d edifact messages", $count ) |
730 |
: sprintf( "%d edifact messages would have been removed", $count ); |
731 |
} |
732 |
} |
733 |
|
716 |
cronlogaction({ action => 'End', info => "COMPLETED" }); |
734 |
cronlogaction({ action => 'End', info => "COMPLETED" }); |
717 |
|
735 |
|
718 |
exit(0); |
736 |
exit(0); |
Lines 851-853
sub DeleteSpecialHolidays {
Link Here
|
851 |
print "Removed $count unique holidays\n" if $verbose; |
869 |
print "Removed $count unique holidays\n" if $verbose; |
852 |
} |
870 |
} |
853 |
|
871 |
|
854 |
- |
872 |
sub PurgeEdifactMessages { |
|
|
873 |
my ( $days, $doit ) = @_; |
874 |
|
875 |
my $count = 0; |
876 |
my $schema = Koha::Database->new()->schema(); |
877 |
|
878 |
$sth = $dbh->prepare( |
879 |
q{ |
880 |
SELECT id |
881 |
FROM edifact_messages |
882 |
WHERE transfer_date < date_sub(curdate(), INTERVAL ? DAY) |
883 |
} |
884 |
); |
885 |
$sth->execute($days) or die $dbh->errstr; |
886 |
|
887 |
while ( my ($msg_id) = $sth->fetchrow_array) { |
888 |
my $msg = $schema->resultset('EdifactMessage')->find($msg_id); |
889 |
$msg->delete if $doit; |
890 |
$count++; |
891 |
} |
892 |
return $count; |
893 |
} |