Bug 33974: (QA follow-up) Remove superflous import
[koha.git] / Koha / SMTP / Servers.pm
1 package Koha::SMTP::Servers;
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Koha::Database;
21 use Koha::Exceptions;
22
23 use Koha::SMTP::Server;
24
25 use base qw(Koha::Objects);
26
27 =head1 NAME
28
29 Koha::SMTP::Servers - Koha SMTP Server Object set class
30
31 =head1 API
32
33 =head2 Class methods
34
35 =head3 get_default
36
37     my $server = Koha::SMTP::Servers->new->get_default;
38
39 Returns the default I<Koha::SMTP::Server> object.
40
41 =cut
42
43 sub get_default {
44     my ($self) = @_;
45
46     my $default = $self->search({ is_default => 1 }, { rows => 1 })->single;
47
48     unless ($default) { # no database default
49         my $smtp_config = C4::Context->config('smtp_server');
50
51         if ( $smtp_config ) { # use koha-conf.xml
52             $default = Koha::SMTP::Server->new( $smtp_config );
53         }
54         else {
55             $default = Koha::SMTP::Server->new( $self->default_setting );
56         }
57
58         $default->{_is_system_default} = 1;
59     }
60
61     return $default;
62 }
63
64 =head2 Internal methods
65
66 =head3 _type
67
68 Return type of object, relating to Schema ResultSet
69
70 =cut
71
72 sub _type {
73     return 'SmtpServer';
74 }
75
76 =head3 default_setting
77
78     my $hash = Koha::SMTP::Servers::default_setting;
79
80 Returns the default setting that is to be used when no user-defined default
81 SMTP server is provided
82
83 =cut
84
85 sub default_setting {
86     return {
87         name       => 'localhost',
88         host       => 'localhost',
89         port       => 25,
90         timeout    => 120,
91         ssl_mode  => 'disabled',
92         user_name  => undef,
93         password   => undef,
94         debug      => 0
95     };
96 }
97
98 =head3 object_class
99
100 Return object class
101
102 =cut
103
104 sub object_class {
105     return 'Koha::SMTP::Server';
106 }
107
108 1;