From ebfed0b76a5c92cedbc44fda5ef3b7981f77f20e Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 24 Nov 2025 12:58:58 +0000 Subject: [PATCH] Bug 33308: (QA follow-up) Use simplified File::Transport API from bug 40811 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This follow-up updates runreport.pl to use the newer simplified File::Transport API introduced by bug 40811, which provides: - Automatic connection management (no explicit connect/disconnect) - Simplified directory handling via options hash - Cleaner, more maintainable code The upload functionality now uses a single upload_file() call with a path option instead of requiring separate connect() and change_directory() calls. Also fixes minor inconsistencies in error messages (missing colons and escaped quotes). Signed-off-by: Martin Renvoize Signed-off-by: Tomás Cohen Arazi --- misc/cronjobs/runreport.pl | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/misc/cronjobs/runreport.pl b/misc/cronjobs/runreport.pl index 39b372dcce..b7f048cf87 100755 --- a/misc/cronjobs/runreport.pl +++ b/misc/cronjobs/runreport.pl @@ -404,29 +404,24 @@ foreach my $report_id (@ARGV) { if ($sftp_dest_id) { my $sftp_server = Koha::File::Transports->find($sftp_dest_id); - die("ERROR:\tSupplied FTP/SFTP Server doesn\'t exist") + die("ERROR:\tSupplied FTP/SFTP Server doesn't exist") unless ($sftp_server); - die("ERROR:\tUnable to connect to FTP/SFTP Server") - unless ( $sftp_server->connect ); - my $upload_directory = $sftp_server->upload_directory; - my $content_type = "text/$format"; - my $filename = $filename || "report$report_id-$date.$format"; + my $filename_to_use = $filename || "report$report_id-$date.$format"; open my $fh, "<", \$message; - - die("ERROR\tMessage supplied is empty, or, not suitable for upload") + die("ERROR:\tMessage supplied is empty, or not suitable for upload") unless ($fh); - die("ERROR\tNo upload directory specified in config") + die("ERROR:\tNo upload directory specified in config") unless ($upload_directory); - die("ERROR\tUnable to change directory") - unless ( $sftp_server->change_directory($upload_directory) ); + # Use simplified API - automatic connection and directory management + my $result = $sftp_server->upload_file( $fh, $filename_to_use, { path => $upload_directory } ); - die("ERROR\tUnable to upload report to server") - unless ( $sftp_server->upload_file( $fh, $filename ) ); + die("ERROR:\tUnable to upload report to server") + unless ($result); } if ( !$send_email && !$sftp_dest_id ) { -- 2.50.1 (Apple Git-155)