Koha/misc/cronjobs/remove_temporary_edifiles.pl
Martin Renvoize d2e189ca1c Bug 22600: Set 'commandline' interface appropriately
This patch change Koha::Cron to be a more generic Koha::Script class and
update all commanline driven scripts to use it.

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
2019-04-10 19:43:11 +00:00

42 lines
801 B
Perl
Executable file

#!/usr/bin/perl
use strict;
use warnings;
use Koha::Script -cron;
use C4::Context;
# this script will remove those older than 5 days
my $tmpdir = '/tmp';
#
opendir( my $dh, $tmpdir) || die "Cannot open $tmpdir : $!";
my @files_in_tmp = grep { /\.CE[IQ]$/ && -f "$tmpdir/$_" } readdir($dh);
closedir $dh;
my $dbh = C4::Context->dbh;
my $query =<<'ENDSQL';
select filename from edifact_messages
where message_type IN ('QUOTE','INVOICE')
and datediff( CURDATE(), transfer_date ) > 5
ENDSQL
my $ingested;
@{$ingested} = $dbh->selectcol_arrayref($query);
my %ingested_hash = map { $_ => 1 } @{$ingested};
my @delete_list;
foreach (@files_in_tmp) {
if ( exists $ingested_hash{$_} ) {
push @delete_list, $_;
}
}
if ( @delete_list ) {
chdir $tmpdir;
unlink @delete_list;
}