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

(-)a/C4/Letters.pm (-1 / +1 lines)
Lines 1312-1318 sub _send_message_by_email { Link Here
1312
                                   status     => 'failed' } );
1312
                                   status     => 'failed' } );
1313
            return;
1313
            return;
1314
        }
1314
        }
1315
        $to_address = C4::Members::GetNoticeEmailAddress( $message->{'borrowernumber'} );
1315
        $to_address = $patron->notice_email_address;
1316
        unless ($to_address) {  
1316
        unless ($to_address) {  
1317
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1317
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1318
            # warning too verbose for this more common case?
1318
            # 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
68
71
        &GetBorrowersToExpunge
69
        &GetBorrowersToExpunge
Lines 878-913 sub get_cardnumber_length { Link Here
878
    return ( $min, $max );
876
    return ( $min, $max );
879
}
877
}
880
878
881
=head2 GetNoticeEmailAddress
882
883
  $email = GetNoticeEmailAddress($borrowernumber);
884
885
Return the email address of borrower used for notices, given the borrowernumber.
886
Returns the empty string if no email address.
887
888
=cut
889
890
sub GetNoticeEmailAddress {
891
    my $borrowernumber = shift;
892
893
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
894
    # if syspref is set to 'first valid' (value == OFF), look up email address
895
    if ( $which_address eq 'OFF' ) {
896
        my $patron = Koha::Patrons->find( $borrowernumber );
897
        return $patron->first_valid_email_address();
898
    }
899
    # specified email address field
900
    my $dbh = C4::Context->dbh;
901
    my $sth = $dbh->prepare( qq{
902
        SELECT $which_address AS primaryemail
903
        FROM borrowers
904
        WHERE borrowernumber=?
905
    } );
906
    $sth->execute($borrowernumber);
907
    my $data = $sth->fetchrow_hashref;
908
    return $data->{'primaryemail'} || '';
909
}
910
911
=head2 GetBorrowersToExpunge
879
=head2 GetBorrowersToExpunge
912
880
913
  $borrowers = &GetBorrowersToExpunge(
881
  $borrowers = &GetBorrowersToExpunge(
(-)a/C4/Reserves.pm (-1 / +1 lines)
Lines 1611-1617 sub _koha_notify_reserve { Link Here
1611
    my $patron = Koha::Patrons->find( $borrowernumber );
1611
    my $patron = Koha::Patrons->find( $borrowernumber );
1612
1612
1613
    # Try to get the borrower's email address
1613
    # Try to get the borrower's email address
1614
    my $to_address = C4::Members::GetNoticeEmailAddress($borrowernumber);
1614
    my $to_address = $patron->notice_email_address;
1615
1615
1616
    my $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( {
1616
    my $messagingprefs = C4::Members::Messaging::GetMessagingPreferences( {
1617
            borrowernumber => $borrowernumber,
1617
            borrowernumber => $borrowernumber,
(-)a/Koha/Patron.pm (+21 lines)
Lines 619-624 sub old_holds { Link Here
619
    return Koha::Old::Holds->_new_from_dbic($old_holds_rs);
619
    return Koha::Old::Holds->_new_from_dbic($old_holds_rs);
620
}
620
}
621
621
622
=head3 notice_email_address
623
624
  my $email = $patron->notice_email_address;
625
626
Return the email address of patron used for notices.
627
Returns the empty string if no email address.
628
629
=cut
630
631
sub notice_email_address{
632
    my ( $self ) = @_;
633
634
    my $which_address = C4::Context->preference("AutoEmailPrimaryAddress");
635
    # if syspref is set to 'first valid' (value == OFF), look up email address
636
    if ( $which_address eq 'OFF' ) {
637
        return $self->first_valid_email_address;
638
    }
639
640
    return $self->$which_address || '';
641
}
642
622
=head3 first_valid_email_address
643
=head3 first_valid_email_address
623
644
624
my $first_valid_email_address = $patron->first_valid_email_address
645
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 705-710 subtest 'holds and old_holds' => sub { Link Here
705
    $patron->delete;
705
    $patron->delete;
706
};
706
};
707
707
708
subtest 'notice_email_address' => sub {
709
    plan tests => 2;
710
711
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
712
713
    t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
714
    is ($patron->notice_email_address, $patron->email, "Koha::Patron->notice_email_address returns correct value when AutoEmailPrimaryAddress is off");
715
716
    t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'emailpro' );
717
    is ($patron->notice_email_address, $patron->emailpro, "Koha::Patron->notice_email_address returns correct value when AutoEmailPrimaryAddress is emailpro");
718
719
    $patron->delete;
720
};
721
708
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
722
subtest 'search_patrons_to_anonymise & anonymise_issue_history' => sub {
709
    plan tests => 4;
723
    plan tests => 4;
710
724
(-)a/t/db_dependent/Members.t (-14 lines)
Lines 139-157 $checkcardnum=C4::Members::checkcardnumber($IMPOSSIBLE_CARDNUMBER, ""); Link Here
139
is ($checkcardnum, "2", "Card number is too long");
139
is ($checkcardnum, "2", "Card number is too long");
140
140
141
141
142
143
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'OFF' );
144
C4::Context->clear_syspref_cache();
145
146
my $notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
147
is ($notice_email, $EMAIL, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is off");
148
149
t::lib::Mocks::mock_preference( 'AutoEmailPrimaryAddress', 'emailpro' );
150
C4::Context->clear_syspref_cache();
151
152
$notice_email = GetNoticeEmailAddress($member->{'borrowernumber'});
153
is ($notice_email, $EMAILPRO, "GetNoticeEmailAddress returns correct value when AutoEmailPrimaryAddress is emailpro");
154
155
# Check_Userid tests
142
# Check_Userid tests
156
%data = (
143
%data = (
157
    cardnumber   => "123456789",
144
    cardnumber   => "123456789",
158
- 

Return to bug 19304