Bugzilla – Attachment 70865 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 - Send emails to guarantee and guarantor
Bug-12532---Send-emails-to-guarantee-and-guarantor.patch (text/plain), 9.29 KB, created by
Charles Farmer
on 2018-01-23 23:22:19 UTC
(
hide
)
Description:
Bug 12532 - Send emails to guarantee and guarantor
Filename:
MIME Type:
Creator:
Charles Farmer
Created:
2018-01-23 23:22:19 UTC
Size:
9.29 KB
patch
obsolete
>From edcf5d942f53059068e5ddf311919f221e32a19c Mon Sep 17 00:00:00 2001 >From: David Bourgault <dav.bour@gmail.com> >Date: Wed, 13 Sep 2017 09:32:38 -0400 >Subject: [PATCH] Bug 12532 - Send emails to guarantee and guarantor > >Adds setting "RedirectGuaranteeEmail". When setting is enabled, >emails to patron with a guarantor will be send to both guarantor >and guarantee. > >Does this by amending the C4::Members::GetNoticeEmail() sub. It does >not affect values in the message_queue table. > >Test plan: > >Before applying >1) Select patron with guarantor >2) Enable checkout emails >3) Checkout item. Email will be sent only to guarantee >4) Apply patch >5) Run updatedatabase.pl >6) Enable 'RedirectGuaranteeEmail' in system preferences >7) Go through step 1) to 3). Email should now be sent to both. >8) Run t/db_dependant/Members.t > >Sponsored by: Ville de Victoriaville > >Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz> >--- > C4/Letters.pm | 4 +- > C4/Members.pm | 72 ++++++++++++++++++++++ > .../bug_12532-RedirectGuaranteeEmail_syspref.sql | 2 + > installer/data/mysql/sysprefs.sql | 1 + > .../prog/en/modules/admin/preferences/patrons.pref | 6 ++ > t/db_dependent/Members.t | 38 +++++++++++- > 6 files changed, 121 insertions(+), 2 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug_12532-RedirectGuaranteeEmail_syspref.sql > >diff --git a/C4/Letters.pm b/C4/Letters.pm >index 42893f1..f030bde 100644 >--- a/C4/Letters.pm >+++ b/C4/Letters.pm >@@ -1305,7 +1305,9 @@ sub _send_message_by_email { > > my $patron = Koha::Patrons->find( $message->{borrowernumber} ); > my $to_address = $message->{'to_address'}; >- unless ($to_address) { >+ >+ my $use_garantor = C4::Context->preference('RedirectGuaranteeEmail'); >+ if($use_garantor || !$to_address) { > unless ($patron) { > warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})"; > _set_message_status( { message_id => $message->{'message_id'}, >diff --git a/C4/Members.pm b/C4/Members.pm >index faa497f..a1e2737 100644 >--- a/C4/Members.pm >+++ b/C4/Members.pm >@@ -71,6 +71,8 @@ BEGIN { > &IssueSlip > > GetOverduesForPatron >+ >+ &GetNoticeEmailAddress > ); > > #Modify data >@@ -876,6 +878,76 @@ sub get_cardnumber_length { > return ( $min, $max ); > } > >+=head2 GetFirstValidEmailAddress >+ >+ $email = GetFirstValidEmailAddress($borrowernumber); >+ >+Return the first valid email address for a borrower, given the borrowernumber. For now, the order >+is defined as email, emailpro, B_email. Returns the empty string if the borrower has no email >+addresses. >+ >+=cut >+ >+sub GetFirstValidEmailAddress { >+ my $borrowernumber = shift; >+ >+ my $borrower = Koha::Patrons->find( $borrowernumber ); >+ >+ return $borrower->first_valid_email_address(); >+} >+ >+=head2 GetNoticeEmailAddress >+ >+ $email = GetNoticeEmailAddress($borrowernumber); >+ >+Return the email address of borrower used for notices, given the borrowernumber. >+Returns the empty string if no email address. >+ >+=cut >+ >+sub GetNoticeEmailAddress { >+ my $borrowernumber = shift; >+ >+ my $which_address = C4::Context->preference("AutoEmailPrimaryAddress"); >+ my $address; >+ >+ # if syspref is set to 'first valid' (value == OFF), look up email address >+ if ( $which_address eq 'OFF' ) { >+ $address = GetFirstValidEmailAddress($borrowernumber); >+ } >+ else { >+ # specified address address field >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare( qq{ >+ SELECT $which_address AS primaryaddress >+ FROM borrowers >+ WHERE borrowernumber=? >+ } ); >+ $sth->execute($borrowernumber); >+ $address = $sth->fetchrow_hashref->{'primaryaddress'}; >+ } >+ >+ # If RedirectGuaranteeEmail is enabled, (and user as guarantor) append guarantor's email >+ my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail'); >+ if ($use_guarantor) { >+ my ($guarantor_id, $guarantor_address ); >+ my $dbh = C4::Context->dbh; >+ my $sth = $dbh->prepare( qq{ >+ SELECT guarantorid >+ FROM borrowers >+ WHERE borrowernumber=? >+ }); >+ $sth->execute($borrowernumber); >+ $guarantor_id = $sth->fetchrow_hashref->{'guarantorid'}; >+ >+ if ($guarantor_id) { >+ $guarantor_address = GetNoticeEmailAddress($guarantor_id); >+ $address .= ', ' . $guarantor_address if $guarantor_address; >+ } >+ } >+ return $address || ''; >+} >+ > =head2 GetBorrowersToExpunge > > $borrowers = &GetBorrowersToExpunge( >diff --git a/installer/data/mysql/atomicupdate/bug_12532-RedirectGuaranteeEmail_syspref.sql b/installer/data/mysql/atomicupdate/bug_12532-RedirectGuaranteeEmail_syspref.sql >new file mode 100644 >index 0000000..e3de7b1 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_12532-RedirectGuaranteeEmail_syspref.sql >@@ -0,0 +1,2 @@ >+INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) >+VALUES ('RedirectGuaranteeEmail','0',NULL,'Enable the ability to redirect guarantee email messages to guarantor.','YesNo'); >\ No newline at end of file >diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql >index 68881d0..ddd1ffa 100644 >--- a/installer/data/mysql/sysprefs.sql >+++ b/installer/data/mysql/sysprefs.sql >@@ -445,6 +445,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('QuoteOfTheDay','0',NULL,'Enable or disable display of Quote of the Day on the OPAC home page','YesNo'), > ('RandomizeHoldsQueueWeight','0',NULL,'if ON, the holds queue in circulation will be randomized, either based on all location codes, or by the location codes specified in StaticHoldsQueueWeight','YesNo'), > ('RecordLocalUseOnReturn','0',NULL,'If ON, statistically record returns of unissued items as local use, instead of return','YesNo'), >+('RedirectGuaranteeEmail', '0', NULL, 'Enable the ability to redirect guarantee email messages to guarantor.', 'YesNo'), > ('RefundLostOnReturnControl','CheckinLibrary','CheckinLibrary|ItemHomeBranch|ItemHoldingBranch','If a lost item is returned, choose which branch to pick rules for refunding.','Choice'), > ('RenewalLog','0','','If ON, log information about renewals','YesNo'), > ('RenewalPeriodBase','date_due','date_due|now','Set whether the renewal date should be counted from the date_due or from the moment the Patron asks for renewal ','Choice'), >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref >index 5591aa1..6d34b4d 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref >@@ -200,6 +200,12 @@ Patrons: > no: "Don't" > - track last patron activity. > - Everytime a patron will connect, the borrowers.lastseen will be updated with the current time. >+ - >+ - pref: RedirectGuaranteeEmail >+ choices: >+ yes: Enable >+ no: Disable >+ - sending emails to both guarantees and their guarantor. This does not affect patrons without guarantors. > "Norwegian patron database": > - > - pref: NorwegianPatronDBEnable >diff --git a/t/db_dependent/Members.t b/t/db_dependent/Members.t >index ac928b2..e805637 100755 >--- a/t/db_dependent/Members.t >+++ b/t/db_dependent/Members.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 62; >+use Test::More tests => 65; > use Test::MockModule; > use Test::Exception; > >@@ -139,6 +139,42 @@ $checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, ""); > is ($checkcardnum, "2", "Card number is too long"); > > >+# Test GetNoticeEmailAddress >+# Add Guarantor for testing >+my $GUARANTOR_EMAIL = "Robert\@email.com"; >+%data = ( >+ cardnumber => "2997924548", >+ firstname => "Robert", >+ surname => "Tables", >+ categorycode => $patron_category->{categorycode}, >+ branchcode => $BRANCHCODE, >+ dateofbirth => '', >+ dateexpiry => '9999-12-31', >+ userid => 'bobbytables', >+ email => $GUARANTOR_EMAIL >+); >+$member->{guarantorid} = AddMember( %data ); >+ModMember( %$member ); >+ >+t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '0' ); >+t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' ); >+C4::Context->clear_syspref_cache(); >+ >+my $notice_email = GetNoticeEmailAddress($member->{'borrowernumber'}); >+is ($notice_email, $EMAIL, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is off"); >+ >+t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'emailpro' ); >+C4::Context->clear_syspref_cache(); >+ >+$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'}); >+is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro"); >+ >+t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' ); >+t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '1' ); >+C4::Context->clear_syspref_cache(); >+$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'}); >+is ($notice_email, $EMAIL . ", " . $GUARANTOR_EMAIL, "GetNoticeEmailAddress returns correct value when RedirectGuaranteeEmail is enabled"); >+ > # Check_Userid tests > %data = ( > cardnumber => "123456789", >-- >2.7.4
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