status => 'failed' } );
return;
}
- $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
+ $to_address = $patron->notice_email_address;
unless ($to_address) {
# warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
# warning too verbose for this more common case?
&GetPendingIssues
&GetAllIssues
- &GetNoticeEmailAddress
-
&GetMemberAccountRecords
&GetBorrowersToExpunge
return ( $min, $max );
}
-=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");
- # if syspref is set to 'first valid' (value == OFF), look up email address
- if ( $which_address eq 'OFF' ) {
- my $patron = Koha::Patrons->find( $borrowernumber );
- return $patron->first_valid_email_address();
- }
- # specified email address field
- my $dbh = C4::Context->dbh;
- my $sth = $dbh->prepare( qq{
- SELECT $which_address AS primaryemail
- FROM borrowers
- WHERE borrowernumber=?
- } );
- $sth->execute($borrowernumber);
- my $data = $sth->fetchrow_hashref;
- return $data->{'primaryemail'} || '';
-}
-
=head2 GetBorrowersToExpunge
$borrowers = &GetBorrowersToExpunge(
my $patron = Koha::Patrons->find( $borrowernumber );
# Try to get the borrower's email address
- my $to_address = C4::Members::GetNoticeEmailAddress($borrowernumber);
+ my $to_address = $patron->notice_email_address;
my $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( {
borrowernumber => $borrowernumber,
return Koha::Old::Holds->_new_from_dbic($old_holds_rs);
}
+=head3 notice_email_address
+
+ my $email = $patron->notice_email_address;
+
+Return the email address of patron used for notices.
+Returns the empty string if no email address.
+
+=cut
+
+sub notice_email_address{
+ my ( $self ) = @_;
+
+ my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
+ # if syspref is set to 'first valid' (value == OFF), look up email address
+ if ( $which_address eq 'OFF' ) {
+ return $self->first_valid_email_address;
+ }
+
+ return $self->$which_address || '';
+}
+
=head3 first_valid_email_address
my $first_valid_email_address = $patron->first_valid_email_address
my $budget = C4::Budgets::GetBudget( $suggestion->{budgetid} );
my $patron = Koha::Patrons->find( $budget->{budget_owner_id} );
- my $email_address =
- C4::Members::GetNoticeEmailAddress( $budget->{budget_owner_id} );
+ my $email_address = $patron->notice_email_address;
my $library = $patron->library;
my $admin_email_address = $library->branchemail
|| C4::Context->preference('KohaAdminEmailAddress');
use Koha::Calendar;
use Koha::Libraries;
use Koha::Acquisition::Currencies;
+use Koha::Patrons;
=head1 NAME
$verbose
and warn "borrower $borr has items triggering level $i.";
+ my $patron = Koha::Patrons->find( $borrowernumber );
@emails_to_use = ();
- my $notice_email =
- C4::Members::GetNoticeEmailAddress($borrowernumber);
+ my $notice_email = $patron->notice_email_address;
unless ($nomail) {
if (@emails) {
foreach (@emails) {
use C4::Members ();
use C4::Output;
+use Koha::Patrons;
use Koha::Virtualshelves;
use Koha::Virtualshelfshares;
sub notify_owner {
my ($param) = @_;
- my $toaddr = C4::Members::GetNoticeEmailAddress( $param->{owner} );
- return if !$toaddr;
-
my $patron = Koha::Patrons->find( $param->{owner} );
+ return unless $patron;
+
+ my $toaddr = $patron->notice_email_address or return;
#prepare letter
my $letter = C4::Letters::GetPreparedLetter(
use Modern::Perl;
-use Test::More tests => 22;
+use Test::More tests => 23;
use Test::Warn;
use Time::Fake;
use DateTime;
$patron->delete;
};
+subtest 'notice_email_address' => sub {
+ plan tests => 2;
+
+ my $patron = $builder->build_object({ class => 'Koha::Patrons' });
+
+ t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
+ is ($patron->notice_email_address, $patron->email, "Koha::Patron->notice_email_address returns correct value when AutoEmailPrimaryAddress is off");
+
+ t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'emailpro' );
+ is ($patron->notice_email_address, $patron->emailpro, "Koha::Patron->notice_email_address returns correct value when AutoEmailPrimaryAddress is emailpro");
+
+ $patron->delete;
+};
+
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
plan tests => 4;
is ($checkcardnum, "2", "Card number is too long");
-
-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");
-
# Check_Userid tests
%data = (
cardnumber => "123456789",