Commit 88ef15d6 authored by IKEDA Soji's avatar IKEDA Soji
Browse files

Small refactoring.

Replace Sympa::List::load_list_of_scenarios() with Sympa::Scenario::get_scenarios().
parent 04571f0e
......@@ -83,14 +83,18 @@
<label for="read_access">[%|loc%]Read access[%END%]</label>
<select id="read_access" name="read_access">
[% FOREACH s = scenari_read %]
<option value='[% s.key %]' [% s.value.selected %]>[% s.value.web_title %]</option>
<option value="[% s.key %]"
[%~ IF s.value.selected %] selected="selected"[% END ~%]
>[% s.value.title %]</option>
[% END %]
</select>
<label for="edit_access">[%|loc%]Edit access[%END%]</label>
<select id="edit_access" name="edit_access">
[% FOREACH s = scenari_edit %]
<option value='[% s.key %]' [% s.value.selected %]>[% s.value.web_title %]</option>
<option value="[% s.key %]"
[%~ IF s.value.selected %] selected="selected"[% END ~%]
>[% s.value.title %]</option>
[% END %]
</select>
<input type="hidden" name="list" value="[% list %]" />
......
......@@ -10129,7 +10129,7 @@ sub do_scenario_test {
wwslog('info', '');
 
# List available scenarios.
# FIXME Use load_scenario_list().
# FIXME Use get_scenarios().
my $dh;
unless (opendir $dh, Sympa::Constants::DEFAULTDIR . '/scenari/') {
Sympa::WWW::Report::reject_report_web(
......@@ -10877,16 +10877,15 @@ sub _do_edit_list_request {
if ref $pitem->{format} eq 'ARRAY';
 
if ($pitem->{scenario}) {
my $scenarios = $list->load_scenario_list($pitem->{scenario});
my $list_of_scenario = {};
# Only get required scenario attributes.
foreach my $name (keys %{$scenarios}) {
$list_of_scenario->{$name} = {
name => $name,
title => $scenarios->{$name}->get_current_title()
};
}
$pitem->{format} = $list_of_scenario;
my $scenarios =
Sympa::Scenario::get_scenarios($list, $pitem->{scenario});
$pitem->{format} = {
map {
my $name = $_->{name};
my $title = $_->get_current_title;
($name => {name => $name, title => $title});
} @$scenarios
};
} elsif ($pitem->{task}) {
my $tasks = Sympa::Task::get_tasks($list, $pitem->{task});
$pitem->{format} = {map { ($_->{name} => $_) } @$tasks};
......@@ -13439,27 +13438,26 @@ sub do_d_control {
 
my $lang = $param->{'lang'};
 
my ($tmp_list_of_scenario, $name);
## Scenario list for READ
## Only get required scenario attributes
$tmp_list_of_scenario = $list->load_scenario_list('d_read');
foreach $name (keys %{$tmp_list_of_scenario}) {
$param->{'scenari_read'}{$name} = {
'name' => $name,
'web_title' => $tmp_list_of_scenario->{$name}->get_current_title
};
}
# Only get required scenario attributes.
# "web_title" is for compatibility to <= 6.2.38.
my $scenarios = Sympa::Scenario::get_scenarios($list, 'd_read');
$param->{'scenari_read'} = {
map {
my $name = $_->{name};
my $title = $_->get_current_title;
($name => {name => $name, title => $title, web_title => $title});
} @$scenarios
};
$param->{'scenari_read'}{$read}{'selected'} = 'selected="selected"';
 
## Scenario list for EDIT
## Only get required scenario attributes
$tmp_list_of_scenario = $list->load_scenario_list('d_edit');
foreach $name (keys %{$tmp_list_of_scenario}) {
$param->{'scenari_edit'}{$name} = {
'name' => $name,
'web_title' => $tmp_list_of_scenario->{$name}->get_current_title
};
}
$scenarios = Sympa::Scenario::get_scenarios($list, 'd_edit');
$param->{'scenari_edit'} = {
map {
my $name = $_->{name};
my $title = $_->get_current_title;
($name => {name => $name, title => $title, web_title => $title});
} @$scenarios
};
$param->{'scenari_edit'}{$edit}{'selected'} = 'selected="selected"';
 
$param->{'set_owner'} = 1;
......
......@@ -56,7 +56,6 @@ use Sympa::Log;
use Sympa::Process;
use Sympa::Regexps;
use Sympa::Robot;
use Sympa::Scenario;
use Sympa::Spindle::ProcessTemplate;
use Sympa::Spool::Auth;
use Sympa::Template;
......@@ -4285,50 +4284,8 @@ sub is_included {
# Moved to Sympa::Spindle::ProcessDigest::_may_distribute_digest().
#sub may_distribute_digest;
## Loads all scenari for an action
sub load_scenario_list {
$log->syslog('debug3', '(%s, %s)', @_);
my $self = shift;
my $function = shift;
my %list_of_scenario;
my %skip_scenario;
my @list_of_scenario_dir =
@{Sympa::get_search_path($self, subdir => 'scenari')};
unshift @list_of_scenario_dir, $self->{'dir'} . '/scenari'; #FIXME
foreach my $dir (@list_of_scenario_dir) {
next unless -d $dir;
my $scenario_regexp = Sympa::Regexps::scenario();
while (<$dir/$function.*:ignore>) {
if (/$function\.($scenario_regexp):ignore$/) {
my $name = $1;
$skip_scenario{$name} = 1;
}
}
while (<$dir/$function.*>) {
next unless /$function\.($scenario_regexp)$/;
my $name = $1;
# Ignore default setting on <= 6.2.40, using symbolic link.
next if $name eq 'default' and -l "$dir/$action.$name";
next if $list_of_scenario{$name};
next if $skip_scenario{$name};
my $scenario =
Sympa::Scenario->new($self, $function, name => $name);
$list_of_scenario{$name} = $scenario;
}
}
## Return a copy of the data to prevent unwanted changes in the central
## scenario data structure
return Sympa::Tools::Data::dup_var(\%list_of_scenario);
}
# Moved: Use Sympa::Scenario::get_scenarios().
#sub load_scenario_list;
# Deprecated: Use Sympa::Task::get_tasks().
#sub load_task_list;
......
......@@ -1574,6 +1574,51 @@ sub _load_ldap_configuration {
return %Ldap;
}
# Loads all scenari for an function
# Old name: Sympa::List::load_scenario_list() which returns hashref.
sub get_scenarios {
$log->syslog('debug3', '(%s, %s)', @_);
my $that = shift;
my $function = shift;
my @scenarios;
my %seen;
my %skipped;
my @paths = @{Sympa::get_search_path($that, subdir => 'scenari')};
#XXXunshift @list_of_scenario_dir, $that->{'dir'} . '/scenari';
my $scenario_re = Sympa::Regexps::scenario();
foreach my $dir (@paths) {
next unless -d $dir;
while (<$dir/$function.*:ignore>) {
if (/$function\.($scenario_re):ignore$/) {
my $name = $1;
$skipped{$name} = 1;
}
}
while (<$dir/$function.*>) {
next unless /$function\.($scenario_re)$/;
my $name = $1;
# Ignore default setting on <= 6.2.40, using symbolic link.
next if $name eq 'default' and -l "$dir/$function.$name";
next if $seen{$name};
next if $skipped{$name};
my $scenario =
Sympa::Scenario->new($that, $function, name => $name);
$seen{$name} = 1;
push @scenarios, $scenario;
}
}
return [@scenarios];
}
sub get_id {
my $self = shift;
sprintf '%s.%s;%s', @{$self}{qw(function name file_path)};
......
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