From 5ae3a3aa4f79f457605e03f53a4b385212d9d93e Mon Sep 17 00:00:00 2001 From: Ian Walls Date: Fri, 3 Jun 2011 16:29:38 -0400 Subject: [PATCH] Bug 5929: use branch admin email for advance_notice.pl emails This squash commit takes the two patches from Srdjan and adds a minor fix to work with template toolkit variable renames. Squashed commit of the following: commit 2cab669d1fd072600942e1e6fbf3378944255a68 Author: Ian Walls Date: Thu Jun 2 14:08:40 2011 -0400 Bug 5929: Fix advanced_notices to use new template-toolkit compatible message names Uses 'item_due' and 'advance_notice' for advance notices names; letters do not send otherwise commit caded04702d5eebd0f63a3b93cdddce28257f092 Author: Srdjan Jankovic Date: Tue Mar 29 12:38:49 2011 +1300 wr77490 (bug 5929): removed debugging leftover commit 1944de0de40f937b1d8748500f24a119390db3f0 Author: Srdjan Jankovic Date: Tue Mar 22 19:05:23 2011 +1300 wr77490 (bug 5929): use branch email in preference for due notices Signed-off-by: Ian Walls Signed-off-by: Chris Cormack --- C4/Circulation.pm | 3 ++- misc/cronjobs/advance_notices.pl | 39 ++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 13 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 9a2db4c518..5efd090099 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2093,9 +2093,10 @@ sub GetUpcomingDueIssues { my $dbh = C4::Context->dbh; my $statement = <preference('KohaAdminEmailAddress'); # -f: From address for the emails my $verbose = 0; # -v: verbose my $itemscontent = join(',',qw( issuedate title barcode author )); GetOptions( 'c' => \$confirm, 'n' => \$nomail, 'm:i' => \$maxdays, - 'f:s' => \$fromaddress, 'v' => \$verbose, 'itemscontent=s' => \$itemscontent, ); @@ -83,7 +81,6 @@ See the comments in the script for directions on changing the script. This script has the following parameters : -c Confirm and remove this help & warning -m maximum number of days in advance to send advance notices. - -f from address for the emails. Defaults to KohaAdminEmailAddress system preference -n send No mail. Instead, all mail messages are printed on screen. Usefull for testing purposes. -v verbose -i csv list of fields that get substituted into templates in places @@ -135,22 +132,28 @@ SELECT biblio.*, items.*, issues.* AND (TO_DAYS(date_due)-TO_DAYS(NOW()) = ?) END_SQL +my $admin_adress = C4::Context->preference('KohaAdminEmailAddress'); + UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { warn 'examining ' . $upcoming->{'itemnumber'} . ' upcoming due items' if $verbose; # warn( Data::Dumper->Dump( [ $upcoming ], [ 'overdue' ] ) ); + my $from_address = $upcoming->{branchemail} || $admin_adress; + my $letter; my $borrower_preferences; if ( 0 == $upcoming->{'days_until_due'} ) { # This item is due today. Send an 'item due' message. $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $upcoming->{'borrowernumber'}, - message_name => 'item due' } ); + message_name => 'item_due' } ); # warn( Data::Dumper->Dump( [ $borrower_preferences ], [ 'borrower_preferences' ] ) ); - next DUEITEM unless $borrower_preferences; + next unless $borrower_preferences; if ( $borrower_preferences->{'wants_digest'} ) { # cache this one to process after we've run through all of the items. - $due_digest->{$upcoming->{'borrowernumber'}}++; + my $digest = $due_digest->{$upcoming->{'borrowernumber'}} ||= {}; + $digest->{email} ||= $from_address; + $digest->{count}++; } else { my $biblio = C4::Biblio::GetBiblioFromItemNumber( $upcoming->{'itemnumber'} ); my $letter_type = 'DUE'; @@ -172,14 +175,16 @@ UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { } } else { $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $upcoming->{'borrowernumber'}, - message_name => 'advance notice' } ); + message_name => 'advance_notice' } ); # warn( Data::Dumper->Dump( [ $borrower_preferences ], [ 'borrower_preferences' ] ) ); next UPCOMINGITEM unless $borrower_preferences && exists $borrower_preferences->{'days_in_advance'}; next UPCOMINGITEM unless $borrower_preferences->{'days_in_advance'} == $upcoming->{'days_until_due'}; if ( $borrower_preferences->{'wants_digest'} ) { # cache this one to process after we've run through all of the items. - $upcoming_digest->{$upcoming->{'borrowernumber'}}++; + my $digest = $upcoming_digest->{$upcoming->{'borrowernumber'}} ||= {}; + $digest->{email} ||= $from_address; + $digest->{count}++; } else { my $biblio = C4::Biblio::GetBiblioFromItemNumber( $upcoming->{'itemnumber'} ); my $letter_type = 'PREDUE'; @@ -211,6 +216,7 @@ UPCOMINGITEM: foreach my $upcoming ( @$upcoming_dues ) { foreach my $transport ( @{$borrower_preferences->{'transports'}} ) { C4::Letters::EnqueueLetter( { letter => $letter, borrowernumber => $upcoming->{'borrowernumber'}, + from_address => $from_address, message_transport_type => $transport } ); } } @@ -231,9 +237,12 @@ SELECT biblio.*, items.*, issues.* AND (TO_DAYS(date_due)-TO_DAYS(NOW()) = ?) END_SQL -PATRON: while ( my ( $borrowernumber, $count ) = each %$upcoming_digest ) { +PATRON: while ( my ( $borrowernumber, $digest ) = each %$upcoming_digest ) { + my $count = $digest->{count}; + my $from_address = $digest->{email}; + my $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrowernumber, - message_name => 'advance notice' } ); + message_name => 'advance_notice' } ); # warn( Data::Dumper->Dump( [ $borrower_preferences ], [ 'borrower_preferences' ] ) ); next PATRON unless $borrower_preferences; # how could this happen? @@ -241,6 +250,7 @@ PATRON: while ( my ( $borrowernumber, $count ) = each %$upcoming_digest ) { my $letter_type = 'PREDUEDGST'; my $letter = C4::Letters::getletter( 'circulation', $letter_type ); die "no letter of type '$letter_type' found. Please see sample_notices.sql" unless $letter; + $sth->execute($borrowernumber,$borrower_preferences->{'days_in_advance'}); my $titles = ""; while ( my $item_info = $sth->fetchrow_hashref()) { @@ -261,15 +271,19 @@ PATRON: while ( my ( $borrowernumber, $count ) = each %$upcoming_digest ) { foreach my $transport ( @{$borrower_preferences->{'transports'}} ) { C4::Letters::EnqueueLetter( { letter => $letter, borrowernumber => $borrowernumber, + from_address => $from_address, message_transport_type => $transport } ); } } } # Now, run through all the people that want digests and send them -PATRON: while ( my ( $borrowernumber, $count ) = each %$due_digest ) { +PATRON: while ( my ( $borrowernumber, $digest ) = each %$due_digest ) { + my $count = $digest->{count}; + my $from_address = $digest->{email}; + my $borrower_preferences = C4::Members::Messaging::GetMessagingPreferences( { borrowernumber => $borrowernumber, - message_name => 'item due' } ); + message_name => 'item_due' } ); # warn( Data::Dumper->Dump( [ $borrower_preferences ], [ 'borrower_preferences' ] ) ); next PATRON unless $borrower_preferences; # how could this happen? @@ -297,6 +311,7 @@ PATRON: while ( my ( $borrowernumber, $count ) = each %$due_digest ) { foreach my $transport ( @{$borrower_preferences->{'transports'}} ) { C4::Letters::EnqueueLetter( { letter => $letter, borrowernumber => $borrowernumber, + from_address => $from_address, message_transport_type => $transport } ); } } -- 2.39.5