Commit 8a3af95b authored by IKEDA Soji's avatar IKEDA Soji
Browse files

Cleanup redundant code

parent e5c50def
......@@ -16517,28 +16517,41 @@ sub do_wsdl {
sub do_sync_include {
wwslog('info', '(%s, %s)', $in{'list'}, $in{'role'});
 
my $role = $in{'role'} || 'member'; # Compat.<=6.2.52.
my $role = $in{'role'} || 'member'; # Compat.<=6.2.54
$in{'page'} = $role unless $role eq 'member';
 
$param->{'list'} = $list->{'name'};
$param->{'role'} = $role;
$param->{'page'} = $role unless $role eq 'member';
 
unless (defined $list->sync_include($role)) {
Sympa::WWW::Report::reject_report_web('intern',
'sync_include_failed', {},
$param->{'action'}, $list, $param->{'user'}{'email'}, $robot);
my $spindle = Sympa::Spindle::ProcessRequest->new(
context => $list,
action => 'include',
role => $role,
sender => $param->{'user'}{'email'},
scenario_context => {skip => 1},
);
unless ($spindle and $spindle->spin) {
wwslog('err', 'Failed to sync role %s of list %s with data sources',
$role, $list);
return undef;
}
 
Sympa::WWW::Report::notice_report_web(
{ member => 'member_updated',
owner => 'owner_updated',
editor => 'editor_updated',
}->{$role},
{},
$param->{'action'}
);
foreach my $report (@{$spindle->{stash} || []}) {
if ($report->[1] eq 'notice') {
Sympa::WWW::Report::notice_report_web(@{$report}[2, 3],
$param->{'action'});
} else {
Sympa::WWW::Report::reject_report_web(@{$report}[1 .. 3],
$param->{action});
}
}
unless (@{$spindle->{stash} || []}) {
Sympa::WWW::Report::notice_report_web('performed', {},
$param->{'action'});
web_db_log({'parameters' => $in{'email'}, 'status' => 'success'});
}
return 'review';
}
 
......
......@@ -4783,9 +4783,10 @@ sub sync_include {
my $self = shift;
my $role = shift;
$role ||= 'member'; # Compat.<=6.2.52
$role ||= 'member'; # Compat.<=6.2.54
return 0 unless $self->has_data_sources($role)
return 0
unless $self->has_data_sources($role)
or $self->has_included_users($role);
my $spindle = Sympa::Spindle::ProcessRequest->new(
......@@ -4809,8 +4810,10 @@ sub sync_include {
}
# Get and save total of subscribers.
$self->_cache_publish_expiry(($role eq 'member') ? 'member' : 'admin_user');
$self->_cache_publish_expiry(($role eq 'member') ? 'last_sync' : 'last_sync_admin_user');
$self->_cache_publish_expiry(
($role eq 'member') ? 'member' : 'admin_user');
$self->_cache_publish_expiry(
($role eq 'member') ? 'last_sync' : 'last_sync_admin_user');
return 1;
}
......@@ -4829,9 +4832,6 @@ sub on_the_fly_sync_include {
my $self = shift;
my %options = @_;
return 0 unless $self->has_data_sources('member')
or $self->has_included_users('member');
my $pertinent_ttl = $self->{'admin'}{'distribution_ttl'}
|| $self->{'admin'}{'ttl'};
$log->syslog('debug2', '(%s)', $pertinent_ttl);
......@@ -4850,15 +4850,8 @@ sub on_the_fly_sync_include {
return 0;
}
# Obsoleted. Use sync_include('owner') & sync_include('editor').
sub sync_include_admin {
my $self = shift;
my $o = $self->sync_include('owner');
my $e = $self->sync_include('editor');
return undef unless defined $o and defined $e;
return $o || $e;
}
# DEPRECATED. Use sync_include('owner') & sync_include('editor').
#sub sync_include_admin;
#sub _load_list_admin_from_config;
# -> No longer used.
......@@ -6649,9 +6642,6 @@ sub has_data_sources {
return 0;
}
# Compat.
sub has_include_data_sources { goto &has_data_sources; }
sub has_included_users {
my $self = shift;
my $role = shift;
......@@ -6659,12 +6649,14 @@ sub has_included_users {
my $sdm = Sympa::DatabaseManager->instance;
my $sth;
if (not $role or $role eq 'member') {
unless ($sdm and $sth = $sdm->do_prepared_query(
q{SELECT COUNT(*)
FROM subscriber_table
WHERE list_subscriber = ? AND robot_subscriber = ? AND
inclusion_subscriber IS NOT NULL},
$self->{'name'}, $self->{'domain'})
unless (
$sdm and $sth = $sdm->do_prepared_query(
q{SELECT COUNT(*)
FROM subscriber_table
WHERE list_subscriber = ? AND robot_subscriber = ? AND
inclusion_subscriber IS NOT NULL},
$self->{'name'}, $self->{'domain'}
)
) {
return undef;
}
......@@ -6672,14 +6664,16 @@ sub has_included_users {
return 1 if $count;
}
if (not $role or $role ne 'member') {
unless ($sdm and $sth = $sdm->do_prepared_query(
q{SELECT COUNT(*)
FROM admin_table
WHERE list_admin = ? AND robot_admin = ? AND
inclusion_admin IS NOT NULL AND
(role_admin = ? OR role_admin = ?)},
$self->{'name'}, $self->{'domain'},
($role || 'owner'), ($role || 'editor'))
unless (
$sdm and $sth = $sdm->do_prepared_query(
q{SELECT COUNT(*)
FROM admin_table
WHERE list_admin = ? AND robot_admin = ? AND
inclusion_admin IS NOT NULL AND
(role_admin = ? OR role_admin = ?)},
$self->{'name'}, $self->{'domain'},
($role || 'owner'), ($role || 'editor')
)
) {
return undef;
}
......
......@@ -271,11 +271,10 @@ sub _twist {
#FIXME: add_stat().
## Synchronize list members if required
if ($list->has_include_data_sources()) {
$log->syslog('notice', "Synchronizing list members...");
$list->sync_include();
}
# Synchronize list members if required
$log->syslog('notice', "Synchronizing list members...");
$list->sync_include('member');
$log->syslog('notice', "...done");
# config_changes
if (open my $fh, '>', "$list->{'dir'}/config_changes") {
......@@ -319,11 +318,10 @@ sub _twist {
}
}
## Synchronize list members if required
if ($list->has_include_data_sources()) {
$log->syslog('notice', "Synchronizing list members...");
$list->sync_include();
}
# Synchronize list members if required
$log->syslog('notice', "Synchronizing list members...");
$list->sync_include('member');
$log->syslog('notice', "...done");
return 1;
}
......
......@@ -258,10 +258,9 @@ sub _twist {
);
# Synchronize list members if required
if ($list->has_include_data_sources()) {
$log->syslog('notice', "Synchronizing list members...");
$list->sync_include();
}
$log->syslog('notice', "Synchronizing list members...");
$list->sync_include('member');
$log->syslog('notice', "...done");
$list->save_config($sender);
return 1;
......
......@@ -83,10 +83,11 @@ sub _twist {
$list->restore_users('owner');
$list->restore_users('editor');
} elsif ($mode eq 'install') {
# Since initial poermanent list users have been stored by create_list
# Since initial permanent list users have been stored by create_list
# or create_automatic_list, add transitional owners/editors from
# external data sources.
$list->sync_include_admin;
$list->sync_include('owner');
$list->sync_include('editor');
}
# Install new aliases.
......
......@@ -56,11 +56,9 @@ sub _twist {
$language->set_lang($list->{'admin'}{'lang'});
# Members list synchronization if include is in use.
if ($list->has_include_data_sources) {
unless (defined $list->on_the_fly_sync_include(use_ttl => 1)) {
$log->syslog('notice', 'Unable to synchronize list %s', $list);
#FIXME: Abort if synchronization failed.
}
unless (defined $list->on_the_fly_sync_include(use_ttl => 1)) {
$log->syslog('notice', 'Unable to synchronize list %s', $list);
#FIXME: Abort if synchronization failed.
}
my @users;
......
......@@ -282,11 +282,10 @@ sub _twist {
$list->{'admin'}{'status'} = $param->{'status'} || 'open';
$list->{'admin'}{'family_name'} = $family->{'name'};
## Synchronize list members if required
if ($list->has_include_data_sources()) {
$log->syslog('notice', "Synchronizing list members...");
$list->sync_include();
}
# Synchronize list members if required
$log->syslog('notice', "Synchronizing list members...");
$list->sync_include('member');
$log->syslog('notice', "...done");
# (Note: Following block corresponds to previous _set_status_changes()).
my $current_status = $list->{'admin'}{'status'} || 'open';
......
......@@ -304,7 +304,7 @@ sub _twist {
}
if ($dyn_just_created) {
unless (defined $list->sync_include()) {
unless (defined $list->sync_include('member')) {
$log->syslog(
'err',
'Failed to synchronize list members of dynamic list %s from %s family',
......
......@@ -193,12 +193,9 @@ sub _send_msg {
unless ($resent_by) { # Not in ResendArchive spindle.
# Synchronize list members, required if list uses include sources
# unless sync_include has been performed recently.
if ($list->has_include_data_sources()) {
unless (defined $list->on_the_fly_sync_include(use_ttl => 1)) {
$log->syslog('notice', 'Unable to synchronize list %s',
$list);
#FIXME: Might be better to abort if synchronization failed.
}
unless (defined $list->on_the_fly_sync_include(use_ttl => 1)) {
$log->syslog('notice', 'Unable to synchronize list %s', $list);
#FIXME: Might be better to abort if synchronization failed.
}
# Blindly send the message to all users.
......
......@@ -99,7 +99,8 @@ sub _create_all_tasks {
next unless $list->{'admin'}{'status'} eq 'open';
if ($model eq 'sync_include') {
# Create tasks only when they are required.
next unless $list->has_data_sources
next
unless $list->has_data_sources
or $list->has_included_users;
}
......
......@@ -175,7 +175,8 @@ sub upgrade {
$log->syslog('notice',
'Rebuilding the admin_table...it may take a while...');
foreach my $list (@{$all_lists || []}) { # See GH #71
$list->sync_include_admin;
$list->sync_include('owner');
$list->sync_include('editor');
}
## Migration to tt2
......@@ -217,7 +218,8 @@ sub upgrade {
$log->syslog('notice', 'Initializing the new admin_table...');
my $all_lists = Sympa::List::get_lists('*');
foreach my $list (@$all_lists) {
$list->sync_include_admin();
$list->sync_include('owner');
$list->sync_include('editor');
}
}
......
......@@ -979,12 +979,10 @@ sub review {
|| Sympa::is_listmaster($list, $sender);
## Members list synchronization if include is in use
if ($list->has_include_data_sources()) {
unless (defined $list->on_the_fly_sync_include(use_ttl => 1)) {
$log->syslog('notice', 'Unable to synchronize list %s',
$list);
}
unless (defined $list->on_the_fly_sync_include(use_ttl => 1)) {
$log->syslog('notice', 'Unable to synchronize list %s', $list);
}
unless ($user = $list->get_first_list_member({'sortby' => 'email'})) {
$log->syslog('err', 'No subscribers in list "%s"',
$list->{'name'});
......@@ -1057,10 +1055,8 @@ sub fullReview {
}
# Members list synchronization if include is in use
if ($list->has_include_data_sources()) {
unless (defined $list->on_the_fly_sync_include(use_ttl => 1)) {
$log->syslog('notice', 'Unable to synchronize list %s', $list);
}
unless (defined $list->on_the_fly_sync_include(use_ttl => 1)) {
$log->syslog('notice', 'Unable to synchronize list %s', $list);
}
my $members;
......
......@@ -823,27 +823,31 @@ if ($main::options{'dump'} or $main::options{'dump_users'}) {
exit 0;
} elsif ($main::options{'sync_include'}) {
my $list = Sympa::List->new($main::options{'sync_include'});
my $role = $main::options{'role'} || 'member'; # Compat. <= 6.2.52
my $role = $main::options{'role'} || 'member'; # Compat. <= 6.2.54
unless (defined $list) {
printf STDERR "Incorrect list name %s\n",
$main::options{'sync_include'};
exit 1;
}
unless (grep {$role eq $_} qw(member owner editor)) {
unless (grep { $role eq $_ } qw(member owner editor)) {
printf STDERR "Unknown role %s\n", $role;
exit 1;
}
unless (defined $list->sync_include($role)) {
printf STDERR "Failed to synchronize list users (%s)\n", $role;
my $spindle = Sympa::Spindle::ProcessRequest->new(
context => $list,
action => 'include',
role => $role,
sender => Sympa::get_address($list, 'listmaster'),
scenario_context => {skip => 1},
);
unless ($spindle and $spindle->spin and _report($spindle)) {
printf STDERR "Could not sync role %s of list %s with data sources\n",
$role, $list->get_id;
exit 1;
}
printf "Users (%s) of list %s have been successfully update.\n",
$role, $list->get_id;
exit 0;
## Migration from one version to another
} elsif ($main::options{'upgrade'}) {
......
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