Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Candidate fix for issue #459 #463

Merged
merged 3 commits into from
Nov 3, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 45 additions & 34 deletions src/lib/Sympa/Upgrade.pm
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,55 @@ sub upgrade {
return undef;
}

#XXX# Always update config.bin files while upgrading
#XXXConf::delete_binaries();
# As of 6.2.33b.1, owners/moderators are no longer stored in config file.
# - Write out initial permanent owners/editors in <role>.dump files.
# - And, if list is not closed, import owners/moderators from those files
# into database.
if (lower_version($previous_version, '6.2.33b.1')) {
$log->syslog('notice',
'Restoring users of ALL lists...it may take a while...');

## Always update config.bin files while upgrading
## This is especially useful for character encoding reasons
$log->syslog('notice',
'Rebuilding config.bin files for ALL lists...it may take a while...');
my $all_lists = Sympa::List::get_lists('*', 'reload_config' => 1);
my $all_lists = Sympa::List::get_lists('*', skip_sync_admin => 1);
foreach my $list (@{$all_lists || []}) {
next unless $list;
my $dir = $list->{'dir'};

## Empty the admin_table entries and recreate them
$log->syslog('notice', 'Rebuilding the admin_table...');
my $fh;
next unless open $fh, '<', $dir . '/config';
my $config = do { local $RS; <$fh> };
close $fh;

if ($all_lists and @$all_lists) {
foreach my $list (@$all_lists) {
$list->sync_include_admin;
$config =~ s/(\A|\n)[\t ]+(?=\n)/$1/g; # normalize empty lines
open my $ifh, '<', \$config; # open "in memory" file
my @config = do { local $RS = ''; <$ifh> };
close $ifh;
foreach my $role (qw(owner editor)) {
my $file = $dir . '/' . $role . '.dump';
if (!-e $file and open my $ofh, '>', $file) {
my $admins = join '', grep {/\A\s*$role\b/} @config;
print $ofh $admins;
close $ofh;
}

next
if $list->{'admin'}{'status'} eq 'closed'
or $list->{'admin'}{'status'} eq 'family_closed';
$list->restore_users($role);
}
}
} else {
# Prevent empty admin table (GH #71).
$log->syslog('notice',
'Skipping rebuild, no list config files found');
}

# Always update config.bin files while upgrading.
# This is especially useful for character encoding reasons.
$log->syslog('notice',
'Rebuilding config.bin files for ALL lists...it may take a while...');
my $all_lists =
Sympa::List::get_lists('*', reload_config => 1, skip_sync_admin => 1);
# Recreate admin_table entries.
$log->syslog('notice',
'Rebuilding the admin_table...it may take a while...');
foreach my $list (@{$all_lists || []}) { # See GH #71
$list->sync_include_admin;
}

## Migration to tt2
Expand Down Expand Up @@ -1792,24 +1821,6 @@ sub upgrade {
rename $dir . '/subscribers.closed.dump',
$dir . '/member.dump';
}

my $fh;
next unless open $fh, '<', $dir . '/config';
my $config = do { local $RS; <$fh> };
close $fh;
# Write out initial permanent owners/editors in <role>.dump files.
$config =~ s/(\A|\n)[\t ]+(?=\n)/$1/g; # normalize empty lines
open my $ifh, '<', \$config; # open "in memory" file
my @config = do { local $RS = ''; <$ifh> };
close $ifh;
foreach my $role (qw(owner editor)) {
my $file = $dir . '/' . $role . '.dump';
if (!-e $file and open my $ofh, '>', $file) {
my $admins = join '', grep {/\A\s*$role\b/} @config;
print $ofh $admins;
close $ofh;
}
}
}
}

Expand Down