View | Details | Raw Unified | Return to bug 19304
Collapse All | Expand All

(-)a/C4/Letters.pm (-1 / +1 lines)
Lines 1311-1317 sub _send_message_by_email { Link Here
1311
                                   status     => 'failed' } );
1311
                                   status     => 'failed' } );
1312
            return;
1312
            return;
1313
        }
1313
        }
1314
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
1314
        $to_address = $patron->notice_email_address;
1315
        unless ($to_address) {  
1315
        unless ($to_address) {  
1316
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1316
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1317
            # warning too verbose for this more common case?
1317
            # warning too verbose for this more common case?
(-)a/C4/Members.pm (-32 lines)
Lines 64-71 BEGIN { Link Here
64
        &GetPendingIssues
64
        &GetPendingIssues
65
        &GetAllIssues
65
        &GetAllIssues
66
66
67
        &GetNoticeEmailAddress
68
69
        &GetMemberAccountRecords
67
        &GetMemberAccountRecords
70
        &GetBorNotifyAcctRecord
68
        &GetBorNotifyAcctRecord
71
69
Lines 917-952 sub get_cardnumber_length { Link Here
917
    return ( $min, $max );
915
    return ( $min, $max );
918
}
916
}
919
917
920
=head2 GetNoticeEmailAddress
921
922
  $email = GetNoticeEmailAddress($borrowernumber);
923
924
Return the email address of borrower used for notices, given the borrowernumber.
925
Returns the empty string if no email address.
926
927
=cut
928
929
sub GetNoticeEmailAddress {
930
    my $borrowernumber = shift;
931
932
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
933
    # if syspref is set to 'first valid' (value == OFF), look up email address
934
    if ( $which_address eq 'OFF' ) {
935
        my $patron = Koha::Patrons->find( $borrowernumber );
936
        return $patron->first_valid_email_address();
937
    }
938
    # specified email address field
939
    my $dbh = C4::Context->dbh;
940
    my $sth = $dbh->prepare( qq{
941
        SELECT $which_address AS primaryemail
942
        FROM borrowers
943
        WHERE borrowernumber=?
944
    } );
945
    $sth->execute($borrowernumber);
946
    my $data = $sth->fetchrow_hashref;
947
    return $data->{'primaryemail'} || '';
948
}
949
950
=head2 GetBorrowersToExpunge
918
=head2 GetBorrowersToExpunge
951
919
952
  $borrowers = &GetBorrowersToExpunge(
920
  $borrowers = &GetBorrowersToExpunge(
(-)a/C4/Reserves.pm (-1 / +1 lines)
Lines 1641-1647 sub _koha_notify_reserve { Link Here
1641
    my $patron = Koha::Patrons->find( $borrowernumber );
1641
    my $patron = Koha::Patrons->find( $borrowernumber );
1642
1642
1643
    # Try to get the borrower's email address
1643
    # Try to get the borrower's email address
1644
    my $to_address = C4::Members::GetNoticeEmailAddress($borrowernumber);
1644
    my $to_address = $patron->notice_email_address;
1645
1645
1646
    my $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( {
1646
    my $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( {
1647
            borrowernumber => $borrowernumber,
1647
            borrowernumber => $borrowernumber,
(-)a/Koha/Patron.pm (+22 lines)
Lines 593-598 sub holds { Link Here
593
    return Koha::Holds->_new_from_dbic($holds_rs);
593
    return Koha::Holds->_new_from_dbic($holds_rs);
594
}
594
}
595
595
596
597
=head3 notice_email_address
598
599
  my $email = $patron->notice_email_address;
600
601
Return the email address of patron used for notices.
602
Returns the empty string if no email address.
603
604
=cut
605
606
sub notice_email_address{
607
    my ( $self ) = @_;
608
609
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
610
    # if syspref is set to 'first valid' (value == OFF), look up email address
611
    if ( $which_address eq 'OFF' ) {
612
        return $self->first_valid_email_address;
613
    }
614
615
    return $self->$which_address || '';
616
}
617
596
=head3 first_valid_email_address
618
=head3 first_valid_email_address
597
619
598
my $first_valid_email_address = $patron->first_valid_email_address
620
my $first_valid_email_address = $patron->first_valid_email_address
(-)a/misc/cronjobs/notice_unprocessed_suggestions.pl (-2 / +1 lines)
Lines 46-53 for my $number_of_days (@days) { Link Here
46
46
47
        my $budget = C4::Budgets::GetBudget( $suggestion->{budgetid} );
47
        my $budget = C4::Budgets::GetBudget( $suggestion->{budgetid} );
48
        my $patron = Koha::Patrons->find( $budget->{budget_owner_id} );
48
        my $patron = Koha::Patrons->find( $budget->{budget_owner_id} );
49
        my $email_address =
49
        my $email_address = $patron->notice_email_address;
50
          C4::Members::GetNoticeEmailAddress( $budget->{budget_owner_id} );
51
        my $library = $patron->library;
50
        my $library = $patron->library;
52
        my $admin_email_address = $library->branchemail
51
        my $admin_email_address = $library->branchemail
53
          || C4::Context->preference('KohaAdminEmailAddress');
52
          || C4::Context->preference('KohaAdminEmailAddress');
(-)a/misc/cronjobs/overdue_notices.pl (-2 / +3 lines)
Lines 43-48 use Koha::DateUtils; Link Here
43
use Koha::Calendar;
43
use Koha::Calendar;
44
use Koha::Libraries;
44
use Koha::Libraries;
45
use Koha::Acquisition::Currencies;
45
use Koha::Acquisition::Currencies;
46
use Koha::Patrons;
46
47
47
=head1 NAME
48
=head1 NAME
48
49
Lines 580-588 END_SQL Link Here
580
                $verbose
581
                $verbose
581
                  and warn "borrower $borr has items triggering level $i.";
582
                  and warn "borrower $borr has items triggering level $i.";
582
583
584
                my $patron = Koha::Patrons->find( $borrowernumber );
583
                @emails_to_use = ();
585
                @emails_to_use = ();
584
                my $notice_email =
586
                my $notice_email = $patron->notice_email_address;
585
                    C4::Members::GetNoticeEmailAddress($borrowernumber);
586
                unless ($nomail) {
587
                unless ($nomail) {
587
                    if (@emails) {
588
                    if (@emails) {
588
                        foreach (@emails) {
589
                        foreach (@emails) {
(-)a/opac/opac-shareshelf.pl (-3 / +4 lines)
Lines 33-38 use C4::Letters; Link Here
33
use C4::Members ();
33
use C4::Members ();
34
use C4::Output;
34
use C4::Output;
35
35
36
use Koha::Patrons;
36
use Koha::Virtualshelves;
37
use Koha::Virtualshelves;
37
use Koha::Virtualshelfshares;
38
use Koha::Virtualshelfshares;
38
39
Lines 166-175 sub show_accept { Link Here
166
sub notify_owner {
167
sub notify_owner {
167
    my ($param) = @_;
168
    my ($param) = @_;
168
169
169
    my $toaddr = C4::Members::GetNoticeEmailAddress( $param->{owner} );
170
    return if !$toaddr;
171
172
    my $patron = Koha::Patrons->find( $param->{owner} );
170
    my $patron = Koha::Patrons->find( $param->{owner} );
171
    return unless $patron;
172
173
    my $toaddr = $patron->notice_email_address or return;
173
174
174
    #prepare letter
175
    #prepare letter
175
    my $letter = C4::Letters::GetPreparedLetter(
176
    my $letter = C4::Letters::GetPreparedLetter(
(-)a/t/db_dependent/Koha/Patrons.t (-1 / +15 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 22;
22
use Test::More tests => 23;
23
use Test::Warn;
23
use Test::Warn;
24
use Time::Fake;
24
use Time::Fake;
25
use DateTime;
25
use DateTime;
Lines 677-682 subtest 'holds' => sub { Link Here
677
    $patron->delete;
677
    $patron->delete;
678
};
678
};
679
679
680
subtest 'notice_email_address' => sub {
681
    plan tests => 2;
682
683
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
684
685
    t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
686
    is ($patron->notice_email_address, $patron->email, "Koha::Patron->notice_email_address returns correct value when AutoEmailPrimaryAddress is off");
687
688
    t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'emailpro' );
689
    is ($patron->notice_email_address, $patron->emailpro, "Koha::Patron->notice_email_address returns correct value when AutoEmailPrimaryAddress is emailpro");
690
691
    $patron->delete;
692
};
693
680
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
694
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
681
    plan tests => 4;
695
    plan tests => 4;
682
696
(-)a/t/db_dependent/Members.t (-14 lines)
Lines 137-155 $checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, ""); Link Here
137
is ($checkcardnum, "2", "Card number is too long");
137
is ($checkcardnum, "2", "Card number is too long");
138
138
139
139
140
141
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
142
C4::Context->clear_syspref_cache();
143
144
my $notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
145
is ($notice_email, $EMAIL, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is off");
146
147
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'emailpro' );
148
C4::Context->clear_syspref_cache();
149
150
$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
151
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro");
152
153
# Check_Userid tests
140
# Check_Userid tests
154
%data = (
141
%data = (
155
    cardnumber   => "123456789",
142
    cardnumber   => "123456789",
156
- 

Return to bug 19304