Skip to content

Commit

Permalink
Deprecated the feature to save config into database.
Browse files Browse the repository at this point in the history
It turned out that this feature has been used only for CSS colors
(Though there was a function to import config into db, they did never
override info in config except CSS colors).
  • Loading branch information
ikedas committed Oct 7, 2022
1 parent 6756da7 commit 10d163c
Show file tree
Hide file tree
Showing 13 changed files with 356 additions and 313 deletions.
29 changes: 15 additions & 14 deletions doc/sympa_config.podpl
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,7 @@ foreach my $key (_keys($pinfo)) {
my $pii = $pinfo->{$key};
my $ppi = [$key];

if ($key eq 'color_0') {
$parameters .= "=head3 C<color_0>, ..., C<color_15>\n\n";
} elsif ($key =~ /\Acolor_/) {
next;
} elsif ($key eq 'dark_color') {
$parameters .=
"=head3 C<dark_color>, C<light_color>, C<text_color>, C<bg_color>, C<error_color>, C<selected_color>, C<shaded_color>\n\n";
} elsif ($key =~ /_color\z/) {
next;
} elsif ($key eq 'main_menu_custom_button_1_title') {
if ($key eq 'main_menu_custom_button_1_title') {
$parameters .=
"=head3 C<main_menu_custom_button_1_title>, ... C<main_menu_custom_button_3_title>, C<main_menu_custom_button_1_url>, ... C<main_menu_custom_button_3_url>, C<main_menu_custom_button_1_target>, ... C<main_menu_custom_button_3_target>\n\n";
} elsif ($key =~ /\Amain_menu_custom_button_/) {
Expand Down Expand Up @@ -97,7 +88,19 @@ foreach my $okey (
my $pii = $pinfo->{$okey};
my $ppi = [$okey];

$parameters .= sprintf "=head3 C<%s>\n\n", _escape_pod($okey);
if ($okey eq 'color_0') {
$parameters .= "=head3 C<color_0>, ..., C<color_15>\n\n";
$parameters .= "See description on web interface.\n";
} elsif ($okey eq 'dark_color') {
$parameters .= "=head3 C<dark_color>, C<light_color>,\n";
$parameters .= "C<text_color>, C<bg_color>, C<error_color>,\n";
$parameters .= "C<selected_color>, C<shaded_color>\n\n";
$parameters .= "See description on web interface.\n";
} elsif ($okey =~ /\Acolor_/ or $okey =~ /_color\z/) {
next;
} else {
$parameters .= sprintf "=head3 C<%s>\n\n", _escape_pod($okey);
}
_render($pii, $ppi);
}
}
Expand Down Expand Up @@ -314,9 +317,7 @@ sub _default {
my $fullname = join '.', @$pnames;

$parameters .= "=item Default:\n\n";
if ($fullname =~ /\Acolor_/ or $fullname =~ /_color\z/) {
$parameters .= "See description on web interface.\n\n";
} elsif (exists $pinfo->{default}) {
if (exists $pinfo->{default}) {
if (exists $pinfo->{default_s}) {
my $default = $pinfo->{default_s};
$parameters .= sprintf "C<%s>\n\n", $default;
Expand Down
2 changes: 1 addition & 1 deletion src/bin/upgrade_bulk_spool.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ if ($options{'help'}) {
my $log = Sympa::Log->instance;

# Load sympa.conf
unless (Conf::load(Conf::get_sympa_conf(), 'no_db')) {
unless (Conf::load(Conf::get_sympa_conf())) {
die sprintf
'Unable to load Sympa configuration, file %s or one of the virtual host robot.conf files contain errors. Exiting',
Conf::get_sympa_conf();
Expand Down
2 changes: 1 addition & 1 deletion src/bin/upgrade_send_spool.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ if ($options{'help'}) {

my $log = Sympa::Log->instance;

unless (Conf::load(Conf::get_sympa_conf(), 'no_db')) {
unless (Conf::load(Conf::get_sympa_conf())) {
die sprintf 'Configuration file %s has errors.\n', Conf::get_sympa_conf();
}

Expand Down
2 changes: 1 addition & 1 deletion src/bin/upgrade_shared_repository.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ if ($options{'help'}) {
my $language = Sympa::Language->instance;
my $log = Sympa::Log->instance;

unless (Conf::load(Conf::get_sympa_conf(), 'no_db')) {
unless (Conf::load(Conf::get_sympa_conf())) {
die sprintf 'Configuration file %s has errors.\n', Conf::get_sympa_conf();
}

Expand Down
2 changes: 1 addition & 1 deletion src/bin/upgrade_sympa_password.pl.in
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ if ($dry_run) {
}

die 'Error in configuration'
unless Conf::load($config, 'no_db');
unless Conf::load($config);

# Get obsoleted parameter.
open my $fh, '<', $config or die $ERRNO;
Expand Down
10 changes: 6 additions & 4 deletions src/cgi/wwsympa.fcgi.in
Original file line number Diff line number Diff line change
Expand Up @@ -6773,7 +6773,7 @@ sub do_skinsedit {
$session->{$cn} = lc $in{$cn}
if $in{$cn} and $in{$cn} =~ /\A#[0-9a-z]+\z/i;

my $cur_color = Conf::get_robot_conf($robot, $cn);
my $cur_color = Sympa::WWW::Tools::get_color($robot, $cn);
unless ($session->{$cn}) {
$session->{$cn} = $cur_color;
} elsif ($session->{$cn} ne $cur_color) {
Expand All @@ -6786,7 +6786,8 @@ sub do_skinsedit {
# Update config.
my @keys = grep { $session->{$_} } @std_color_names;
foreach my $key (@keys) {
Conf::set_robot_conf($robot, $key, $session->{$key});
Sympa::WWW::Tools::set_color($robot, $key,
$session->{$key});
}
# Force update CSS.
Sympa::WWW::Tools::get_css_url($robot, force => 1);
Expand All @@ -6801,11 +6802,12 @@ sub do_skinsedit {

$param->{'custom_css'} = $session->{'custom_css'};
foreach my $cn (@std_color_names) {
$param->{$cn} = $session->{$cn} || Conf::get_robot_conf($robot, $cn);
$param->{$cn} =
$session->{$cn} || Sympa::WWW::Tools::get_color($robot, $cn);
}
# Compat.
foreach my $cn (@obs_color_names) {
$param->{$cn} = Conf::get_robot_conf($robot, $cn);
$param->{$cn} = Sympa::WWW::Tools::get_color($robot, $cn);
}

return 1;
Expand Down
147 changes: 8 additions & 139 deletions src/lib/Conf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ use English qw(-no_match_vars);
use Sympa;
use Sympa::ConfDef;
use Sympa::Constants;
use Sympa::DatabaseManager;
use Sympa::Language;
use Sympa::Log;
use Sympa::Regexps;
Expand All @@ -58,22 +57,17 @@ my $log = Sympa::Log->instance;
=cut

## Database and SQL statement handlers
my $sth;
# parameters hash, keyed by parameter name
our %params =
map { $_->{name} => $_ }
grep { $_->{name} } @Sympa::ConfDef::params;

# valid virtual host parameters, keyed by parameter name
my %valid_robot_key_words;
my %db_storable_parameters;
my %optional_key_words;
foreach my $hash (@Sympa::ConfDef::params) {
$valid_robot_key_words{$hash->{'name'}} = 1 if ($hash->{'vhost'});
$db_storable_parameters{$hash->{'name'}} = 1
if (defined($hash->{'db'}) and $hash->{'db'} ne 'none');
$optional_key_words{$hash->{'name'}} = 1 if ($hash->{'optional'});
$optional_key_words{$hash->{'name'}} = 1 if ($hash->{'optional'});
}

our $params_by_categories = _get_parameters_names_by_category();
Expand Down Expand Up @@ -138,7 +132,7 @@ do not change gloval hash %Conf if RETURN_RESULT is set;

sub load {
my $config_file = shift || get_sympa_conf();
my $no_db = shift;
my $no_db = shift; # No longer used.
my $return_result = shift;
my $force_reload;

Expand Down Expand Up @@ -196,16 +190,13 @@ sub load {
$missing_modules_count);
}

_replace_file_value_by_db_value({'config_hash' => \%Conf})
unless ($no_db);
_load_server_specific_secondary_config_files({'config_hash' => \%Conf,});
_load_robot_secondary_config_files({'config_hash' => \%Conf});

## Load robot.conf files
unless (
load_robots(
{ 'config_hash' => \%Conf,
'no_db' => $no_db,
'force_reload' => $force_reload
}
)
Expand Down Expand Up @@ -238,7 +229,6 @@ sub load_robots {
unless (
$robot_conf = _load_single_robot_config(
{ 'robot' => $robot,
'no_db' => $param->{'no_db'},
'force_reload' => $param->{'force_reload'}
}
)
Expand Down Expand Up @@ -375,119 +365,11 @@ sub get_parameters_group {
return $param_hash;
}

## fetch the value from parameter $label of robot $robot from conf_table
sub get_db_conf {
my $robot = shift;
my $label = shift;
# Moved to: Sympa::WWW::Tools::get_color().
#sub get_db_conf;

# if the value is related to a robot that is not explicitly defined, apply
# it to the default robot.
$robot = '*' unless (-f $Conf{'etc'} . '/' . $robot . '/robot.conf');
unless ($robot) { $robot = '*' }

my $sdm = Sympa::DatabaseManager->instance;
unless (
$sdm
and $sth = $sdm->do_prepared_query(
q{SELECT value_conf AS value
FROM conf_table
WHERE robot_conf = ? AND label_conf = ?},
$robot, $label
)
) {
$log->syslog(
'err',
'Unable retrieve value of parameter %s for robot %s from the database',
$label,
$robot
);
return undef;
}

my $value = $sth->fetchrow;

$sth->finish();
return $value;
}

## store the value from parameter $label of robot $robot from conf_table
sub set_robot_conf {
my $robot = shift;
my $label = shift;
my $value = shift;

$log->syslog('info', 'Set config for robot %s, %s="%s"',
$robot, $label, $value);

# set the current config before to update database.
if (-f "$Conf{'etc'}/$robot/robot.conf") {
$Conf{'robots'}{$robot}{$label} = $value;
} else {
$Conf{$label} = $value;
$robot = '*';
}

my $sdm = Sympa::DatabaseManager->instance;
unless (
$sdm
and $sth = $sdm->do_prepared_query(
q{SELECT COUNT(*)
FROM conf_table
WHERE robot_conf = ? AND label_conf = ?},
$robot, $label
)
) {
$log->syslog(
'err',
'Unable to check presence of parameter %s for robot %s in database',
$label,
$robot
);
return undef;
}

my $count = $sth->fetchrow;
$sth->finish();

if ($count == 0) {
unless (
$sth = $sdm->do_prepared_query(
q{INSERT INTO conf_table
(robot_conf, label_conf, value_conf)
VALUES (?, ?, ?)},
$robot, $label, $value
)
) {
$log->syslog(
'err',
'Unable add value %s for parameter %s in the robot %s DB conf',
$value,
$label,
$robot
);
return undef;
}
} else {
unless (
$sth = $sdm->do_prepared_query(
q{UPDATE conf_table
SET robot_conf = ?, label_conf = ?, value_conf = ?
WHERE robot_conf = ? AND label_conf = ?},
$robot, $label, $value,
$robot, $label
)
) {
$log->syslog(
'err',
'Unable set parameter %s value to %s in the robot %s DB conf',
$label,
$value,
$robot
);
return undef;
}
}
}
# Moved to: Sympa::WWW::Tools::set_color().
#sub set_robot_conf;

# Store configs to database
# Deprecated.
Expand Down Expand Up @@ -1982,8 +1864,6 @@ sub _load_single_robot_config {
#XXX {'config_hash' => $robot_conf, 'source_file' => $config_file});
return undef if ($config_err);

_replace_file_value_by_db_value({'config_hash' => $robot_conf})
unless $param->{'no_db'};
_load_robot_secondary_config_files({'config_hash' => $robot_conf});
return $robot_conf;
}
Expand Down Expand Up @@ -2030,19 +1910,8 @@ sub _parse_custom_robot_parameters {
}
}

sub _replace_file_value_by_db_value {
my $param = shift;
my $robot = $param->{'config_hash'}{'robot_name'};
# The name of the default robot is "*" in the database.
$robot = '*' if ($param->{'config_hash'}{'robot_name'} eq '');
foreach my $label (keys %db_storable_parameters) {
next unless ($robot ne '*' && $valid_robot_key_words{$label} == 1);
my $value = get_db_conf($robot, $label);
if (defined $value) {
$param->{'config_hash'}{$label} = $value;
}
}
}
# Deprecated: No longer used.
#sub _replace_file_value_by_db_value;

# Stores the config hash binary representation to a file.
# Returns 1 or undef if something went wrong.
Expand Down
9 changes: 1 addition & 8 deletions src/lib/Sympa/CLI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ sub arrange {
# Moved from: _load() in sympa.pl.
## Load sympa.conf.

unless (Conf::load($options{config}, 'no_db')) {
unless (Conf::load($options{config})) {
die sprintf
"Unable to load sympa configuration, file %s or one of the vhost robot.conf files contain errors. Exiting.\n",
Conf::get_sympa_conf();
Expand Down Expand Up @@ -274,13 +274,6 @@ sub arrange {
$Conf::Conf{'db_name'};
}

# Now trying to load full config (including database)
unless (Conf::load()) {
die sprintf
"Unable to load Sympa configuration, file %s or any of the virtual host robot.conf files contain errors. Exiting.\n",
Conf::get_sympa_conf();
}

$language->set_lang($Conf::Conf{'lang'}) unless $options{lang};

## Main program
Expand Down
9 changes: 1 addition & 8 deletions src/lib/Sympa/CLI/check.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ sub _run {

# Load configuration file. Ignoring database config for now: it avoids
# trying to load a database that could not exist yet.
unless (Conf::load(Conf::get_sympa_conf(), 'no_db')) {
unless (Conf::load(Conf::get_sympa_conf())) {
#FIXME: force reload
die sprintf
"Configuration file %s has errors.\n",
Expand Down Expand Up @@ -95,13 +95,6 @@ sub _run {
$Conf::Conf{'db_name'};
}

## Now trying to load full config (including database)
unless (Conf::load()) { #FIXME: load Site, then robot cache
die sprintf
"Unable to load Sympa configuration, file %s or any of the virtual host robot.conf files contain errors. Exiting.\n",
Conf::get_sympa_conf();
}

## Change working directory.
if (!chdir($Conf::Conf{'home'})) {
printf STDERR "Can't chdir to %s: %s\n", $Conf::Conf{'home'}, $ERRNO;
Expand Down
Loading

0 comments on commit 10d163c

Please sign in to comment.