Bugzilla – Attachment 109728 Details for
Bug 22343
Add configuration options for SMTP servers
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 22343: Add Koha::Library->smtp_server
Bug-22343-Add-KohaLibrary-smtpserver.patch (text/plain), 5.95 KB, created by
Martin Renvoize (ashimema)
on 2020-09-08 08:51:54 UTC
(
hide
)
Description:
Bug 22343: Add Koha::Library->smtp_server
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2020-09-08 08:51:54 UTC
Size:
5.95 KB
patch
obsolete
>From ebd345b719a52124170f1d0282a3d29141acf4fc Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Sun, 23 Aug 2020 17:39:23 -0300 >Subject: [PATCH] Bug 22343: Add Koha::Library->smtp_server > >Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/Library.pm | 52 +++++++++++++++++++ > t/db_dependent/Koha/Library.t | 95 +++++++++++++++++++++++++++++++++++ > 2 files changed, 147 insertions(+) > create mode 100644 t/db_dependent/Koha/Library.t > >diff --git a/Koha/Library.pm b/Koha/Library.pm >index b3f763a9ef..7a640d7b74 100644 >--- a/Koha/Library.pm >+++ b/Koha/Library.pm >@@ -25,6 +25,7 @@ use C4::Context; > > use Koha::Database; > use Koha::StockRotationStages; >+use Koha::SMTP::Servers; > > use base qw(Koha::Object); > >@@ -65,6 +66,57 @@ sub get_effective_marcorgcode { > return $self->marcorgcode || C4::Context->preference("MARCOrgCode"); > } > >+=head3 smtp_server >+ >+ my $smtp_server = $library->smtp_server; >+ $library->smtp_server({ smtp_server => $smtp_server }); >+ $library->smtp_server({ smtp_server => undef }); >+ >+Accessor for getting and setting the library's SMTP server. >+ >+Returns the effective SMTP server configuration to be used on the library. The returned >+value is always a I<Koha::SMTP::Server> object. >+ >+Setting it to undef will remove the link to a specific SMTP server and effectively >+make the library use the default setting >+ >+=cut >+ >+sub smtp_server { >+ my ( $self, $params ) = @_; >+ >+ my $library_smtp_server_rs = $self->_result->library_smtp_server; >+ >+ if ( exists $params->{smtp_server} ) { >+ >+ $self->_result->result_source->schema->txn_do( sub { >+ $library_smtp_server_rs->delete >+ if $library_smtp_server_rs; >+ >+ if ( defined $params->{smtp_server} ) { >+ # Set the new server >+ # Remove any already set SMTP server >+ >+ my $smtp_server = $params->{smtp_server}; >+ $smtp_server->_result->add_to_library_smtp_servers({ library_id => $self->id }); >+ } >+ }); >+ } # else => reset to default >+ else { >+ # Getter >+ if ( $library_smtp_server_rs ) { >+ # use Data::Printer colored => 1; >+ # p($library_smtp_server_rs); >+ return Koha::SMTP::Servers->find( >+ $library_smtp_server_rs->smtp_server_id ); >+ } >+ >+ return Koha::SMTP::Servers->get_default; >+ } >+ >+ return $self; >+} >+ > =head3 inbound_email_address > > my $to_email = Koha::Library->inbound_email_address; >diff --git a/t/db_dependent/Koha/Library.t b/t/db_dependent/Koha/Library.t >new file mode 100644 >index 0000000000..23e88578b3 >--- /dev/null >+++ b/t/db_dependent/Koha/Library.t >@@ -0,0 +1,95 @@ >+#!/usr/bin/perl >+ >+# Copyright 2020 Koha Development team >+# >+# This file is part of Koha >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 1; >+ >+use Koha::Database; >+use Koha::SMTP::Servers; >+ >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'smtp_server() tests' => sub { >+ >+ plan tests => 14; >+ >+ $schema->storage->txn_begin; >+ >+ my $library = $builder->build_object({ class => 'Koha::Libraries' }); >+ my $smtp_server_1 = $builder->build_object({ class => 'Koha::SMTP::Servers' }); >+ my $smtp_server_2 = $builder->build_object({ class => 'Koha::SMTP::Servers' }); >+ >+ is( ref($library->smtp_server), 'Koha::SMTP::Server', 'Type is correct' ); >+ >+ is_deeply( >+ $library->smtp_server->unblessed, >+ Koha::SMTP::Servers->get_default->unblessed, >+ 'Fresh library is set the default' >+ ); >+ >+ my $return = $library->smtp_server({ smtp_server => $smtp_server_1 }); >+ $library->discard_changes; >+ >+ is( ref($return), 'Koha::Library', 'The setter is chainable' ); >+ is( ref($library->smtp_server), 'Koha::SMTP::Server', 'Type is correct' ); >+ is_deeply( >+ $library->smtp_server->unblessed, >+ $smtp_server_1->unblessed, >+ 'SMTP server correctly set for library' >+ ); >+ >+ $return = $library->smtp_server({ smtp_server => $smtp_server_2 }); >+ $library->discard_changes; >+ >+ is( ref($return), 'Koha::Library', 'The setter is chainable' ); >+ is( ref($library->smtp_server), 'Koha::SMTP::Server', 'Type is correct' ); >+ is_deeply( >+ $library->smtp_server->unblessed, >+ $smtp_server_2->unblessed, >+ 'SMTP server correctly set for library' >+ ); >+ >+ $return = $library->smtp_server({ smtp_server => undef }); >+ $library->discard_changes; >+ >+ is( ref($return), 'Koha::Library', 'The setter is chainable' ); >+ is( ref($library->smtp_server), 'Koha::SMTP::Server', 'Type is correct' ); >+ is_deeply( >+ $library->smtp_server->unblessed, >+ Koha::SMTP::Servers->get_default->unblessed, >+ 'Resetting makes it return the default' >+ ); >+ >+ $return = $library->smtp_server({ smtp_server => undef }); >+ $library->discard_changes; >+ >+ is( ref($return), 'Koha::Library', 'The setter is chainable' ); >+ is( ref($library->smtp_server), 'Koha::SMTP::Server', 'Type is correct' ); >+ is_deeply( >+ $library->smtp_server->unblessed, >+ Koha::SMTP::Servers->get_default->unblessed, >+ q{Resetting twice doesn't explode and has the expected results} >+ ); >+ >+ $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 22343
:
107598
|
107599
|
107600
|
107601
|
107602
|
107603
|
107604
|
107605
|
107987
|
107988
|
107989
|
107990
|
107991
|
107992
|
107993
|
107994
|
107995
|
107996
|
107997
|
107998
|
107999
|
108009
|
108107
|
108108
|
108109
|
108110
|
108111
|
108112
|
108113
|
108114
|
108115
|
108116
|
108117
|
108118
|
108119
|
108131
|
108132
|
108133
|
108134
|
108135
|
108136
|
108137
|
108138
|
108139
|
108140
|
108141
|
108142
|
108143
|
108529
|
108537
|
108538
|
108539
|
108540
|
108541
|
108542
|
108543
|
108544
|
108545
|
108546
|
108547
|
108548
|
108549
|
108609
|
108638
|
108642
|
108643
|
108644
|
108645
|
108646
|
108647
|
108648
|
108649
|
108650
|
108651
|
108652
|
108653
|
108654
|
108655
|
108656
|
108715
|
108716
|
109003
|
109004
|
109005
|
109006
|
109007
|
109008
|
109009
|
109010
|
109011
|
109012
|
109013
|
109014
|
109015
|
109016
|
109017
|
109018
|
109155
|
109156
|
109157
|
109158
|
109159
|
109160
|
109161
|
109162
|
109163
|
109164
|
109165
|
109166
|
109167
|
109168
|
109169
|
109170
|
109601
|
109602
|
109603
|
109604
|
109605
|
109606
|
109607
|
109608
|
109609
|
109610
|
109611
|
109612
|
109613
|
109614
|
109615
|
109616
|
109723
|
109724
|
109725
|
109726
|
109727
| 109728 |
109729
|
109730
|
109731
|
109732
|
109733
|
109734
|
109735
|
109736
|
109737
|
109738
|
109739
|
109740
|
109787
|
109788
|
111048
|
111087
|
111088
|
111089
|
111090
|
111154
|
111165
|
111166
|
111175
|
111176
|
111213
|
111215
|
111216
|
111442
|
111482
|
113240
|
113827
|
113847