From 458f615f342a560be0219278f14efc72b8414004 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 20 Aug 2020 11:31:41 +0200 Subject: [PATCH] Bug 22343: Trivial code simplification --- Koha/SMTP/Servers.pm | 19 ++++--------------- t/db_dependent/Koha/SMTP/Servers.t | 11 ++++++++++- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Koha/SMTP/Servers.pm b/Koha/SMTP/Servers.pm index eee40e4e11..de18b31528 100644 --- a/Koha/SMTP/Servers.pm +++ b/Koha/SMTP/Servers.pm @@ -48,12 +48,9 @@ sub get_effective_server { Koha::Exceptions::MissingParameter->throw('Mandatory parameter missing: library') unless $library; - my $servers_rs = Koha::SMTP::Servers->search({ library_id => $library->branchcode }); - if ( $servers_rs->count > 0 ) { - return $servers_rs->next; - } + my ($server) = Koha::SMTP::Servers->search({ library_id => $library->branchcode }); - return $self->get_default; + return $server || $self->get_default; } =head3 get_default @@ -67,17 +64,9 @@ Returns the default I object. sub get_default { my ($self) = @_; - my $servers_rs = $self->search({ library_id => undef }); + my ( $server ) = $self->search({ library_id => undef }); - my $server; - if ($servers_rs->count > 0) { - $server = $servers_rs->next; - } - else { - $server = Koha::SMTP::Server->new( $self->default_setting ); - } - - return $server; + return $server || Koha::SMTP::Server->new( $self->default_setting ); } =head3 set_default diff --git a/t/db_dependent/Koha/SMTP/Servers.t b/t/db_dependent/Koha/SMTP/Servers.t index f306178f73..404026ca4a 100644 --- a/t/db_dependent/Koha/SMTP/Servers.t +++ b/t/db_dependent/Koha/SMTP/Servers.t @@ -132,7 +132,7 @@ subtest 'set_default() tests' => sub { subtest 'get_effective_server() tests' => sub { - plan tests => 4; + plan tests => 5; $schema->storage->txn_begin; @@ -179,6 +179,15 @@ subtest 'get_effective_server() tests' => sub { 'Library specific server retrieved' ); + my $other_library = $builder->build_object( { class => 'Koha::Libraries' } ); + is( + Koha::SMTP::Servers->new->get_effective_server( + { library => $other_library } + )->id, + $default_server->id, + 'Fallback default server retrieved' + ); + $schema->storage->txn_rollback; }; -- 2.20.1