From fb4418ec71f282f0b3b09d25052a4ad3c51ae4e2 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Mon, 21 Oct 2024 12:51:34 +0000 Subject: [PATCH] Bug 34355: (QA follow-up) Add a delete flag to the cronjob This patch adds a 'delete' flag to the cronjob to select whether a file should be deleted or archived once processed --- misc/cronjobs/marc_ordering_process.pl | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/misc/cronjobs/marc_ordering_process.pl b/misc/cronjobs/marc_ordering_process.pl index 113c4d8876f..afe41c8c7d3 100755 --- a/misc/cronjobs/marc_ordering_process.pl +++ b/misc/cronjobs/marc_ordering_process.pl @@ -47,6 +47,10 @@ Print report to standard out. Without this parameter no changes will be made +=item B<-d|--delete> + +Delete the file once it has been processed + =back =cut @@ -64,11 +68,12 @@ use C4::Log qw( cronlogaction ); my $command_line_options = join( " ", @ARGV ); -my ( $help, $verbose, $confirm ); +my ( $help, $verbose, $confirm, $delete ); GetOptions( 'h|help' => \$help, 'v|verbose' => \$verbose, 'c|confirm' => \$confirm, + 'd|delete' => \$delete, ) || pod2usage(1); pod2usage(0) if $help; @@ -116,11 +121,19 @@ foreach my $acct (@accounts) { } if ($confirm) { say sprintf "Creating order lines from file %s", $filename if $verbose; + my $result = Koha::MarcOrder->create_order_lines_from_file($args); if ( $result->{success} ) { $files_processed++; say sprintf "Successfully processed file: %s", $filename if $verbose; - unlink $full_path; + if ($delete) { + say sprintf "Deleting processed file: %s", $filename if $verbose; + unlink $full_path; + } else { + mkdir "$working_dir/archive" unless -d "$working_dir/archive"; + say sprintf "Moving file to archive: %s", $filename if $verbose; + move( $full_path, "$working_dir/archive/$filename" ); + } } else { say sprintf "Error processing file: %s", $filename if $verbose; say sprintf "Error message: %s", $result->{error} if $verbose; -- 2.39.3 (Apple Git-146)