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

(-)a/Koha/SMTP/Servers.pm (-15 / +4 lines)
Lines 48-59 sub get_effective_server { Link Here
48
    Koha::Exceptions::MissingParameter->throw('Mandatory parameter missing: library')
48
    Koha::Exceptions::MissingParameter->throw('Mandatory parameter missing: library')
49
        unless $library;
49
        unless $library;
50
50
51
    my $servers_rs = Koha::SMTP::Servers->search({ library_id => $library->branchcode });
51
    my ($server) = Koha::SMTP::Servers->search({ library_id => $library->branchcode });
52
    if ( $servers_rs->count > 0 ) {
53
        return $servers_rs->next;
54
    }
55
52
56
    return $self->get_default;
53
    return $server || $self->get_default;
57
}
54
}
58
55
59
=head3 get_default
56
=head3 get_default
Lines 67-83 Returns the default I<Koha::SMTP::Server> object. Link Here
67
sub get_default {
64
sub get_default {
68
    my ($self) = @_;
65
    my ($self) = @_;
69
66
70
    my $servers_rs = $self->search({ library_id => undef });
67
    my ( $server ) = $self->search({ library_id => undef });
71
68
72
    my $server;
69
    return $server || Koha::SMTP::Server->new( $self->default_setting );
73
    if ($servers_rs->count > 0) {
74
        $server = $servers_rs->next;
75
    }
76
    else {
77
        $server = Koha::SMTP::Server->new( $self->default_setting );
78
    }
79
80
    return $server;
81
}
70
}
82
71
83
=head3 set_default
72
=head3 set_default
(-)a/t/db_dependent/Koha/SMTP/Servers.t (-2 / +10 lines)
Lines 132-138 subtest 'set_default() tests' => sub { Link Here
132
132
133
subtest 'get_effective_server() tests' => sub {
133
subtest 'get_effective_server() tests' => sub {
134
134
135
    plan tests => 4;
135
    plan tests => 5;
136
136
137
    $schema->storage->txn_begin;
137
    $schema->storage->txn_begin;
138
138
Lines 179-184 subtest 'get_effective_server() tests' => sub { Link Here
179
        'Library specific server retrieved'
179
        'Library specific server retrieved'
180
    );
180
    );
181
181
182
    my $other_library = $builder->build_object( { class => 'Koha::Libraries' } );
183
    is(
184
        Koha::SMTP::Servers->new->get_effective_server(
185
            { library => $other_library }
186
        )->id,
187
        $default_server->id,
188
        'Fallback default server retrieved'
189
    );
190
182
    $schema->storage->txn_rollback;
191
    $schema->storage->txn_rollback;
183
};
192
};
184
193
185
- 

Return to bug 22343