Bugzilla – Attachment 154857 Details for
Bug 12532
Copy guarantee email to guarantor (or redirect if guarantee has no email set)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 12532: (follow-up) Send email to guarantor using the CC field
Bug-12532-follow-up-Send-email-to-guarantor-using-.patch (text/plain), 5.08 KB, created by
Hammat wele
on 2023-08-25 23:42:34 UTC
(
hide
)
Description:
Bug 12532: (follow-up) Send email to guarantor using the CC field
Filename:
MIME Type:
Creator:
Hammat wele
Created:
2023-08-25 23:42:34 UTC
Size:
5.08 KB
patch
obsolete
>From 78af1289670ae7f83da8426951a5719e4dd08641 Mon Sep 17 00:00:00 2001 >From: Hammat Wele <hammat.wele@inlibro.com> >Date: Fri, 25 Aug 2023 23:39:24 +0000 >Subject: [PATCH] Bug 12532: (follow-up) Send email to guarantor using the CC > field >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >In This patch the CC field is used to send the message to the guarantors. If the «to» field is empty (the guarantee has no address) we send the message «to» the garantors. >--- > C4/Letters.pm | 33 +++++++++++++++++++++++++++------ > Koha/Patron.pm | 28 ++++------------------------ > 2 files changed, 31 insertions(+), 30 deletions(-) > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index 4c17c29f13..519639f9d1 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -40,6 +40,7 @@ use Koha::Auth::TwoFactorAuth; > use Koha::Patrons; > use Koha::SMTP::Servers; > use Koha::Subscriptions; >+use Data::Dumper; > > use constant SERIALIZED_EMAIL_CONTENT_TYPE => 'message/rfc822'; > >@@ -1319,12 +1320,23 @@ sub _send_message_by_email { > my $message = shift or return; > my ( $username, $password, $method, $smtp_transports ) = @_; > >- my $patron; >+ my $patron = Koha::Patrons->find( $message->{borrowernumber} ); > my $to_address = $message->{'to_address'}; >- my $use_garantor = C4::Context->preference('RedirectGuaranteeEmail'); >- if($use_garantor eq 'yes' || !$to_address) { >- $patron = Koha::Patrons->find( $message->{borrowernumber} ); >- unless ($patron or $to_address) { >+ my $cc_address; >+ my @guarantor_address; >+ my $count_guarantor_address; >+ if (C4::Context->preference('RedirectGuaranteeEmail') eq 'yes' && $patron) { >+ #Get guanrantor adresses >+ my $guarantor_relationships = $patron->guarantor_relationships; >+ my @guarantors = $guarantor_relationships->guarantors->as_list; >+ foreach my $guarantor (@guarantors) { >+ my $address = $guarantor->notice_email_address; >+ push( @guarantor_address, $address ) if $address; >+ } >+ $count_guarantor_address = scalar @guarantor_address; >+ } >+ unless ($to_address) { >+ if (!$patron && !$count_guarantor_address) { > warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; > _set_message_status( > { >@@ -1338,7 +1350,7 @@ sub _send_message_by_email { > if ($patron) { > $to_address = $patron->notice_email_address; > } >- unless ($to_address) { >+ if (!$to_address && !$count_guarantor_address) { > # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})"; > # warning too verbose for this more common case? > _set_message_status( >@@ -1350,8 +1362,12 @@ sub _send_message_by_email { > ); > return; > } >+ if (!$to_address && $count_guarantor_address) { >+ $to_address = shift @guarantor_address; >+ } > } > >+ $cc_address = join( ',', @guarantor_address ); > # Skip this message if we exceed domain limits in this run > if( Koha::Notice::Util->exceeds_limit({ to => $to_address, limits => $domain_limits }) ) { > # Save the to_address if you delay the message so that we dont need to look it up again >@@ -1406,6 +1422,11 @@ sub _send_message_by_email { > ? ( bcc => C4::Context->preference('NoticeBcc') ) > : () > ), >+ ( >+ $cc_address >+ ? ( cc => $cc_address ) >+ : () >+ ), > from => $from_address, > reply_to => $message->{'reply_address'} || $branch_replyto, > sender => $branch_returnpath, >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 1d058fc52c..6937ea904a 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -1411,36 +1411,16 @@ Returns the empty string if no email address. > > =cut > >-sub notice_email_address { >- my ($self) = @_; >- my $address; >- my $guarantor_address; >+sub notice_email_address{ >+ my ( $self ) = @_; > > my $which_address = C4::Context->preference("EmailFieldPrimary"); >- > # if syspref is set to 'first valid' (value == OFF), look up email address > if ( $which_address eq 'OFF' ) { >- $address = $self->first_valid_email_address; >- } >- else { >- $address = $self->$which_address || ''; >+ return $self->first_valid_email_address; > } > >- my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail'); >- if ($use_guarantor) { >- my @guarantors = >- map { $_->guarantors->as_list } $self->guarantor_relationships(); >- if (@guarantors) { >- foreach my $guarantor (@guarantors) { >- $guarantor_address = $guarantor->notice_email_address; >- if ($address) { >- $address .= ', '; >- } >- $address .= $guarantor_address if $guarantor_address; >- } >- } >- } >- return $address; >+ return $self->$which_address || ''; > } > > =head3 first_valid_email_address >-- >2.34.1
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 12532
:
29510
|
30747
|
35313
|
36752
|
39787
|
39925
|
48645
|
53649
|
53689
|
53690
|
53699
|
53700
|
55985
|
56052
|
56053
|
59445
|
59446
|
59447
|
63197
|
64802
|
64824
|
67115
|
68340
|
70865
|
72064
|
72617
|
75099
|
77606
|
80313
|
85134
|
85135
|
87815
|
87816
|
88208
|
88209
|
88210
|
88211
|
88212
|
88213
|
88295
|
88296
|
114455
|
114456
|
114457
|
114458
|
114459
|
114460
|
114461
|
131091
|
131092
|
131093
|
131094
|
149233
|
150071
|
150208
|
150217
|
150240
|
150256
|
151028
|
151029
|
154854
|
154855
|
154856
|
154857
|
155036
|
155037
|
155828
|
155829
|
155830
|
155831
|
155832
|
155833
|
155834
|
155835
|
155836
|
155837
|
155873
|
155874
|
155875
|
155876
|
155877
|
155878
|
155879
|
155880
|
155881
|
155882
|
155883
|
155886
|
155934
|
155935
|
155936
|
155937
|
155938
|
155939
|
155940
|
155941
|
155942
|
155943
|
155944
|
155945
|
155946