|
Lines 31-56
use constant DEFAULT_JOBS_PURGEDAYS => 1;
Link Here
|
| 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 |
use constant DEFAULT_EDIFACT_MSG_PURGEDAYS => 365; |
| 33 |
|
33 |
|
|
|
34 |
use Getopt::Long qw( GetOptions ); |
| 35 |
|
| 34 |
use Koha::Script -cron; |
36 |
use Koha::Script -cron; |
|
|
37 |
|
| 38 |
use C4::Accounts qw( purge_zero_balance_fees ); |
| 35 |
use C4::Context; |
39 |
use C4::Context; |
| 36 |
use C4::Search; |
|
|
| 37 |
use C4::Search::History; |
| 38 |
use Getopt::Long qw( GetOptions ); |
| 39 |
use C4::Log qw( cronlogaction ); |
40 |
use C4::Log qw( cronlogaction ); |
| 40 |
use C4::Accounts qw( purge_zero_balance_fees ); |
41 |
use C4::Search::History; |
| 41 |
use Koha::UploadedFiles; |
42 |
use C4::Search; |
| 42 |
use Koha::BackgroundJobs; |
43 |
use Koha::BackgroundJobs; |
| 43 |
use Koha::Old::Biblios; |
44 |
use Koha::Database; |
| 44 |
use Koha::Old::Items; |
45 |
use Koha::DateUtils qw( dt_from_string ); |
|
|
46 |
use Koha::Item::Transfers; |
| 45 |
use Koha::Old::Biblioitems; |
47 |
use Koha::Old::Biblioitems; |
|
|
48 |
use Koha::Old::Biblios; |
| 46 |
use Koha::Old::Checkouts; |
49 |
use Koha::Old::Checkouts; |
| 47 |
use Koha::Old::Holds; |
50 |
use Koha::Old::Holds; |
|
|
51 |
use Koha::Old::Items; |
| 48 |
use Koha::Old::Patrons; |
52 |
use Koha::Old::Patrons; |
| 49 |
use Koha::Item::Transfers; |
|
|
| 50 |
use Koha::PseudonymizedTransactions; |
| 51 |
use Koha::Patron::Messages; |
| 52 |
use Koha::Patron::Debarments qw( DelDebarment ); |
53 |
use Koha::Patron::Debarments qw( DelDebarment ); |
| 53 |
use Koha::Database; |
54 |
use Koha::Patron::Messages; |
|
|
55 |
use Koha::PseudonymizedTransactions; |
| 56 |
use Koha::UploadedFiles; |
| 54 |
|
57 |
|
| 55 |
sub usage { |
58 |
sub usage { |
| 56 |
print STDERR <<USAGE; |
59 |
print STDERR <<USAGE; |
|
Lines 116-122
Usage: $0 [-h|--help] [--confirm] [--sessions] [--sessdays DAYS] [-v|--verbose]
Link Here
|
| 116 |
--jobs-type TYPES What type of background job to purge. Defaults to "update_elastic_index" if omitted |
119 |
--jobs-type TYPES What type of background job to purge. Defaults to "update_elastic_index" if omitted |
| 117 |
Specifying "all" will purge all types. Repeatable. |
120 |
Specifying "all" will purge all types. Repeatable. |
| 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. |
121 |
--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 the edifact_messages table older than DAYS days. |
122 |
--edifact-messages DAYS Purge process and failed EDIFACT messages handled more than DAYS days. |
| 120 |
Defaults to 365 days if no days specified. |
123 |
Defaults to 365 days if no days specified. |
| 121 |
USAGE |
124 |
USAGE |
| 122 |
exit $_[0]; |
125 |
exit $_[0]; |
|
Lines 894-916
sub PurgeSavedReports {
Link Here
|
| 894 |
sub PurgeEdifactMessages { |
897 |
sub PurgeEdifactMessages { |
| 895 |
my ( $days, $doit ) = @_; |
898 |
my ( $days, $doit ) = @_; |
| 896 |
|
899 |
|
| 897 |
my $count = 0; |
|
|
| 898 |
my $schema = Koha::Database->new()->schema(); |
900 |
my $schema = Koha::Database->new()->schema(); |
| 899 |
|
901 |
my $dtf = $schema->storage->datetime_parser; |
| 900 |
$sth = $dbh->prepare( |
902 |
my $resultset = $schema->resultset('EdifactMessage')->search( |
| 901 |
q{ |
903 |
{ |
| 902 |
SELECT id |
904 |
transfer_date => { |
| 903 |
FROM edifact_messages |
905 |
'<' => $dtf->format_datetime(dt_from_string->subtract( days => $days )) |
| 904 |
WHERE transfer_date < date_sub(curdate(), INTERVAL ? DAY) |
906 |
}, |
| 905 |
AND status != 'new'; |
907 |
status => { '!=' => 'new' }, |
| 906 |
} |
908 |
} |
| 907 |
); |
909 |
); |
| 908 |
$sth->execute($days) or die $dbh->errstr; |
910 |
my $count = $resultset->count; |
|
|
911 |
|
| 912 |
$resultset->delete if $doit; |
| 909 |
|
913 |
|
| 910 |
while ( my ($msg_id) = $sth->fetchrow_array) { |
|
|
| 911 |
my $msg = $schema->resultset('EdifactMessage')->find($msg_id); |
| 912 |
$msg->delete if $doit; |
| 913 |
$count++; |
| 914 |
} |
| 915 |
return $count; |
914 |
return $count; |
| 916 |
} |
915 |
} |
| 917 |
- |
|
|