From 10d163cc23e2a59ab077199c9d1208dbec60b63e Mon Sep 17 00:00:00 2001 From: IKEDA Soji Date: Sat, 27 Aug 2022 18:17:38 +0900 Subject: [PATCH] Deprecated the feature to save config into database. 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). --- doc/sympa_config.podpl | 29 +-- src/bin/upgrade_bulk_spool.pl.in | 2 +- src/bin/upgrade_send_spool.pl.in | 2 +- src/bin/upgrade_shared_repository.pl.in | 2 +- src/bin/upgrade_sympa_password.pl.in | 2 +- src/cgi/wwsympa.fcgi.in | 10 +- src/lib/Conf.pm | 147 +-------------- src/lib/Sympa/CLI.pm | 9 +- src/lib/Sympa/CLI/check.pm | 9 +- src/lib/Sympa/Config/Schema.pm | 209 ++++++++++----------- src/lib/Sympa/WWW/Tools.pm | 230 +++++++++++++++++++++++- src/sbin/sympa_automatic.pl.in | 9 +- src/sbin/sympa_msg.pl.in | 9 +- 13 files changed, 356 insertions(+), 313 deletions(-) diff --git a/doc/sympa_config.podpl b/doc/sympa_config.podpl index 54db4afce0..b98f5131ce 100644 --- a/doc/sympa_config.podpl +++ b/doc/sympa_config.podpl @@ -37,16 +37,7 @@ foreach my $key (_keys($pinfo)) { my $pii = $pinfo->{$key}; my $ppi = [$key]; - if ($key eq 'color_0') { - $parameters .= "=head3 C, ..., C\n\n"; - } elsif ($key =~ /\Acolor_/) { - next; - } elsif ($key eq 'dark_color') { - $parameters .= - "=head3 C, C, C, C, C, C, C\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, ... C, C, ... C, C, ... C\n\n"; } elsif ($key =~ /\Amain_menu_custom_button_/) { @@ -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, ..., C\n\n"; + $parameters .= "See description on web interface.\n"; + } elsif ($okey eq 'dark_color') { + $parameters .= "=head3 C, C,\n"; + $parameters .= "C, C, C,\n"; + $parameters .= "C, C\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); } } @@ -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; diff --git a/src/bin/upgrade_bulk_spool.pl.in b/src/bin/upgrade_bulk_spool.pl.in index 2135d40bee..55792374ce 100644 --- a/src/bin/upgrade_bulk_spool.pl.in +++ b/src/bin/upgrade_bulk_spool.pl.in @@ -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(); diff --git a/src/bin/upgrade_send_spool.pl.in b/src/bin/upgrade_send_spool.pl.in index 7a89163a05..7354eecf52 100644 --- a/src/bin/upgrade_send_spool.pl.in +++ b/src/bin/upgrade_send_spool.pl.in @@ -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(); } diff --git a/src/bin/upgrade_shared_repository.pl.in b/src/bin/upgrade_shared_repository.pl.in index 2e308d4e46..32ba8f58de 100644 --- a/src/bin/upgrade_shared_repository.pl.in +++ b/src/bin/upgrade_shared_repository.pl.in @@ -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(); } diff --git a/src/bin/upgrade_sympa_password.pl.in b/src/bin/upgrade_sympa_password.pl.in index f01c9261e0..72a7d260dc 100644 --- a/src/bin/upgrade_sympa_password.pl.in +++ b/src/bin/upgrade_sympa_password.pl.in @@ -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; diff --git a/src/cgi/wwsympa.fcgi.in b/src/cgi/wwsympa.fcgi.in index 04c0b26df4..9ffa9ab288 100644 --- a/src/cgi/wwsympa.fcgi.in +++ b/src/cgi/wwsympa.fcgi.in @@ -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) { @@ -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); @@ -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; diff --git a/src/lib/Conf.pm b/src/lib/Conf.pm index cca4f9e517..e8a0c5b7b2 100644 --- a/src/lib/Conf.pm +++ b/src/lib/Conf.pm @@ -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; @@ -58,8 +57,6 @@ my $log = Sympa::Log->instance; =cut -## Database and SQL statement handlers -my $sth; # parameters hash, keyed by parameter name our %params = map { $_->{name} => $_ } @@ -67,13 +64,10 @@ our %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(); @@ -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; @@ -196,8 +190,6 @@ 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}); @@ -205,7 +197,6 @@ sub load { unless ( load_robots( { 'config_hash' => \%Conf, - 'no_db' => $no_db, 'force_reload' => $force_reload } ) @@ -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'} } ) @@ -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. @@ -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; } @@ -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. diff --git a/src/lib/Sympa/CLI.pm b/src/lib/Sympa/CLI.pm index 928cd1853c..2f9593db06 100644 --- a/src/lib/Sympa/CLI.pm +++ b/src/lib/Sympa/CLI.pm @@ -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(); @@ -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 diff --git a/src/lib/Sympa/CLI/check.pm b/src/lib/Sympa/CLI/check.pm index e8d1970dc7..79588e7cf2 100644 --- a/src/lib/Sympa/CLI/check.pm +++ b/src/lib/Sympa/CLI/check.pm @@ -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", @@ -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; diff --git a/src/lib/Sympa/Config/Schema.pm b/src/lib/Sympa/Config/Schema.pm index 21ac7dcd22..b6d46e793a 100644 --- a/src/lib/Sympa/Config/Schema.pm +++ b/src/lib/Sympa/Config/Schema.pm @@ -5353,168 +5353,141 @@ our %pinfo = ( color_0 => { context => [qw(domain site)], - order => 120.10, - group => 'www_appearances', - gettext_id => 'Colors for web interface', - gettext_comment => - 'Colors are used in style sheet (CSS). They may be changed using web interface by listmasters.', - default => '#f7f7f7', # very light grey use in tables, - db => 'db_first', + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, color_1 => { - context => [qw(domain site)], - order => 120.11, - group => 'www_appearances', - default => '#222222', # main menu button color, - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, color_2 => { - context => [qw(domain site)], - order => 120.12, - group => 'www_appearances', - default => '#004b94', # font color, - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, color_3 => { - context => [qw(domain site)], - order => 120.13, - group => 'www_appearances', - default => '#5e5e5e', # top boxe and footer box bacground color, - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, color_4 => { - context => [qw(domain site)], - order => 120.14, - group => 'www_appearances', - default => '#4c4c4c', # page backgound color, - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, color_5 => { - context => [qw(domain site)], - order => 120.15, - group => 'www_appearances', - default => '#0090e9', - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, color_6 => { - context => [qw(domain site)], - order => 120.16, - group => 'www_appearances', - default => '#005ab2', # list menu current button, - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, color_7 => { - context => [qw(domain site)], - order => 120.17, - group => 'www_appearances', - default => '#ffffff', # errorbackground color, - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, color_8 => { - context => [qw(domain site)], - order => 120.18, - group => 'www_appearances', - default => '#f2f6f9', - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, color_9 => { - context => [qw(domain site)], - order => 120.19, - group => 'www_appearances', - default => '#bfd2e1', - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, color_10 => { - context => [qw(domain site)], - order => 120.20, - group => 'www_appearances', - default => '#983222', # inactive button, - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, color_11 => { - context => [qw(domain site)], - order => 120.21, - group => 'www_appearances', - default => '#66aaff', - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, color_12 => { - context => [qw(domain site)], - order => 120.22, - group => 'www_appearances', - default => '#ffe7e7', - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, color_13 => { - context => [qw(domain site)], - order => 120.23, - group => 'www_appearances', - default => '#f48a7b', # input backgound | transparent, - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, color_14 => { - context => [qw(domain site)], - order => 120.24, - group => 'www_appearances', - default => '#ffff99', - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, color_15 => { - context => [qw(domain site)], - order => 120.25, - group => 'www_appearances', - default => '#fe57a1', - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '5.1b', + not_after => '6.2.70', }, dark_color => { context => [qw(domain site)], - order => 120.30, - group => 'www_appearances', - gettext_id => 'Colors for web interface, obsoleted', - default => '#c0c0c0', # 'silver' - db => 'db_first', + obsolete => 1, + not_before => '3.3a', + not_after => '6.2.70', }, light_color => { - context => [qw(domain site)], - order => 120.31, - group => 'www_appearances', - default => '#aaddff', - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '3.3a', + not_after => '6.2.70', }, text_color => { - context => [qw(domain site)], - order => 120.32, - group => 'www_appearances', - default => '#000000', - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '3.3a', + not_after => '6.2.70', }, bg_color => { - context => [qw(domain site)], - order => 120.33, - group => 'www_appearances', - default => '#ffffcc', - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '3.3a', + not_after => '6.2.70', }, error_color => { - context => [qw(domain site)], - order => 120.34, - group => 'www_appearances', - default => '#ff6666', - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '3.3a', + not_after => '6.2.70', }, selected_color => { - context => [qw(domain site)], - order => 120.35, - group => 'www_appearances', - default => '#c0c0c0', # 'silver' - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '3.3a', + not_after => '6.2.70', }, shaded_color => { - context => [qw(domain site)], - order => 120.36, - group => 'www_appearances', - default => '#66cccc', - db => 'db_first', + context => [qw(domain site)], + obsolete => 1, + not_before => '3.3a', + not_after => '6.2.70', }, default_home => { context => [qw(domain site)], @@ -6734,8 +6707,8 @@ It remains there in order to migrating older versions of config. =item db +Deprecated. 'db_first', 'file_first' or 'no'. -TBD. =item importance diff --git a/src/lib/Sympa/WWW/Tools.pm b/src/lib/Sympa/WWW/Tools.pm index 95456878ce..306da1b57c 100644 --- a/src/lib/Sympa/WWW/Tools.pm +++ b/src/lib/Sympa/WWW/Tools.pm @@ -39,6 +39,7 @@ use Sympa; use Conf; use Sympa::ConfDef; use Sympa::Constants; +use Sympa::DatabaseManager; use Sympa::Language; use Sympa::List; use Sympa::LockedFile; @@ -171,6 +172,101 @@ our %bounce_status = ( '7.27' => 'Sender address has null MX', ); +our %css_colors = ( + color_0 => { + order => 0, + default => '#f7f7f7', # very light grey use in tables, + }, + color_1 => { + order => 1, + default => '#222222', # main menu button color, + }, + color_2 => { + order => 2, + default => '#004b94', # font color, + }, + color_3 => { + order => 3, + default => '#5e5e5e', # top boxe and footer box bacground color, + }, + color_4 => { + order => 4, + default => '#4c4c4c', # page backgound color, + }, + color_5 => { + order => 5, + default => '#0090e9', + }, + color_6 => { + order => 6, + default => '#005ab2', # list menu current button, + }, + color_7 => { + order => 7, + default => '#ffffff', # errorbackground color, + }, + color_8 => { + order => 8, + default => '#f2f6f9', + }, + color_9 => { + order => 9, + default => '#bfd2e1', + }, + color_10 => { + order => 10, + default => '#983222', # inactive button, + }, + color_11 => { + order => 11, + default => '#66aaff', + }, + color_12 => { + order => 12, + default => '#ffe7e7', + }, + color_13 => { + order => 13, + default => '#f48a7b', # input backgound | transparent, + }, + color_14 => { + order => 14, + default => '#ffff99', + }, + color_15 => { + order => 15, + default => '#fe57a1', + }, + dark_color => { + order => 100, + default => '#c0c0c0', # 'silver' + }, + light_color => { + order => 101, + default => '#aaddff', + }, + text_color => { + order => 102, + default => '#000000', + }, + bg_color => { + order => 103, + default => '#ffffcc', + }, + error_color => { + order => 104, + default => '#ff6666', + }, + selected_color => { + order => 105, + default => '#c0c0c0', # 'silver' + }, + shaded_color => { + order => 106, + default => '#66cccc', + }, +); + ## Load WWSympa configuration file ##sub load_config ## MOVED: use Conf::_load_wwsconf(). @@ -721,12 +817,16 @@ sub _get_css_url { # Get parameters for parsing. my $param = {}; foreach my $p ( - grep { /_color\z/ or /\Acolor_/ or /_url\z/ } - map { $_->{name} } + grep {/_url\z/} + map { $_->{name} } grep { not $_->{obsolete} and $_->{name} } @Sympa::ConfDef::params ) { $param->{$p} = Conf::get_robot_conf($robot, $p); } + foreach my $cn (Sympa::WWW::Tools::css_colors()) { + $param->{$cn} = Sympa::WWW::Tools::get_color($robot, $cn); + } + if (%colors) { # Override colors for parsing. my @keys = @@ -946,5 +1046,131 @@ sub _get_css_url { # DEPRECATED. No longer used. #sub unescape_html_minimum; +my %color_values; + +sub css_colors { + return sort { $css_colors{$a}->{order} <=> $css_colors{$b}->{order} } + keys %css_colors; +} + +# Fetch the color value for name $label of domain $robot from conf_table. +# Old name: Conf::get_db_conf(). +sub get_color { + my $robot = shift; + my $label = shift; + + my $value = $color_values{$robot}->{$label} + if $color_values{$robot}; + return $value if length($value // ''); + + my $sdm = Sympa::DatabaseManager->instance; + my $sth; + 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; + } + $value = $sth->fetchrow; + $sth->finish; + + if (length($value // '')) { + $color_values{$robot} ||= {}; + $color_values{$robot}->{$label} = $value; + return $value; + } + return $css_colors{$label}->{default}; +} + +# store the color value $label of robot $robot to conf_table +# Old name: Conf::set_robot_conf(). +sub set_color { + $log->syslog('debug2', 'Set config for robot %s, %s="%s"', @_); + my $robot = shift; + my $label = shift; + my $value = shift; + + return unless grep { $label eq $_ } Sympa::WWW::Tools::css_colors(); + + # set the current config before to update database. + $color_values{$robot} ||= {}; + $color_values{$robot}->{$label} = $value; + + my $sdm = Sympa::DatabaseManager->instance; + my $sth; + 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; + } + } + + return 1; +} + 1; __END__ diff --git a/src/sbin/sympa_automatic.pl.in b/src/sbin/sympa_automatic.pl.in index b643421209..84d8bfce54 100644 --- a/src/sbin/sympa_automatic.pl.in +++ b/src/sbin/sympa_automatic.pl.in @@ -197,7 +197,7 @@ exit(0); # Load configuration. sub _load { ## Load sympa.conf. - unless (Conf::load(Conf::get_sympa_conf(), 'no_db')) { #Site and Robot + unless (Conf::load(Conf::get_sympa_conf())) { #Site and Robot 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(); @@ -234,13 +234,6 @@ sub _load { $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(); - } - ## Main program if (!chdir($Conf::Conf{'home'})) { die sprintf 'Can\'t chdir to %s: %s', $Conf::Conf{'home'}, $ERRNO; diff --git a/src/sbin/sympa_msg.pl.in b/src/sbin/sympa_msg.pl.in index ef0eee50b7..4fcaa4406a 100644 --- a/src/sbin/sympa_msg.pl.in +++ b/src/sbin/sympa_msg.pl.in @@ -277,7 +277,7 @@ exit(0); # Load configuration. sub _load { ## Load sympa.conf. - unless (Conf::load(Conf::get_sympa_conf(), 'no_db')) { #Site and Robot + unless (Conf::load(Conf::get_sympa_conf())) { #Site and Robot 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(); @@ -314,13 +314,6 @@ sub _load { $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(); - } - ## Set locale configuration ## Compatibility with version < 2.3.3 $main::options{'lang'} =~ s/\.cat$//