Bug 23777: (follow-up) Use To.json in results.tt
[koha.git] / misc / cronjobs / remove_temporary_edifiles.pl
blob7791717e50ee8a62f2bf49f06cfc2eaf868620a2
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 use Koha::Script -cron;
6 use C4::Context;
8 # this script will remove those older than 5 days
9 my $tmpdir = '/tmp';
11 opendir( my $dh, $tmpdir) || die "Cannot open $tmpdir : $!";
13 my @files_in_tmp = grep { /\.CE[IQ]$/ && -f "$tmpdir/$_" } readdir($dh);
14 closedir $dh;
17 my $dbh = C4::Context->dbh;
19 my $query =<<'ENDSQL';
20 select filename from edifact_messages
21 where message_type IN ('QUOTE','INVOICE')
22 and datediff( CURDATE(), transfer_date ) > 5
23 ENDSQL
25 my $ingested;
27 @{$ingested} = $dbh->selectcol_arrayref($query);
29 my %ingested_hash = map { $_ => 1 } @{$ingested};
31 my @delete_list;
33 foreach (@files_in_tmp) {
34 if ( exists $ingested_hash{$_} ) {
35 push @delete_list, $_;
39 if ( @delete_list ) {
40 chdir $tmpdir;
41 unlink @delete_list;