From bec0b96e72dddb86d89698cfa3a7e1632168de9c Mon Sep 17 00:00:00 2001 From: Martin Renvoize 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. --- Koha/Patrons/Import.pm | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Koha/Patrons/Import.pm b/Koha/Patrons/Import.pm index fe3fd80c11..b695c4a93b 100644 --- a/Koha/Patrons/Import.pm +++ b/Koha/Patrons/Import.pm @@ -437,6 +437,46 @@ 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 + && $borrower{'userid'} + && $borrower{'password'} ) + { + #look for defined primary email address, if blank - attempt to use borr.email + #and borr.emailpro instead + my $emailaddr; + if ( C4::Context->preference("AutoEmailPrimaryAddress") ne 'OFF' + && $borrower{ C4::Context->preference( + "AutoEmailPrimaryAddress") } =~ /\w\@\w/ ) + { + $emailaddr = $borrower{ C4::Context->preference( + "AutoEmailPrimaryAddress") }; + } + elsif ( $borrower{email} =~ /\w\@\w/ ) { + $emailaddr = $borrower{email}; + } + elsif ( $borrower{emailpro} =~ /\w\@\w/ ) { + $emailaddr = $borrower{emailpro}; + } + elsif ( $borrower{B_email} =~ /\w\@\w/ ) { + $emailaddr = $borrower{B_email}; + } + + # 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