Commit 9abae3a6 authored by IKEDA Soji's avatar IKEDA Soji
Browse files

Fixup: Now db_host parameter became optional.

On mysql & PostgreSQL, undefined db_host is treated as "localhost".
parent 7b3f9b96
......@@ -1319,7 +1319,7 @@ sub load_sql_filter {
'db_type' =>
{'format' => 'mysql|MySQL|Oracle|Pg|PostgreSQL|SQLite',},
'db_name' => {'format' => '.*', 'occurrence' => '1',},
'db_host' => {'format' => '.*', 'occurrence' => '1',},
'db_host' => {'format' => '.*', 'occurrence' => '0-1',},
'statement' => {'format' => '.*', 'occurrence' => '1',},
'db_user' => {'format' => '.*', 'occurrence' => '0-1',},
'db_passwd' => {'format' => '.*', 'occurrence' => '0-1',},
......
......@@ -118,13 +118,14 @@ our @params = (
'edit' => '1',
},
{ 'name' => 'db_host',
'default' => 'localhost',
#'default' => 'localhost',
'sample' => 'localhost',
'gettext_id' => 'Hostname of the database server',
'gettext_comment' =>
'With PostgreSQL, you can also use the path to Unix Socket Directory, e.g. "/var/run/postgresql" for connection with Unix domain socket.',
'file' => 'sympa.conf',
'edit' => '1',
'optional' => 1,
},
{ 'name' => 'db_port',
'default' => undef,
......
......@@ -33,10 +33,10 @@ use warnings;
use base qw(Sympa::Database);
use constant required_modules => [];
use constant required_parameters => [qw(db_host db_name db_user)];
use constant required_parameters => [qw(db_name db_user)];
use constant optional_modules => [];
use constant optional_parameters =>
[qw(db_port db_passwd db_timeout db_options db_env)];
[qw(db_host db_port db_passwd db_options db_env)];
sub translate_type {
return $_[1];
......@@ -87,7 +87,11 @@ By default, no packages are required.
I<Overridable>.
Returns an arrayref including names of required (not optional) parameters.
By default, returns C<['db_host', 'db_name', 'db_user']>.
By default, returns C<['db_name', 'db_user']>.
I<Note>:
On Sympa prior to 6.2.37b.2, it by default returned
C<['db_host', 'db_name', 'db_user']>.
=item optional_modules ( )
......
......@@ -42,7 +42,9 @@ sub build_connect_string {
my $self = shift;
my $connect_string =
'DBI:mysql:' . $self->{'db_name'} . ':' . $self->{'db_host'};
'DBI:mysql:'
. $self->{'db_name'} . ':'
. ($self->{'db_host'} || 'localhost');
$connect_string .= ';port=' . $self->{'db_port'}
if defined $self->{'db_port'};
$connect_string .= ';' . $self->{'db_options'}
......
......@@ -37,10 +37,7 @@ use base qw(Sympa::DatabaseDriver);
my $log = Sympa::Log->instance;
use constant required_modules => [qw(DBD::Oracle)];
use constant required_parameters => [qw(db_name db_user)];
use constant optional_parameters =>
[qw(db_host db_port db_passwd db_options db_env)];
use constant required_modules => [qw(DBD::Oracle)];
sub build_connect_string {
my $self = shift;
......
......@@ -43,7 +43,10 @@ sub build_connect_string {
my $self = shift;
my $connect_string =
"DBI:Pg:dbname=$self->{'db_name'};host=$self->{'db_host'}";
'DBI:Pg:dbname='
. $self->{'db_name'}
. ';host='
. ($self->{'db_host'} || 'localhost');
$connect_string .= ';port=' . $self->{'db_port'}
if defined $self->{'db_port'};
$connect_string .= ';' . $self->{'db_options'}
......
......@@ -1998,7 +1998,8 @@ our %pinfo = (
'order' => 2,
'gettext_id' => "remote host",
format_s => '$host',
'occurrence' => '1'
# Not required for ODBC and SQLite. Optional for Oracle.
#'occurrence' => '1'
},
'db_port' => {
'order' => 3,
......
......@@ -1545,12 +1545,8 @@ sub search {
%{$sql_conf->{'sql_named_filter_query'}}
);
unless ($db and $db->connect()) {
$log->syslog(
'notice',
'Unable to connect to the SQL server %s:%d',
$sql_conf->{'db_host'},
$sql_conf->{'db_port'}
);
$log->syslog('notice',
'Unable to connect to the SQL server %s', $db);
return undef;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment