Commit 7ab10f43 authored by IKEDA Soji's avatar IKEDA Soji
Browse files

Sympa::Upgrade: rename blacklist.txt to blocklist.txt

parent 687842bc
......@@ -2070,44 +2070,50 @@ sub upgrade {
}
}
# Variable tags "($tag$% ... %$tag$)" no longer used in
# mhonarc_rc.tt2 (ex. mhonarc-ressources.tt2) and were replaced with
# "<% ... %>".
if (lower_version($previous_version, '6.2.61b.1')) {
# Variable tags "($tag$% ... %$tag$)" no longer used in
# mhonarc_rc.tt2 (ex. mhonarc-ressources.tt2) and were replaced with
# "<% ... %>".
$log->syslog('notice', 'Converting mhonarc-ressources.tt2...');
my $oldfile = 'mhonarc-ressources.tt2';
my $newfile = 'mhonarc_rc.tt2';
my @dirs;
push @dirs, $Conf::Conf{'etc'}
if -f $Conf::Conf{'etc'} . '/' . $oldfile;
foreach my $robot (Sympa::List::get_robots()) {
my $dir = sprintf '%s/%s', $Conf::Conf{'etc'}, $robot;
push @dirs, $dir
if -f $dir . '/' . $oldfile;
foreach my $list (@{Sympa::List::get_lists($robot) || []}) {
push @dirs, $list->{'dir'}
if -f $list->{'dir'} . '/' . $oldfile;
_process_all_files(
'mhonarc-ressources.tt2',
sub {
my $dir = shift;
my $oldfile = shift;
my $newfile = 'mhonarc_rc.tt2';
open my $ifh, '<', $dir . '/' . $oldfile
or die sprintf '%s: %s', $oldfile, $ERRNO;
my $text = do { local $RS; <$ifh> };
close $ifh;
$text =~ s{[(]\$tag\$%}{<%}g;
$text =~ s{%\$tag\$[)]}{%>}g;
open my $ofh, '>', $dir . '/' . $newfile
or die sprintf '%s: %s', $newfile, $ERRNO;
print $ofh $text;
close $ofh;
}
}
foreach my $dir (@dirs) {
open my $ifh, '<', $dir . '/' . $oldfile
or die sprintf '%s: %s', $oldfile, $ERRNO;
my $text = do { local $RS; <$ifh> };
close $ifh;
$text =~ s{[(]\$tag\$%}{<%}g;
$text =~ s{%\$tag\$[)]}{%>}g;
);
$log->syslog('notice', '...Done. Use new file(s) mhonarc_rc.tt2.');
open my $ofh, '>', $dir . '/' . $newfile
or die sprintf '%s: %s', $newfile, $ERRNO;
print $ofh $text;
close $ofh;
}
# blocklist.txt will be used instead of blacklist.txt
$log->syslog('notice', 'Rename blacklist.txt to blocklist.txt...');
_process_all_files(
'search_filter/blacklist.txt',
sub {
my $dir = shift;
my $oldfile = shift;
my $newfile = 'search_filter/blocklist.txt';
$log->syslog('notice', '...Done. Use new file(s) mhonarc_rc.tt2.');
rename($dir . '/' . $oldfile, $dir . '/' . $newfile)
or
$log->syslog('err', 'Cannot rename file %s/%s to %s: %m',
$dir, $oldfile, $newfile);
}
);
$log->syslog('notice', '...Done.');
}
return 1;
......@@ -2423,4 +2429,27 @@ sub _get_cacnonical_write_date {
}
}
sub _process_all_files {
my $file = shift;
my $sub = shift;
my @dirs;
push @dirs, $Conf::Conf{'etc'}
if -f $Conf::Conf{'etc'} . '/' . $file;
foreach my $robot (Sympa::List::get_robots()) {
my $dir = sprintf '%s/%s', $Conf::Conf{'etc'}, $robot;
push @dirs, $dir
if -f $dir . '/' . $file;
foreach my $list (@{Sympa::List::get_lists($robot) || []}) {
push @dirs, $list->{'dir'}
if -f $list->{'dir'} . '/' . $file;
}
}
foreach my $dir (@dirs) {
$sub->($dir, $file);
}
}
1;
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