|
Lines 23-28
use Koha::Email;
Link Here
|
| 23 |
use Getopt::Long qw( GetOptions ); |
23 |
use Getopt::Long qw( GetOptions ); |
| 24 |
use Pod::Usage qw( pod2usage ); |
24 |
use Pod::Usage qw( pod2usage ); |
| 25 |
use Carp qw( carp ); |
25 |
use Carp qw( carp ); |
|
|
26 |
use C4::Letters qw( GetPreparedLetter EnqueueLetter ); |
| 26 |
|
27 |
|
| 27 |
=head1 NAME |
28 |
=head1 NAME |
| 28 |
|
29 |
|
|
Lines 178-191
if ( $email ) {
Link Here
|
| 178 |
if ( !Koha::Email->is_valid($email) ) { |
179 |
if ( !Koha::Email->is_valid($email) ) { |
| 179 |
return warn "The email address you defined in the --email parameter is invalid\n"; |
180 |
return warn "The email address you defined in the --email parameter is invalid\n"; |
| 180 |
} |
181 |
} |
| 181 |
|
|
|
| 182 |
$status_email = Koha::Email->new( |
| 183 |
{ |
| 184 |
to => $email, |
| 185 |
from => $admin_address, |
| 186 |
subject => '[OCLC] ' . C4::Context->config('database') . ' ' . $sftp_status, |
| 187 |
} |
| 188 |
); |
| 189 |
} |
182 |
} |
| 190 |
|
183 |
|
| 191 |
# Do the SFTP upload |
184 |
# Do the SFTP upload |
|
Lines 196-226
if (
Link Here
|
| 196 |
callback => sub { my ( $sftp, $data, $offset, $size ) = @_; warn "$offset of $size bytes transferred\n"; } |
189 |
callback => sub { my ( $sftp, $data, $offset, $size ) = @_; warn "$offset of $size bytes transferred\n"; } |
| 197 |
) |
190 |
) |
| 198 |
) { |
191 |
) { |
| 199 |
$sftp_status = 'successful'; |
|
|
| 200 |
# Send success email |
192 |
# Send success email |
| 201 |
if ( $email ) { |
193 |
$sftp_status = 'SUCCESS'; |
| 202 |
$status_email_message = "OCLC upload was successful"; |
|
|
| 203 |
} |
| 204 |
close $fh; |
194 |
close $fh; |
| 205 |
} else { |
195 |
} else { |
| 206 |
$sftp_status = 'failed'; |
|
|
| 207 |
# Send failure email |
196 |
# Send failure email |
| 208 |
if ( $email ) { |
197 |
$sftp_status = 'FAILURE'; |
| 209 |
$status_email_message = "OCLC upload failed\nOCLC error: " . $sftp->error; |
|
|
| 210 |
} |
| 211 |
} |
198 |
} |
| 212 |
|
199 |
|
| 213 |
# Send email confirming the success or failure of the SFTP |
200 |
# Send email confirming the success or failure of the SFTP |
| 214 |
if ( $email ) { |
201 |
if ( $email ) { |
| 215 |
$status_email->text_body($status_email_message); |
202 |
$status_email = C4::Letters::GetPreparedLetter ( |
| 216 |
my $smtp_server = Koha::SMTP::Servers->get_default; |
203 |
module => 'commandline', |
| 217 |
$email->transport( $smtp_server->transport ); |
204 |
letter_code => "SFTP_$sftp_status", #SFTP_SUCCESS, SFTP_FAILURE |
| 218 |
try { |
205 |
message_transport_type => 'email', |
| 219 |
$email->send_or_die; |
206 |
substitute => { |
| 220 |
} |
207 |
sftp_error => $sftp->error |
| 221 |
catch { |
208 |
} |
| 222 |
carp "Mail not sent: $_"; |
209 |
); |
| 223 |
}; |
210 |
|
|
|
211 |
C4::Letters::EnqueueLetter( |
| 212 |
{ |
| 213 |
letter => $status_email, |
| 214 |
to_address => $email, |
| 215 |
from_address => $admin_address, |
| 216 |
message_transport_type => 'email' |
| 217 |
} |
| 218 |
) or warn "can't enqueue letter " . $status_email->{code}; |
| 224 |
} |
219 |
} |
| 225 |
|
220 |
|
| 226 |
cronlogaction({ action => 'End', info => "COMPLETED" }); |
221 |
cronlogaction({ action => 'End', info => "COMPLETED" }); |
| 227 |
- |
|
|