Bug 28581: Use 'from_email_address' where appropriate
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 17 Jun 2021 13:30:59 +0000 (14:30 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 23 Jun 2021 13:09:55 +0000 (15:09 +0200)
This patch replaces a few more trivial cases where we were using
library->branchemail with a fallback to KohaAdminEmail to just use the
new library->from_email_address method directly instead.

There were also a couple of cases where we were passing borrowernumber
and the patrons library from address too.. this is unneccesary as the
code in _send_email_massage will already default to patron library from
address if we do not pass an override.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Added a semicolon.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
C4/Reserves.pm
Koha/Illrequest.pm
circ/pendingreserves.pl
misc/cronjobs/notice_unprocessed_suggestions.pl
misc/cronjobs/overdue_notices.pl
suggestion/suggestion.pl

index 0bf8bf6..8fb05c1 100644 (file)
@@ -1849,7 +1849,7 @@ sub _koha_notify_reserve {
 
     my $library = Koha::Libraries->find( $hold->branchcode )->unblessed;
 
-    my $admin_email_address = $library->{branchemail} || C4::Context->preference('KohaAdminEmailAddress');
+    my $admin_email_address = $library->from_email_address;
 
     my %letter_params = (
         module => 'reserves',
index 74d9b84..01d421f 100644 (file)
@@ -1335,7 +1335,7 @@ sub generic_confirm {
             "No target email addresses found. Either select at least one partner or check your ILL partner library records.")
           if ( !$to );
         # Create the from, replyto and sender headers
-        my $from = $branch->branchemail;
+        my $from = $branch->from_email_address;
         my $replyto = $branch->inbound_ill_address;
         Koha::Exceptions::Ill::NoLibraryEmail->throw(
             "Your library has no usable email address. Please set it.")
@@ -1427,7 +1427,7 @@ sub send_patron_notice {
     # Notice should come from the library where the request was placed,
     # not the patrons home library
     my $branch = Koha::Libraries->find($self->branchcode);
-    my $from_address = $branch->branchemail;
+    my $from_address = $branch->from_email_address;
     my $reply_address = $branch->inbound_ill_address;
 
     # Send the notice to the patron via the chosen transport methods
index 9c73023..9310f26 100755 (executable)
@@ -84,13 +84,13 @@ if ( $op eq 'cancel_reserve' and $reserve_id ) {
                 },
             );
             if ( $letter ) {
-                my $admin_email_address = $library->branchemail || C4::Context->preference('KohaAdminEmailAddress');
+                my $from_address = $library->from_email_address;
 
                 C4::Letters::EnqueueLetter(
                     {   letter                 => $letter,
                         borrowernumber         => $patron->borrowernumber,
                         message_transport_type => 'email',
-                        from_address           => $admin_email_address,
+                        from_address           => $from_address,
                     }
                 );
                 unless ( $patron->notice_email_address ) {
index 055315c..d2870b2 100755 (executable)
@@ -48,9 +48,6 @@ for my $number_of_days (@days) {
         my $budget = C4::Budgets::GetBudget( $suggestion->{budgetid} );
         my $patron = Koha::Patrons->find( $budget->{budget_owner_id} );
         my $email_address = $patron->notice_email_address;
-        my $library = $patron->library;
-        my $admin_email_address = $library->branchemail
-          || C4::Context->preference('KohaAdminEmailAddress');
 
         if ($email_address) {
             say "Patron " . $patron->borrowernumber . " is going to be notified" if $verbose;
@@ -70,8 +67,7 @@ for my $number_of_days (@days) {
                     {
                         letter                 => $letter,
                         borrowernumber         => $patron->borrowernumber,
-                        message_transport_type => 'email',
-                        from_address           => $admin_email_address,
+                        message_transport_type => 'email'
                     }
                 );
             }
index 74c1fc3..c18997d 100755 (executable)
@@ -469,8 +469,7 @@ foreach my $branchcode (@branches) {
     }
 
     my $library             = Koha::Libraries->find($branchcode);
-    my $admin_email_address = $library->branchemail
-      || C4::Context->preference('KohaAdminEmailAddress');
+    my $admin_email_address = $library->from_email_address;
     my $branch_email_address = C4::Context->preference('AddressForFailedOverdueNotices')
       || $library->inbound_email_address;
     my @output_chunks;    # may be sent to mail or stdout or csv file.
index 24b2099..370bac1 100755 (executable)
@@ -187,9 +187,6 @@ if ( $op =~ /save/i ) {
                 my $patron = Koha::Patrons->find( $suggestion_only->{managedby} );
                 my $email_address = $patron->notice_email_address;
                 if ($patron->notice_email_address) {
-                    my $library = $patron->library;
-                    my $admin_email_address = $library->branchemail
-                      || C4::Context->preference('KohaAdminEmailAddress');
 
                     my $letter = C4::Letters::GetPreparedLetter(
                         module      => 'suggestions',
@@ -206,8 +203,7 @@ if ( $op =~ /save/i ) {
                         {
                             letter                 => $letter,
                             borrowernumber         => $patron->borrowernumber,
-                            message_transport_type => 'email',
-                            from_address           => $admin_email_address,
+                            message_transport_type => 'email'
                         }
                     );
                 }