Simplify param panel list code

Remove duplicated code, move it into Bugzilla::Config, do not require add_panels hook
hinted-selects
Vitaliy Filippov 2014-11-03 00:24:49 +03:00
parent 23cab471af
commit 25894d28ab
5 changed files with 36 additions and 54 deletions

View File

@ -35,6 +35,7 @@ use strict;
use base qw(Exporter);
use Bugzilla::Constants;
use Bugzilla::Hook;
use Bugzilla::Util qw(get_subclasses);
use Bugzilla::Install::Filesystem qw(fix_file_permissions);
use Data::Dumper;
use File::Temp;
@ -54,40 +55,40 @@ use vars qw(@param_list);
# Perl throws a warning if we use bz_locations() directly after do.
our %params;
# Load in the param definitions
sub _load_params {
my $panels = param_panels();
my %hook_panels;
foreach my $panel (keys %$panels) {
my $module = $panels->{$panel};
eval("require $module") || die $@;
my @new_param_list = $module->get_param_list();
$hook_panels{lc($panel)} = { params => \@new_param_list };
foreach my $item (@new_param_list) {
$params{$item->{'name'}} = $item;
sub _load_params
{
my $panels = param_panel_props();
foreach my $panel (values %$panels)
{
foreach my $item (@{$panel->{params}})
{
$params{$item->{name}} = $item;
}
push(@param_list, @new_param_list);
push @param_list, @{$panel->{params}};
}
# This hook is also called in editparams.cgi. This call here is required
# to make SetParam work.
Bugzilla::Hook::process('config_modify_panels',
{ panels => \%hook_panels });
}
# END INIT CODE
# Subroutines go here
sub param_panels {
my $param_panels = {};
my $libpath = bz_locations()->{'libpath'};
foreach my $item ((glob "$libpath/Bugzilla/Config/*.pm")) {
$item =~ m#/([^/]+)\.pm$#;
my $module = $1;
$param_panels->{$module} = "Bugzilla::Config::$module" unless $module eq 'Common';
sub param_panel_props
{
my $r = {};
foreach my $panel (@{get_subclasses('Bugzilla::Config')})
{
next if $panel eq 'Common';
my $module = "Bugzilla::Config::$panel";
eval("require $module") || die $@;
my @module_param_list = "$module"->get_param_list();
my $item = {
name => lc($panel),
params => \@module_param_list,
sortkey => eval "\$${module}::sortkey;"
};
$r->{$item->{name}} = $item;
}
# Now check for any hooked params
Bugzilla::Hook::process('config_add_panels',
{ panel_modules => $param_panels });
return $param_panels;
Bugzilla::Hook::process('config_modify_panels', { panels => $r });
return $r;
}
sub SetParam {

View File

@ -52,35 +52,16 @@ my $current_panel = $ARGS->{section} || 'core';
$current_panel =~ /^([A-Za-z0-9_-]+)$/;
$current_panel = $1;
my $current_module;
my @panels = ();
my $param_panels = Bugzilla::Config::param_panels();
foreach my $panel (keys %$param_panels)
{
my $module = $param_panels->{$panel};
eval("require $module") || die $@;
my @module_param_list = "$module"->get_param_list();
my $item = {
name => lc($panel),
current => ($current_panel eq lc($panel)) ? 1 : 0,
param_list => \@module_param_list,
sortkey => eval "\$${module}::sortkey;"
};
push @panels, $item;
$current_module = $panel if ($current_panel eq lc($panel));
}
my $panels = Bugzilla::Config::param_panel_props();
$current_panel = undef if !$panels->{$current_panel};
$panels->{$current_panel}->{current} = 1 if $current_panel;
$vars->{panels} = [ values %$panels ];
my %hook_panels = map { $_->{name} => { params => $_->{param_list} } } @panels;
# Note that this hook is also called in Bugzilla::Config.
Bugzilla::Hook::process('config_modify_panels', { panels => \%hook_panels });
$vars->{panels} = \@panels;
if ($action eq 'save' && $current_module)
if ($action eq 'save' && $current_panel)
{
check_token_data($token, 'edit_parameters');
my @changes = ();
my @module_param_list = @{ $hook_panels{lc($current_module)}->{params} };
my @module_param_list = @{ $vars->{panels}->{$current_panel}->{params} };
foreach my $i (@module_param_list)
{

View File

@ -25,7 +25,7 @@
[% sortlist_separator = '---' %]
<dl>
[% FOREACH param = panel.param_list %]
[% FOREACH param = panel.params %]
<dt><a name="[% param.name FILTER html %]">[% param.name FILTER html %]</a></dt>
<dd>[% panel.param_descs.${param.name} FILTER none %]
<p>

View File

@ -29,7 +29,7 @@
[% FOREACH panel = panels %]
[% PROCESS "admin/params/${panel.name}.html.tmpl"
params = panel.param_list %]
params = panel.params %]
[% panel.title = title %]
[% panel.desc = desc %]
[% panel.param_descs = param_descs %]

View File

@ -31,7 +31,7 @@
<th>Section</th>
</tr>
[% FOREACH panel = panels %]
[% FOREACH param = panel.param_list.sort('name') %]
[% FOREACH param = panel.params.sort('name') %]
<tr>
<td>
<a href="editparams.cgi?section=