|
Lines 52-59
if ( $op eq 'add' ) {
Link Here
|
| 52 |
my $user_name = $input->param('smtp_user_name') || undef; |
52 |
my $user_name = $input->param('smtp_user_name') || undef; |
| 53 |
my $password = $input->param('smtp_password') || undef; |
53 |
my $password = $input->param('smtp_password') || undef; |
| 54 |
my $debug = ( scalar $input->param('smtp_debug_mode') ) ? 1 : 0; |
54 |
my $debug = ( scalar $input->param('smtp_debug_mode') ) ? 1 : 0; |
|
|
55 |
my $is_default = ( scalar $input->param('smtp_default') ) ? 1 : 0; |
| 55 |
|
56 |
|
|
|
57 |
my $schema = Koha::Database->new->schema; |
| 56 |
try { |
58 |
try { |
|
|
59 |
$schema->storage->txn_begin; |
| 60 |
|
| 61 |
Koha::SMTP::Servers->search->update({ is_default => 0 }) if $is_default; |
| 62 |
|
| 57 |
Koha::SMTP::Server->new( |
63 |
Koha::SMTP::Server->new( |
| 58 |
{ |
64 |
{ |
| 59 |
name => $name, |
65 |
name => $name, |
|
Lines 64-75
if ( $op eq 'add' ) {
Link Here
|
| 64 |
user_name => $user_name, |
70 |
user_name => $user_name, |
| 65 |
password => $password, |
71 |
password => $password, |
| 66 |
debug => $debug, |
72 |
debug => $debug, |
|
|
73 |
is_default => $is_default, |
| 67 |
} |
74 |
} |
| 68 |
)->store; |
75 |
)->store; |
| 69 |
|
76 |
|
| 70 |
push @messages, { type => 'message', code => 'success_on_insert' }; |
77 |
push @messages, { type => 'message', code => 'success_on_insert' }; |
|
|
78 |
$schema->storage->txn_commit; |
| 71 |
} |
79 |
} |
| 72 |
catch { |
80 |
catch { |
|
|
81 |
$schema->storage->txn_rollback; |
| 73 |
if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) { |
82 |
if ( blessed $_ and $_->isa('Koha::Exceptions::Object::DuplicateID') ) { |
| 74 |
push @messages, |
83 |
push @messages, |
| 75 |
{ |
84 |
{ |
|
Lines 122-142
elsif ( $op eq 'edit_save' ) {
Link Here
|
| 122 |
my $user_name = $input->param('smtp_user_name') || undef; |
131 |
my $user_name = $input->param('smtp_user_name') || undef; |
| 123 |
my $password = $input->param('smtp_password') || undef; |
132 |
my $password = $input->param('smtp_password') || undef; |
| 124 |
my $debug = ( scalar $input->param('smtp_debug_mode') ) ? 1 : 0; |
133 |
my $debug = ( scalar $input->param('smtp_debug_mode') ) ? 1 : 0; |
|
|
134 |
my $is_default = ( scalar $input->param('smtp_default') ) ? 1 : 0; |
| 135 |
|
| 136 |
my $schema = Koha::Database->new->schema; |
| 125 |
|
137 |
|
| 126 |
try { |
138 |
try { |
|
|
139 |
$schema->storage->txn_begin; |
| 140 |
|
| 141 |
Koha::SMTP::Servers->search->update({ is_default => 0 }) if $is_default; |
| 142 |
|
| 127 |
$smtp_server->password( $password ) |
143 |
$smtp_server->password( $password ) |
| 128 |
if defined $password and $password ne '****' |
144 |
if defined $password and $password ne '****' |
| 129 |
or not defined $password; |
145 |
or not defined $password; |
| 130 |
|
146 |
|
| 131 |
$smtp_server->set( |
147 |
$smtp_server->set( |
| 132 |
{ |
148 |
{ |
| 133 |
name => $name, |
149 |
name => $name, |
| 134 |
host => $host, |
150 |
host => $host, |
| 135 |
port => $port, |
151 |
port => $port, |
| 136 |
timeout => $timeout, |
152 |
timeout => $timeout, |
| 137 |
ssl_mode => $ssl_mode, |
153 |
ssl_mode => $ssl_mode, |
| 138 |
user_name => $user_name, |
154 |
user_name => $user_name, |
| 139 |
debug => $debug |
155 |
debug => $debug, |
|
|
156 |
is_default => $is_default, |
| 140 |
} |
157 |
} |
| 141 |
)->store; |
158 |
)->store; |
| 142 |
|
159 |
|
|
Lines 145-152
elsif ( $op eq 'edit_save' ) {
Link Here
|
| 145 |
type => 'message', |
162 |
type => 'message', |
| 146 |
code => 'success_on_update' |
163 |
code => 'success_on_update' |
| 147 |
}; |
164 |
}; |
|
|
165 |
$schema->storage->txn_commit; |
| 148 |
} |
166 |
} |
| 149 |
catch { |
167 |
catch { |
|
|
168 |
$schema->storage->txn_rollback; |
| 150 |
push @messages, |
169 |
push @messages, |
| 151 |
{ |
170 |
{ |
| 152 |
type => 'alert', |
171 |
type => 'alert', |