Bugzilla – Attachment 130303 Details for
Bug 27424
One should be able to assign an SMTP server as the default
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27424: (QA follow-up) Make Koha::SMTP::Server->store deal with defaults
Bug-27424-QA-follow-up-Make-KohaSMTPServer-store-d.patch (text/plain), 4.84 KB, created by
Martin Renvoize (ashimema)
on 2022-02-08 15:53:06 UTC
(
hide
)
Description:
Bug 27424: (QA follow-up) Make Koha::SMTP::Server->store deal with defaults
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2022-02-08 15:53:06 UTC
Size:
4.84 KB
patch
obsolete
>From e62cb3287d79a8d6f90f90ae9a34b6a7704e2e23 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Fri, 4 Feb 2022 14:24:18 -0300 >Subject: [PATCH] Bug 27424: (QA follow-up) Make Koha::SMTP::Server->store deal > with defaults > >This patch makes the ->store method take care of setting the server as >the only default one. > >To test: >1. Apply this patch >2. Run: > $ kshell > k$ prove t/db_dependent/Koha/SMTP/Server.t >=> SUCCESS: Tests pass! >3. The UI keeps working as it should. >4. Sign off :-D > >Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/SMTP/Server.pm | 24 +++++++++++++++++++++++ > admin/smtp_servers.pl | 13 ------------- > t/db_dependent/Koha/SMTP/Server.t | 32 ++++++++++++++++++++++++++++++- > 3 files changed, 55 insertions(+), 14 deletions(-) > >diff --git a/Koha/SMTP/Server.pm b/Koha/SMTP/Server.pm >index 7a2a40cb18..b08bb5ebe1 100644 >--- a/Koha/SMTP/Server.pm >+++ b/Koha/SMTP/Server.pm >@@ -33,6 +33,30 @@ Koha::SMTP::Server - Koha SMTP Server Object class > > =head2 Class methods > >+=head3 store >+ >+ $server->store; >+ >+Overloaded store method. >+ >+=cut >+ >+sub store { >+ my ($self) = @_; >+ >+ $self->_result->result_source->schema->txn_do( >+ sub { >+ Koha::SMTP::Servers->search->update( { is_default => 0 }, >+ { no_triggers => 1 } ) >+ if $self->is_default; >+ >+ $self = $self->SUPER::store; >+ } >+ ); >+ >+ return $self; >+} >+ > =head3 transport > > my $transport = $smtp_server->transport; >diff --git a/admin/smtp_servers.pl b/admin/smtp_servers.pl >index ccad8e95ff..cd76cc5ff5 100755 >--- a/admin/smtp_servers.pl >+++ b/admin/smtp_servers.pl >@@ -54,11 +54,7 @@ if ( $op eq 'add' ) { > my $debug = ( scalar $input->param('smtp_debug_mode') ) ? 1 : 0; > my $is_default = ( scalar $input->param('smtp_default') ) ? 1 : 0; > >- my $schema = Koha::Database->new->schema; > try { >- $schema->storage->txn_begin; >- >- Koha::SMTP::Servers->search->update({ is_default => 0 }) if $is_default; > > Koha::SMTP::Server->new( > { >@@ -75,10 +71,8 @@ if ( $op eq 'add' ) { > )->store; > > push @messages, { type => 'message', code => 'success_on_insert' }; >- $schema->storage->txn_commit; > } > catch { >- $schema->storage->txn_rollback; > if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) { > push @messages, > { >@@ -133,12 +127,7 @@ elsif ( $op eq 'edit_save' ) { > my $debug = ( scalar $input->param('smtp_debug_mode') ) ? 1 : 0; > my $is_default = ( scalar $input->param('smtp_default') ) ? 1 : 0; > >- my $schema = Koha::Database->new->schema; >- > try { >- $schema->storage->txn_begin; >- >- Koha::SMTP::Servers->search->update({ is_default => 0 }) if $is_default; > > $smtp_server->password( $password ) > if defined $password and $password ne '****' >@@ -162,10 +151,8 @@ elsif ( $op eq 'edit_save' ) { > type => 'message', > code => 'success_on_update' > }; >- $schema->storage->txn_commit; > } > catch { >- $schema->storage->txn_rollback; > push @messages, > { > type => 'alert', >diff --git a/t/db_dependent/Koha/SMTP/Server.t b/t/db_dependent/Koha/SMTP/Server.t >index c8922177dd..5ca2488455 100755 >--- a/t/db_dependent/Koha/SMTP/Server.t >+++ b/t/db_dependent/Koha/SMTP/Server.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 3; >+use Test::More tests => 4; > use Test::Exception; > use Test::Warn; > >@@ -104,3 +104,33 @@ subtest 'to_api() tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'store() tests' => sub { >+ >+ plan tests => 4; >+ >+ $schema->storage->txn_begin; >+ >+ Koha::SMTP::Servers->search->delete; >+ >+ my $server_1 = $builder->build_object( >+ { class => 'Koha::SMTP::Servers', value => { is_default => 0 } } ); >+ my $server_2 = $builder->build_object( >+ { class => 'Koha::SMTP::Servers', value => { is_default => 0 } } ); >+ my $server_3 = $builder->build_object( >+ { class => 'Koha::SMTP::Servers', value => { is_default => 1 } } ); >+ >+ my $default_servers = Koha::SMTP::Servers->search( { is_default => 1 } ); >+ >+ is( $default_servers->count, 1, 'Only one default server' ); >+ is( $default_servers->next->id, $server_3->id, 'Server 3 is the default' ); >+ >+ $server_1->set( { is_default => 1 } )->store->discard_changes; >+ >+ $default_servers = Koha::SMTP::Servers->search( { is_default => 1 } ); >+ >+ is( $default_servers->count, 1, 'Only one default server' ); >+ is( $default_servers->next->id, $server_1->id, 'Server 1 is the default' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.20.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27424
:
129673
|
129674
|
129675
|
129814
|
130168
|
130169
|
130170
|
130171
|
130172
|
130300
|
130301
|
130302
|
130303
|
130304
|
145697
|
145698
|
145699
|
145700
|
145701
|
145702
|
145705
|
145723
|
145724
|
145725
|
152192