Bugzilla – Attachment 30984 Details for
Bug 11678
Gather print notices: send files by email
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11678: Gather print notices: add --email parameter
Bug-11678-Gather-print-notices-add---email-paramet.patch (text/plain), 4.30 KB, created by
Jonathan Druart
on 2014-08-19 13:02:41 UTC
(
hide
)
Description:
Bug 11678: Gather print notices: add --email parameter
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2014-08-19 13:02:41 UTC
Size:
4.30 KB
patch
obsolete
>From c091b8928dd3643e36144f61f571cce86bdbf93a Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Thu, 23 Jan 2014 13:12:30 +0100 >Subject: [PATCH] Bug 11678: Gather print notices: add --email parameter > >This patch add the ability to send generated files by email. > >You can specify several emails. > >Test plan: >- same as Bug 11603 >- call the script misc/cronjobs/gather_print_notices.pl with the > following parameters: > >perl misc/cronjobs/gather_print_notices.pl /tmp/test --csv --ods --html >--letter_code=CHECKIN -d=: --email="email_one@example.org" >--email="email_two@example.org" > >check your mailbox and verify the email contain 3 attached files: 1 csv, >1 ods and 1 html >--- > misc/cronjobs/gather_print_notices.pl | 70 ++++++++++++++++++++++++++++++++++- > 1 file changed, 68 insertions(+), 2 deletions(-) > >diff --git a/misc/cronjobs/gather_print_notices.pl b/misc/cronjobs/gather_print_notices.pl >index 890c8ce..e0f07ea 100755 >--- a/misc/cronjobs/gather_print_notices.pl >+++ b/misc/cronjobs/gather_print_notices.pl >@@ -21,8 +21,9 @@ use Pod::Usage; > use Getopt::Long; > use File::Basename qw( dirname ); > use Koha::DateUtils; >+use MIME::Lite; > >-my ( $stylesheet, $help, $split, $html, $csv, $ods, $delimiter, @letter_codes ); >+my ( $stylesheet, $help, $split, $html, $csv, $ods, $delimiter, @letter_codes, @emails ); > > GetOptions( > 'h|help' => \$help, >@@ -32,6 +33,7 @@ GetOptions( > 'ods' => \$ods, > 'd|delimiter:s' => \$delimiter, > 'letter_code:s' => \@letter_codes, >+ 'e|email:s' => \@emails, > ) || pod2usage(1); > > pod2usage(0) if $help; >@@ -77,6 +79,7 @@ my @all_messages = @{ GetPrintMessages() }; > exit unless @all_messages; > > my ( $html_filenames, $csv_filenames, $ods_filenames ); >+ > $csv_filenames = print_notices({ > messages => \@all_messages, > split => $split, >@@ -108,6 +111,22 @@ if ( $html ) { > }); > } > >+if ( @emails ) { >+ my $files = { >+ html => $html_filenames, >+ csv => $csv_filenames, >+ ods => $ods_filenames, >+ }; >+ for my $email ( @emails ) { >+ send_files({ >+ directory => $output_directory, >+ files => $files, >+ to => $email, >+ from => C4::Context->preference('KohaAdminEmailAddress'), # Should be replaced if bug 8000 is pushed >+ }); >+ } >+} >+ > sub print_notices { > my ( $params ) = @_; > >@@ -263,13 +282,56 @@ sub generate_ods { > $doc->save(); > } > >+sub send_files { >+ my ( $params ) = @_; >+ my $directory = $params->{directory}; >+ my $files = $params->{files}; >+ my $to = $params->{to}; >+ my $from = $params->{from}; >+ return unless $to and $from; >+ >+ my $mail = MIME::Lite->new( >+ From => $from, >+ To => $to, >+ Subject => 'Print notices for ' . $today->output(), >+ Type => 'multipart/mixed', >+ ); >+ >+ while ( my ( $type, $filenames ) = each %$files ) { >+ for my $filename ( @$filenames ) { >+ my $mimetype = $type eq 'html' >+ ? 'text/html' >+ : $type eq 'csv' >+ ? 'text/csv' >+ : $type eq 'ods' >+ ? 'application/vnd.oasis.opendocument.spreadsheet' >+ : undef; >+ >+ next unless $mimetype; >+ >+ my $filepath = File::Spec->catdir( $directory, $filename ); >+ >+ next unless $filepath or -f $filepath; >+ >+ $mail->attach( >+ Type => $mimetype, >+ Path => $filepath, >+ Filename => $filename, >+ Encoding => 'base64', >+ ); >+ } >+ } >+ >+ $mail->send; >+} >+ > =head1 NAME > > gather_print_notices - Print waiting print notices > > =head1 SYNOPSIS > >-gather_print_notices output_directory [-s|--split] [--html] [--csv] [--ods] [--letter_code=LETTER_CODE] [-h|--help] >+gather_print_notices output_directory [-s|--split] [--html] [--csv] [--ods] [--letter_code=LETTER_CODE] [-e|--email=your_email@example.org] [-h|--help] > > Will print all waiting print notices to the output_directory. > >@@ -314,6 +376,10 @@ This is the same as the csv parameter but using csv2odf to generate an ods file > Filter print messages by letter_code. > Several letter_code parameters can be given. > >+=item B<-e|--email> >+ >+E-mail address to send generated files. >+ > =item B<-h|--help> > > Print a brief help message >-- >2.0.0.rc2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11678
:
25025
|
30984
|
37838
|
43581
|
43582
|
43939
|
43940
|
43941