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 114-119
Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose]
Link Here
|
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. |
116 |
--reports DAYS Purge reports data saved more than DAYS days ago. The data is created by running runreport.pl with the --store-results option. |
118 |
--reports DAYS Purge reports data saved more than DAYS days ago. The data is created by running runreport.pl with the --store-results option. |
|
|
119 |
--edifact-messages DAYS Purge entries from edifact_messages table older than DAYS days. |
120 |
Defaults to 365 days if no days specified. |
117 |
USAGE |
121 |
USAGE |
118 |
exit $_[0]; |
122 |
exit $_[0]; |
119 |
} |
123 |
} |
Lines 158-208
my @preserve_logs;
Link Here
|
158 |
my $jobs_days; |
162 |
my $jobs_days; |
159 |
my @jobs_types; |
163 |
my @jobs_types; |
160 |
my $reports; |
164 |
my $reports; |
|
|
165 |
my $edifact_msg_days; |
161 |
|
166 |
|
162 |
my $command_line_options = join(" ",@ARGV); |
167 |
my $command_line_options = join(" ",@ARGV); |
163 |
|
168 |
|
164 |
GetOptions( |
169 |
GetOptions( |
165 |
'h|help' => \$help, |
170 |
'h|help' => \$help, |
166 |
'confirm' => \$confirm, |
171 |
'confirm' => \$confirm, |
167 |
'sessions' => \$sessions, |
172 |
'sessions' => \$sessions, |
168 |
'sessdays:i' => \$sess_days, |
173 |
'sessdays:i' => \$sess_days, |
169 |
'v|verbose' => \$verbose, |
174 |
'v|verbose' => \$verbose, |
170 |
'm|mail:i' => \$mail, |
175 |
'm|mail:i' => \$mail, |
171 |
'zebraqueue:i' => \$zebraqueue_days, |
176 |
'zebraqueue:i' => \$zebraqueue_days, |
172 |
'merged' => \$purge_merged, |
177 |
'merged' => \$purge_merged, |
173 |
'import:i' => \$pImport, |
178 |
'import:i' => \$pImport, |
174 |
'z3950' => \$pZ3950, |
179 |
'z3950' => \$pZ3950, |
175 |
'logs:i' => \$pLogs, |
180 |
'logs:i' => \$pLogs, |
176 |
'log-module:s' => \@log_modules, |
181 |
'log-module:s' => \@log_modules, |
177 |
'preserve-log:s' => \@preserve_logs, |
182 |
'preserve-log:s' => \@preserve_logs, |
178 |
'messages:i' => \$pMessages, |
183 |
'messages:i' => \$pMessages, |
179 |
'fees:i' => \$fees_days, |
184 |
'fees:i' => \$fees_days, |
180 |
'searchhistory:i' => \$pSearchhistory, |
185 |
'searchhistory:i' => \$pSearchhistory, |
181 |
'list-invites:i' => \$pListShareInvites, |
186 |
'list-invites:i' => \$pListShareInvites, |
182 |
'restrictions:i' => \$pDebarments, |
187 |
'restrictions:i' => \$pDebarments, |
183 |
'all-restrictions' => \$allDebarments, |
188 |
'all-restrictions' => \$allDebarments, |
184 |
'del-exp-selfreg' => \$pExpSelfReg, |
189 |
'del-exp-selfreg' => \$pExpSelfReg, |
185 |
'del-unv-selfreg:i' => \$pUnvSelfReg, |
190 |
'del-unv-selfreg:i' => \$pUnvSelfReg, |
186 |
'unique-holidays:i' => \$special_holidays_days, |
191 |
'unique-holidays:i' => \$special_holidays_days, |
187 |
'temp-uploads' => \$temp_uploads, |
192 |
'temp-uploads' => \$temp_uploads, |
188 |
'temp-uploads-days:i' => \$temp_uploads_days, |
193 |
'temp-uploads-days:i' => \$temp_uploads_days, |
189 |
'uploads-missing:i' => \$uploads_missing, |
194 |
'uploads-missing:i' => \$uploads_missing, |
190 |
'oauth-tokens' => \$oauth_tokens, |
195 |
'oauth-tokens' => \$oauth_tokens, |
191 |
'statistics:i' => \$pStatistics, |
196 |
'statistics:i' => \$pStatistics, |
192 |
'deleted-catalog:i' => \$pDeletedCatalog, |
197 |
'deleted-catalog:i' => \$pDeletedCatalog, |
193 |
'deleted-patrons:i' => \$pDeletedPatrons, |
198 |
'deleted-patrons:i' => \$pDeletedPatrons, |
194 |
'old-issues:i' => \$pOldIssues, |
199 |
'old-issues:i' => \$pOldIssues, |
195 |
'old-reserves:i' => \$pOldReserves, |
200 |
'old-reserves:i' => \$pOldReserves, |
196 |
'transfers:i' => \$pTransfers, |
201 |
'transfers:i' => \$pTransfers, |
197 |
'pseudo-transactions:i' => \$pPseudoTransactions, |
202 |
'pseudo-transactions:i' => \$pPseudoTransactions, |
198 |
'pseudo-transactions-from:s' => \$pPseudoTransactionsFrom, |
203 |
'pseudo-transactions-from:s' => \$pPseudoTransactionsFrom, |
199 |
'pseudo-transactions-to:s' => \$pPseudoTransactionsTo, |
204 |
'pseudo-transactions-to:s' => \$pPseudoTransactionsTo, |
200 |
'labels' => \$labels, |
205 |
'labels' => \$labels, |
201 |
'cards' => \$cards, |
206 |
'cards' => \$cards, |
202 |
'return-claims' => \$return_claims, |
207 |
'return-claims' => \$return_claims, |
203 |
'jobs-type:s' => \@jobs_types, |
208 |
'jobs-type:s' => \@jobs_types, |
204 |
'jobs-days:i' => \$jobs_days, |
209 |
'jobs-days:i' => \$jobs_days, |
205 |
'reports:i' => \$reports, |
210 |
'reports:i' => \$reports, |
|
|
211 |
'edifact-messages:i' => \$edifact_msg_days, |
206 |
) || usage(1); |
212 |
) || usage(1); |
207 |
|
213 |
|
208 |
# Use default values |
214 |
# Use default values |
Lines 217-222
$pDebarments = DEFAULT_DEBARMENTS_PURGEDAYS if defined($pDebarment
Link Here
|
217 |
$pMessages = DEFAULT_MESSAGES_PURGEDAYS if defined($pMessages) && $pMessages == 0; |
223 |
$pMessages = DEFAULT_MESSAGES_PURGEDAYS if defined($pMessages) && $pMessages == 0; |
218 |
$jobs_days = DEFAULT_JOBS_PURGEDAYS if defined($jobs_days) && $jobs_days == 0; |
224 |
$jobs_days = DEFAULT_JOBS_PURGEDAYS if defined($jobs_days) && $jobs_days == 0; |
219 |
@jobs_types = (DEFAULT_JOBS_PURGETYPES) if $jobs_days && @jobs_types == 0; |
225 |
@jobs_types = (DEFAULT_JOBS_PURGETYPES) if $jobs_days && @jobs_types == 0; |
|
|
226 |
$edifact_msg_days = DEFAULT_EDIFACT_MSG_PURGEDAYS if defined($edifact_msg_days) && $edifact_msg_days == 0; |
220 |
|
227 |
|
221 |
if ($help) { |
228 |
if ($help) { |
222 |
usage(0); |
229 |
usage(0); |
Lines 256-261
unless ( $sessions
Link Here
|
256 |
|| $return_claims |
263 |
|| $return_claims |
257 |
|| $jobs_days |
264 |
|| $jobs_days |
258 |
|| $reports |
265 |
|| $reports |
|
|
266 |
|| $edifact_msg_days |
259 |
) { |
267 |
) { |
260 |
print "You did not specify any cleanup work for the script to do.\n\n"; |
268 |
print "You did not specify any cleanup work for the script to do.\n\n"; |
261 |
usage(1); |
269 |
usage(1); |
Lines 725-730
if ($reports) {
Link Here
|
725 |
} |
733 |
} |
726 |
} |
734 |
} |
727 |
|
735 |
|
|
|
736 |
if($edifact_msg_days) { |
737 |
print "Purging edifact messages older than $edifact_msg_days days.\n" if $verbose; |
738 |
my $count = PurgeEdifactMessages($edifact_msg_days, $confirm); |
739 |
if ( $verbose ) { |
740 |
say $confirm |
741 |
? sprintf( "Done with purging %d edifact messages", $count ) |
742 |
: sprintf( "%d edifact messages would have been removed", $count ); |
743 |
} |
744 |
} |
745 |
|
728 |
cronlogaction({ action => 'End', info => "COMPLETED" }); |
746 |
cronlogaction({ action => 'End', info => "COMPLETED" }); |
729 |
|
747 |
|
730 |
exit(0); |
748 |
exit(0); |
Lines 872-874
sub PurgeSavedReports {
Link Here
|
872 |
}); |
890 |
}); |
873 |
$sth->execute( $reports ); |
891 |
$sth->execute( $reports ); |
874 |
} |
892 |
} |
875 |
- |
893 |
|
|
|
894 |
sub PurgeEdifactMessages { |
895 |
my ( $days, $doit ) = @_; |
896 |
|
897 |
my $count = 0; |
898 |
my $schema = Koha::Database->new()->schema(); |
899 |
|
900 |
$sth = $dbh->prepare( |
901 |
q{ |
902 |
SELECT id |
903 |
FROM edifact_messages |
904 |
WHERE transfer_date < date_sub(curdate(), INTERVAL ? DAY) |
905 |
} |
906 |
); |
907 |
$sth->execute($days) or die $dbh->errstr; |
908 |
|
909 |
while ( my ($msg_id) = $sth->fetchrow_array) { |
910 |
my $msg = $schema->resultset('EdifactMessage')->find($msg_id); |
911 |
$msg->delete if $doit; |
912 |
$count++; |
913 |
} |
914 |
return $count; |
915 |
} |