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

(-)a/C4/Letters.pm (-9 / +7 lines)
Lines 40-46 use Koha::Patrons; Link Here
40
use Koha::SMS::Providers;
40
use Koha::SMS::Providers;
41
use Koha::SMTP::Servers;
41
use Koha::SMTP::Servers;
42
use Koha::Subscriptions;
42
use Koha::Subscriptions;
43
use Data::Dumper;
44
43
45
use constant SERIALIZED_EMAIL_CONTENT_TYPE => 'message/rfc822';
44
use constant SERIALIZED_EMAIL_CONTENT_TYPE => 'message/rfc822';
46
45
Lines 1324-1330 sub _send_message_by_email { Link Here
1324
    my @guarantor_address;
1323
    my @guarantor_address;
1325
    my $count_guarantor_address;
1324
    my $count_guarantor_address;
1326
    if (C4::Context->preference('RedirectGuaranteeEmail') eq 'yes' && $patron) {
1325
    if (C4::Context->preference('RedirectGuaranteeEmail') eq 'yes' && $patron) {
1327
        #Get guanrantor adresses
1326
        #Get guanrantor addresses
1328
        my $guarantor_relationships = $patron->guarantor_relationships;
1327
        my $guarantor_relationships = $patron->guarantor_relationships;
1329
        my @guarantors              = $guarantor_relationships->guarantors->as_list;
1328
        my @guarantors              = $guarantor_relationships->guarantors->as_list;
1330
        foreach my $guarantor (@guarantors) {
1329
        foreach my $guarantor (@guarantors) {
Lines 1334-1340 sub _send_message_by_email { Link Here
1334
        $count_guarantor_address = scalar @guarantor_address;
1333
        $count_guarantor_address = scalar @guarantor_address;
1335
    }
1334
    }
1336
    unless ($to_address) {
1335
    unless ($to_address) {
1337
        if (!$patron && !$count_guarantor_address) {
1336
        if (!$patron) {
1338
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1337
            warn "FAIL: No 'to_address' and INVALID borrowernumber ($message->{borrowernumber})";
1339
            _set_message_status(
1338
            _set_message_status(
1340
                {
1339
                {
Lines 1349-1356 sub _send_message_by_email { Link Here
1349
            $to_address = $patron->notice_email_address;
1348
            $to_address = $patron->notice_email_address;
1350
        }
1349
        }
1351
        if (!$to_address && !$count_guarantor_address) {
1350
        if (!$to_address && !$count_guarantor_address) {
1352
            # warn "FAIL: No 'to_address' and no email for " . ($member->{surname} ||'') . ", borrowernumber ($message->{borrowernumber})";
1351
            warn "FAIL: No 'to_address', email address or guantors email address for borrowernumber ($message->{borrowernumber})";
1353
            # warning too verbose for this more common case?
1354
            _set_message_status(
1352
            _set_message_status(
1355
                {
1353
                {
1356
                    message_id   => $message->{'message_id'},
1354
                    message_id   => $message->{'message_id'},
Lines 1360-1366 sub _send_message_by_email { Link Here
1360
            );
1358
            );
1361
            return;
1359
            return;
1362
        }
1360
        }
1363
        if (!$to_address && $count_guarantor_address) {
1361
        if ( !$to_address && $count_guarantor_address ) {
1364
            $to_address = shift @guarantor_address;
1362
            $to_address = shift @guarantor_address;
1365
        }
1363
        }
1366
    }
1364
    }
Lines 1494-1502 sub _send_message_by_email { Link Here
1494
    $smtp_transports->{ $smtp_server->id // 'default' } ||= $smtp_server->transport;
1492
    $smtp_transports->{ $smtp_server->id // 'default' } ||= $smtp_server->transport;
1495
    my $smtp_transport = $smtp_transports->{ $smtp_server->id // 'default' };
1493
    my $smtp_transport = $smtp_transports->{ $smtp_server->id // 'default' };
1496
1494
1497
    _update_message_from_address($message->{'message_id'},$email->email->header('From') )
1495
    _update_message_from_address( $message->{'message_id'}, $email->email->header('From') )
1498
      if !$message->{from_address}
1496
        if !$message->{from_address}
1499
      || $message->{from_address} ne $email->email->header('From');
1497
        || $message->{from_address} ne $email->email->header('From');
1500
1498
1501
    try {
1499
    try {
1502
        $email->send_or_die({ transport => $smtp_transport });
1500
        $email->send_or_die({ transport => $smtp_transport });
(-)a/installer/data/mysql/atomicupdate/bug_12532-RedirectGuaranteeEmail_syspref.pl (-5 / +10 lines)
Lines 1-14 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
return {
3
return {
4
    bug_number => "12532",
4
    bug_number  => "12532",
5
    description => "Add new system preference RedirectGuaranteeEmail",
5
    description => "Add new system preference RedirectGuaranteeEmail",
6
    up => sub {
6
    up          => sub {
7
        my ($args) = @_;
7
        my ($args) = @_;
8
        my ($dbh, $out) = @$args{qw(dbh out)};
8
        my ( $dbh, $out ) = @$args{qw(dbh out)};
9
9
10
        $dbh->do(q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('RedirectGuaranteeEmail', '0', 'Enable the ability to redirect guarantee email messages to guarantor.', NULL, 'YesNo') });
10
        $dbh->do(
11
            q{
12
            INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type)
13
            VALUES ('RedirectGuaranteeEmail', '0', 'Enable the ability to redirect guarantee email messages to guarantor.', NULL, 'YesNo')
14
        }
15
        );
11
16
12
        say $out "Added system preference 'RedirectGuaranteeEmail'";
17
        say $out "Added system preference 'RedirectGuaranteeEmail'";
13
    },
18
    },
14
};
19
};
(-)a/t/db_dependent/Letters.t (-2 / +1 lines)
Lines 869-875 subtest 'Test SMS handling in SendQueuedMessages' => sub { Link Here
869
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
869
    t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
870
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', '');
870
    t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', '');
871
871
872
    t::lib::Mocks::mock_preference('RedirectGuaranteeEmail', '0');
872
    t::lib::Mocks::mock_preference( 'RedirectGuaranteeEmail', '0' );
873
    my $patron = Koha::Patrons->find($borrowernumber);
873
    my $patron = Koha::Patrons->find($borrowernumber);
874
    $dbh->do(q|
874
    $dbh->do(q|
875
        INSERT INTO message_queue(borrowernumber, subject, content, message_transport_type, status, letter_code)
875
        INSERT INTO message_queue(borrowernumber, subject, content, message_transport_type, status, letter_code)
876
- 

Return to bug 12532