From 6696b0e42d01c3120ee63a6f66ecda8895fc99eb Mon Sep 17 00:00:00 2001
From: Alex Buckley
Date: Wed, 6 Apr 2022 09:33:12 +1200
Subject: [PATCH] Bug 23538: Email library when new patron self-registers
Test plan:
1. Apply patchset
2. Update database:
- cd installer/data/mysql
- sudo koha-shell
- ./updatedatabase.pl
3. Restart services
4. Set email addresses in:
- KohaAdminEmailAddress syspref
- EmailAddressForPatronRegistrations syspref
- Email address in the library branch
5. Enable PatronSelfRegistration syspref
6. Test the following use cases:
6.a. EmailPatronRegistrations syspref = 'none'. Submit OPAC registration.
= OUTCOME: Confirm no OPAC_REG notice in message_queue table
6.b. EmailPatronRegistrations syspref = 'email address of branch'. Submit OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address of
branch address
6.c. EmailPatronRegistrations syspref =
'EmailAddressForPatronRegistrations'. Submit OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address
equalling EmailAddressForPatronRegistrations syspref
6.d. EmailPatronRegistrations syspref = 'KohaAdminEmailAddress'. Submit
OPAC registration.
= OUTCOME: Confirm OPAC_REG notice in message_queue with to_address
equalling KohaAdminEmaiLAddress syspref
7. Enable PatronSelfRegistrationVerifyByEmail syspref
8. Repeat steps 6.a, 6.b, 6.c, 6.d but this time confirm the expected
outcomes only happen AFTER you have clicked the verification link in the
OPAC_REG_VERIFY notice
Sponsored-by: Catalyst IT
---
Koha/Patron.pm | 51 +++++++++++++++++++
...lAddressForPatronRegistrations_sysprefs.pl | 19 ++++---
.../mysql/en/mandatory/sample_notices.yml | 19 ++++---
opac/opac-memberentry.pl | 7 +++
opac/opac-registration-verify.pl | 6 +++
5 files changed, 82 insertions(+), 20 deletions(-)
diff --git a/Koha/Patron.pm b/Koha/Patron.pm
index 58f600c0a9..68b38344dc 100644
--- a/Koha/Patron.pm
+++ b/Koha/Patron.pm
@@ -2078,6 +2078,57 @@ sub account_balance {
return $self->account->balance;
}
+=head3 notify_library_of_registration
+
+$patron->notify_library_of_registration( $email_patron_registrations );
+
+Send patron registration email to library if EmailPatronRegistrations system preference is enabled.
+
+=cut
+
+sub notify_library_of_registration {
+ my ( $self, $email_patron_registrations ) = @_;
+
+ if (
+ my $letter = C4::Letters::GetPreparedLetter(
+ module => 'members',
+ letter_code => 'OPAC_REG',
+ branchcode => $self->branchcode,
+ lang => $self->lang || 'default',
+ tables => {
+ 'borrowers' => $self->borrowernumber
+ },
+ )
+ ) {
+ my $to_address;
+ if ( $email_patron_registrations eq "BranchEmailAddress" ) {
+ my $library = Koha::Libraries->find( $self->branchcode );
+ $to_address = $library->inbound_email_address;
+ }
+ elsif ( $email_patron_registrations eq "KohaAdminEmailAddress" ) {
+ $to_address = C4::Context->preference('ReplytoDefault')
+ || C4::Context->preference('KohaAdminEmailAddress');
+ }
+ else {
+ $to_address =
+ C4::Context->preference('EmailAddressForPatronRegistrations')
+ || C4::Context->preference('ReplytoDefault')
+ || C4::Context->preference('KohaAdminEmailAddress');
+ }
+
+ my $message_id = C4::Letters::EnqueueLetter(
+ {
+ letter => $letter,
+ borrowernumber => $self->borrowernumber,
+ to_address => $to_address,
+ message_transport_type => 'email'
+ }
+ ) or warn "can't enqueue letter $letter";
+ if ( $message_id ) {
+ return 1;
+ }
+ }
+}
=head2 Internal methods
diff --git a/installer/data/mysql/atomicupdate/bug23538-add_EmailPatronRegistrations_and_EmailAddressForPatronRegistrations_sysprefs.pl b/installer/data/mysql/atomicupdate/bug23538-add_EmailPatronRegistrations_and_EmailAddressForPatronRegistrations_sysprefs.pl
index 61ee73395e..55082df006 100755
--- a/installer/data/mysql/atomicupdate/bug23538-add_EmailPatronRegistrations_and_EmailAddressForPatronRegistrations_sysprefs.pl
+++ b/installer/data/mysql/atomicupdate/bug23538-add_EmailPatronRegistrations_and_EmailAddressForPatronRegistrations_sysprefs.pl
@@ -13,16 +13,15 @@ return {
'New OPAC self-registration
Self-registration made by
- - <> <>
- - Physical address: <> <> <> <>, <>, <> <>, <>
- - Email: <>
- - Phone: <>
- - Mobile: <>
- - Fax: <>
- - Secondary email: <>
- - Secondary phone:<>
- - Home library: <>
- - Temporary patron category: <>
+ - <> <>
+ - Email: <>
+ - Phone: <>
+ - Mobile: <>
+ - Fax: <>
+ - Secondary email: <>
+ - Secondary phone:<>
+ - Home library: <>
+ - Patron category: <>
', 'email', 'default') });
},
diff --git a/installer/data/mysql/en/mandatory/sample_notices.yml b/installer/data/mysql/en/mandatory/sample_notices.yml
index 121276dbbc..953d158355 100644
--- a/installer/data/mysql/en/mandatory/sample_notices.yml
+++ b/installer/data/mysql/en/mandatory/sample_notices.yml
@@ -1648,15 +1648,14 @@ tables:
- "New OPAC self-registration
"
- "Self-registration made by
"
- ""
- - "- <> <>
"
- - "- Physical address: <> <> <> <>, <>, <> <>, <>
"
- - "- Email: <>
"
- - "- Phone: <>
"
- - "- Mobile: <>
"
- - "- Fax: <>
"
- - "- Secondary email: <>
"
- - "- Secondary phone:<>
"
- - "- Home library: <>
"
- - "- Temporary patron category: <>
"
+ - "- <> <>
"
+ - "- Email: <>
"
+ - "- Phone: <>
"
+ - "- Mobile: <>
"
+ - "- Fax: <>
"
+ - "- Secondary email: <>
"
+ - "- Secondary phone:<>
"
+ - "- Home library: <>
"
+ - "- Temporary patron category: <>
"
- "
"
- ""
diff --git a/opac/opac-memberentry.pl b/opac/opac-memberentry.pl
index e33ab0391e..432b28b81f 100755
--- a/opac/opac-memberentry.pl
+++ b/opac/opac-memberentry.pl
@@ -274,6 +274,13 @@ if ( $action eq 'create' ) {
};
}
}
+
+ # Notify library of new patron registration
+ my $notify_library = C4::Context->preference('EmailPatronRegistrations');
+ if ($notify_library) {
+ $patron->notify_library_of_registration($notify_library);
+ }
+
} else {
# FIXME Handle possible errors here
}
diff --git a/opac/opac-registration-verify.pl b/opac/opac-registration-verify.pl
index 99651eef5c..22de52decb 100755
--- a/opac/opac-registration-verify.pl
+++ b/opac/opac-registration-verify.pl
@@ -110,6 +110,12 @@ if (
}
}
+ # Notify library of new patron registration
+ my $notify_library = C4::Context->preference("EmailPatronRegistrations");
+ if ($notify_library) {
+ $patron->notify_library_of_registration($notify_library);
+ }
+
$template->param(
PatronSelfRegistrationAdditionalInstructions =>
C4::Context->preference(
--
2.20.1