Bug 19377: Remove $5 charge from sample item types
[koha.git] / misc / cronjobs / remove_temporary_edifiles.pl
blobe799ee5b2e229b8690a18a05100f706eac7870b1
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 use C4::Context;
7 # this script will remove those older than 5 days
8 my $tmpdir = '/tmp';
10 opendir( my $dh, $tmpdir) || die "Cannot open $tmpdir : $!";
12 my @files_in_tmp = grep { /\.CE[IQ]$/ && -f "$tmpdir/$_" } readdir($dh);
13 closedir $dh;
16 my $dbh = C4::Context->dbh;
18 my $query =<<'ENDSQL';
19 select filename from edifact_messages
20 where message_type IN ('QUOTE','INVOICE')
21 and datediff( CURDATE(), transfer_date ) > 5
22 ENDSQL
24 my $ingested;
26 @{$ingested} = $dbh->selectcol_arrayref($query);
28 my %ingested_hash = map { $_ => 1 } @{$ingested};
30 my @delete_list;
32 foreach (@files_in_tmp) {
33 if ( exists $ingested_hash{$_} ) {
34 push @delete_list, $_;
38 if ( @delete_list ) {
39 chdir $tmpdir;
40 unlink @delete_list;