Bugzilla – Attachment 109018 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: Allow choosing an SMTP server in branches.pl
Bug-22343-Allow-choosing-an-SMTP-server-in-branche.patch (text/plain), 7.67 KB, created by
Tomás Cohen Arazi (tcohen)
on 2020-08-24 15:32:57 UTC
(
hide
)
Description:
Bug 22343: Allow choosing an SMTP server in branches.pl
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2020-08-24 15:32:57 UTC
Size:
7.67 KB
patch
obsolete
>From 4264f99b0207d56b5a0f1e7c6d221986094b6094 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Mon, 24 Aug 2020 10:48:56 -0300 >Subject: [PATCH] Bug 22343: Allow choosing an SMTP server in branches.pl > >The missing piece on this patchset is choosing the desired SMTP server >for each library. This patch adds the option on editing the library. > >The default one is picked for existing libraries, and you can pick the >one you want. > >To test: >1. Apply the patchset >2. Run: > $ updatedatabase >=> SUCCESS: Things go smooth >3. Notice the new permission for managing SMTP servers >4. Notice the entry in the admin page >5. Add/have a few SMTP servers defined. >6. Edit a library >=> SUCCESS: The 'Default' SMTP server is picked >7. Choose any server and save >=> SUCCESS: Saving doesn't explode >8. Edit the server >=> SUCCESS: Your selection is kept (this can also be checked on the DB, > the library_smtp_server table) >9. Try (7) with many different options >=> SUCCESS: It works >10. Sign off :-D >--- > admin/branches.pl | 71 ++++++++++++++++--- > .../prog/en/modules/admin/branches.tt | 16 +++++ > 2 files changed, 76 insertions(+), 11 deletions(-) > >diff --git a/admin/branches.pl b/admin/branches.pl >index b609c20d83..9ce082e45a 100755 >--- a/admin/branches.pl >+++ b/admin/branches.pl >@@ -19,16 +19,22 @@ > # along with Koha; if not, see <http://www.gnu.org/licenses>. > > use Modern::Perl; >+ > use CGI qw ( -utf8 ); >+use Try::Tiny; >+ > use C4::Auth; > use C4::Context; > use C4::Output; > use C4::Koha; >+ >+use Koha::Database; > use Koha::Patrons; > use Koha::Items; > use Koha::Libraries; >+use Koha::SMTP::Servers; > >-my $input = new CGI; >+my $input = CGI->new; > my $branchcode = $input->param('branchcode'); > my $categorycode = $input->param('categorycode'); > my $op = $input->param('op') || 'list'; >@@ -48,10 +54,14 @@ if ( $op eq 'add_form' ) { > my $library; > if ($branchcode) { > $library = Koha::Libraries->find($branchcode); >+ $template->param( selected_smtp_server => $library->smtp_server ); > } > >+ my @smtp_servers = Koha::SMTP::Servers->search; >+ > $template->param( >- library => $library, >+ library => $library, >+ smtp_servers => \@smtp_servers > ); > } elsif ( $op eq 'add_validate' ) { > my @fields = qw( >@@ -83,11 +93,32 @@ if ( $op eq 'add_form' ) { > for my $field (@fields) { > $library->$field( scalar $input->param($field) ); > } >- eval { $library->store; }; >- if ($@) { >+ >+ try { >+ Koha::Database->new->schema->txn_do( >+ sub { >+ $library->store->discard_changes; >+ # Deal with SMTP server >+ my $smtp_server_id = $input->param('smtp_server'); >+ >+ if ( $smtp_server_id ) { >+ if ( $smtp_server_id eq '*' ) { >+ $library->smtp_server({ smtp_server => undef }); >+ } >+ else { >+ my $smtp_server = Koha::SMTP::Servers->find( $smtp_server_id ); >+ Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' ) >+ unless $smtp_server; >+ $library->smtp_server({ smtp_server => $smtp_server }); >+ } >+ } >+ >+ push @messages, { type => 'message', code => 'success_on_update' }; >+ } >+ ); >+ } >+ catch { > push @messages, { type => 'alert', code => 'error_on_update' }; >- } else { >- push @messages, { type => 'message', code => 'success_on_update' }; > } > } else { > $branchcode =~ s|\s||g; >@@ -96,12 +127,30 @@ if ( $op eq 'add_form' ) { > ( map { $_ => scalar $input->param($_) || undef } @fields ) > } > ); >- eval { $library->store; }; >- if ($@) { >- push @messages, { type => 'alert', code => 'error_on_insert' }; >- } else { >- push @messages, { type => 'message', code => 'success_on_insert' }; >+ >+ try { >+ Koha::Database->new->schema->txn_do( >+ sub { >+ $library->store->discard_changes; >+ >+ my $smtp_server_id = $input->param('smtp_server'); >+ >+ if ( $smtp_server_id ) { >+ if ( $smtp_server_id ne '*' ) { >+ my $smtp_server = Koha::SMTP::Servers->find( $smtp_server_id ); >+ Koha::Exceptions::BadParameter->throw( parameter => 'smtp_server' ) >+ unless $smtp_server; >+ $library->smtp_server({ smtp_server => $smtp_server }); >+ } >+ } >+ >+ push @messages, { type => 'message', code => 'success_on_insert' }; >+ } >+ ); > } >+ catch { >+ push @messages, { type => 'alert', code => 'error_on_insert' }; >+ }; > } > $op = 'list'; > } elsif ( $op eq 'delete_confirm' ) { >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt >index bf140b2960..2d5d59ca91 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/branches.tt >@@ -141,6 +141,22 @@ > <li><label for="branchemail">Email: </label><input type="text" name="branchemail" id="branchemail" class="email" size="80" value="[% library.branchemail | html %]" /></li> > <li><label for="branchreplyto">Reply-To: </label> <input type="text" name="branchreplyto" id="branchreplyto" class="email" size="80" value="[% library.branchreplyto | html %]" /><br /><span class="hint">Default: ReplyToDefault system preference</span></li> > <li><label for="branchreturnpath">Return-Path: </label> <input type="text" name="branchreturnpath" id="branchreturnpath" class="email" size="80" value="[% library.branchreturnpath | html %]" /><br /><span class="hint">Default: ReturnpathDefault system preference</span></li> >+ <li><label for="smtp_server">SMTP server: </label> >+ <select name="smtp_server" id="smtp_server"> >+ [% IF selected_smtp_server.is_system_default %] >+ <option value="*" selected="selected">Default</option> >+ [% ELSE %] >+ <option value="*">Default</option> >+ [% END %] >+ [% FOREACH smtp_server IN smtp_servers %] >+ [% IF smtp_server.id == selected_smtp_server.id %] >+ <option value="[% smtp_server.id | html %]" selected="selected">[% smtp_server.name | html %]</option> >+ [% ELSE %] >+ <option value="[% smtp_server.id | html %]">[% smtp_server.name | html %]</option> >+ [% END %] >+ [% END %] >+ </select> >+ </li> > <li><label for="branchurl">URL: </label><input type="text" name="branchurl" id="branchurl" size="80" value="[% library.branchurl | html %]" class="url" /></li> > <li><label for="opac_info">OPAC info: </label><textarea name="opac_info" id="opac_info">[% library.opac_info | $raw %]</textarea></li> > <li><label for="branchip">IP: </label><input type="text" name="branchip" id="branchip" size="15" maxlength="15" value="[% library.branchip | html %]" /> <span class="hint">Can be entered as a single IP, or a subnet such as 192.168.1.*</span></li> >-- >2.28.0
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