Bug 36766: Make SFTP notice more customisable

SFTP_FAILURE and SFTP_SUCCESSFUL notices can be configured from Notices
and slip tool.

Sponsored-by: Horowhenua Libraries, Toi Ohomai Institute of Technology, Plant and Food Research Limited, Waitaki District Council, South Taranaki District Council New Zealand
Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Alex Buckley 2024-05-10 06:14:56 +12:00 committed by Katrin Fischer
parent 2f508087f5
commit 62569feec9
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
3 changed files with 64 additions and 25 deletions

View File

@ -0,0 +1,20 @@
use Modern::Perl;
return {
bug_number => "36766",
description => "Add command-line utility to SFTP a file to a remote server",
up => sub {
my ($args) = @_;
my ( $dbh, $out ) = @$args{qw(dbh out)};
$dbh->do(q{
INSERT IGNORE INTO letter
(module,code,branchcode,name,is_html,title,content,message_transport_type,lang)
VALUES
('commandline', 'SFTP_FAILURE', '', 'File SFTP failed', 0, 'The SFTP by sftp_file.pl failed', 'SFTP upload failed:\n\n<<sftp_status>>', 'email', 'default'),
('commandline', 'SFTP_SUCCESS', '', 'File SFTP success', 0, 'The SFTP by sftp_file.pl was successful', 'SFTP upload succeeded', 'email', 'default')
});
say $out "Added new sample notices 'SFTP_FAILURE' and 'SFTP_SUCCESS'";
},
};

View File

@ -1005,6 +1005,30 @@ tables:
- ""
- "<order>Ordernumber <<aqorders.ordernumber>> (<<biblio.title>>) (<<aqorders.quantity>> ordered) ($<<aqorders.listprice>> each) has not been received.</order>"
- module: commandline
code: SFTP_FAILURE
branchcode: ""
name: "File SFTP failed"
is_html: 0
title: "The SFTP by sftp_file.pl failed"
message_transport_type: email
lang: default
content:
- "SFTP upload failed:"
- ""
- "<<sftp_status>>"
- module: commandline
code: SFTP_SUCCESS
branchcode: ""
name: "File SFTP success"
is_html: 0
title: "The SFTP by sftp_file.pl was successful"
message_transport_type: email
lang: default
content:
- "SFTP upload succeeded"
- module: ill
code: ILL_PICKUP_READY
branchcode: ""

View File

@ -23,6 +23,7 @@ use Koha::Email;
use Getopt::Long qw( GetOptions );
use Pod::Usage qw( pod2usage );
use Carp qw( carp );
use C4::Letters qw( GetPreparedLetter EnqueueLetter );
=head1 NAME
@ -178,14 +179,6 @@ if ( $email ) {
if ( !Koha::Email->is_valid($email) ) {
return warn "The email address you defined in the --email parameter is invalid\n";
}
$status_email = Koha::Email->new(
{
to => $email,
from => $admin_address,
subject => '[OCLC] ' . C4::Context->config('database') . ' ' . $sftp_status,
}
);
}
# Do the SFTP upload
@ -196,31 +189,33 @@ if (
callback => sub { my ( $sftp, $data, $offset, $size ) = @_; warn "$offset of $size bytes transferred\n"; }
)
) {
$sftp_status = 'successful';
# Send success email
if ( $email ) {
$status_email_message = "OCLC upload was successful";
}
$sftp_status = 'SUCCESS';
close $fh;
} else {
$sftp_status = 'failed';
# Send failure email
if ( $email ) {
$status_email_message = "OCLC upload failed\nOCLC error: " . $sftp->error;
}
$sftp_status = 'FAILURE';
}
# Send email confirming the success or failure of the SFTP
if ( $email ) {
$status_email->text_body($status_email_message);
my $smtp_server = Koha::SMTP::Servers->get_default;
$email->transport( $smtp_server->transport );
try {
$email->send_or_die;
}
catch {
carp "Mail not sent: $_";
};
$status_email = C4::Letters::GetPreparedLetter (
module => 'commandline',
letter_code => "SFTP_$sftp_status", #SFTP_SUCCESS, SFTP_FAILURE
message_transport_type => 'email',
substitute => {
sftp_error => $sftp->error
}
);
C4::Letters::EnqueueLetter(
{
letter => $status_email,
to_address => $email,
from_address => $admin_address,
message_transport_type => 'email'
}
) or warn "can't enqueue letter " . $status_email->{code};
}
cronlogaction({ action => 'End', info => "COMPLETED" });