From a42b045787130d23b4b85b702f658f6b111bf952 Mon Sep 17 00:00:00 2001 From: Kris Sinnaeve Date: Fri, 1 Oct 2021 10:40:50 +0100 Subject: [PATCH] Bug 29005: Enable welcome email from patron imports This patch was updated from work done by Evangelische Theologische Faculteit to allow the patron import to send welcome emails to users when enabled. Test plan 1. Enable 'AutoEmailOpacUser' system preference 2. Add a new user via the csv patron imports (Include a password and an email address for which you have access) 3. Check that you received a welcome email for the user. 4. Overwrite the previous user with a new password using CSV imports 5. Check that you received a welcome email again for the user. Rescued-by: Martin Renvoize Signed-off-by: Martin Renvoize --- Koha/Patrons/Import.pm | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/Koha/Patrons/Import.pm b/Koha/Patrons/Import.pm index fe3fd80c11..7b84397053 100644 --- a/Koha/Patrons/Import.pm +++ b/Koha/Patrons/Import.pm @@ -24,6 +24,7 @@ use Encode qw( decode_utf8 ); use Try::Tiny qw( catch try ); use C4::Members qw( checkcardnumber ); +use C4::Letters qw( SendAlerts ); use Koha::Libraries; use Koha::Patrons; @@ -277,7 +278,6 @@ sub import_patrons { } } - my $patron = Koha::Patrons->find( $borrowernumber ); try { $schema->storage->txn_do(sub { $patron->set(\%borrower)->store; @@ -373,7 +373,7 @@ sub import_patrons { else { try { $schema->storage->txn_do(sub { - my $patron = Koha::Patron->new(\%borrower)->store; + $patron = Koha::Patron->new(\%borrower)->store; $borrowernumber = $patron->id; if ( $patron->is_debarred ) { @@ -437,6 +437,27 @@ sub import_patrons { }; } + if ($success) { + + # If 'AutoEmailOpacUser' syspref is on, email user their account details from the 'notice' + # that matches the user's branchcode. + if ( C4::Context->preference("AutoEmailOpacUser") == 1 + && $patron->plain_text_password ) + { + my $emailaddr = $patron->notice_email_address; + + # if we manage to find a valid email address, send notice + if ($emailaddr) { + $borrower{emailaddr} = $emailaddr; + my $err; + eval { + $err = + SendAlerts( 'members', \%borrower, "ACCTDETAILS" ); + }; + } + } + } + next LINE unless $success; # Add a guarantor if we are given a relationship -- 2.20.1