2015-07-28 22:44:53 +02:00
|
|
|
|
# Copyright (C) 2014–2015 Alex Schroeder <alex@gnu.org>
|
2014-06-06 17:32:44 +02:00
|
|
|
|
#
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify it under
|
|
|
|
|
|
# the terms of the GNU General Public License as published by the Free Software
|
|
|
|
|
|
# Foundation; either version 3 of the License, or (at your option) any later
|
|
|
|
|
|
# version.
|
|
|
|
|
|
#
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
#
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
|
|
# this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
2015-03-29 23:18:07 +02:00
|
|
|
|
use strict;
|
2015-08-18 10:48:03 +02:00
|
|
|
|
use v5.10;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
|
2014-06-19 23:00:18 +02:00
|
|
|
|
use utf8;
|
2014-06-17 13:14:13 +02:00
|
|
|
|
|
2014-08-22 16:17:18 +02:00
|
|
|
|
AddModuleDescription('upgrade.pl', '2014-06-17 New Directory Structure');
|
|
|
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
|
our ($q, %Action, %InterSite, $ModuleDir, $IndexFile, $DataDir, $PageDir, $KeepDir, $InterMap, $JoinerDir, $JoinerEmailDir, $LocalNamesPage, $GotobarName, $NearMap, $RefererDir, $SidebarName);
|
2015-03-27 03:01:01 +02:00
|
|
|
|
|
2014-06-21 04:18:16 -04:00
|
|
|
|
# We are now running in InitModules. InitVariables will be called later.
|
|
|
|
|
|
# We want to prevent any calls to GetPageContent and the like.
|
|
|
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
|
*UpgradeOldInitVariables = \&InitVariables;
|
|
|
|
|
|
*InitVariables = \&UpgradeNewInitVariables;
|
2014-06-21 04:18:16 -04:00
|
|
|
|
|
|
|
|
|
|
sub UpgradeNewInitVariables {
|
|
|
|
|
|
$InterMap = undef;
|
2014-06-21 04:44:33 -04:00
|
|
|
|
$LocalNamesPage = undef;
|
|
|
|
|
|
$SidebarName = undef;
|
|
|
|
|
|
$NearMap = undef;
|
2014-06-21 05:49:31 -04:00
|
|
|
|
$GotobarName = undef;
|
2014-06-21 04:18:16 -04:00
|
|
|
|
UpgradeOldInitVariables(@_);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
|
*DoBrowseRequest = \&DoUpgrade;
|
2014-06-06 17:32:44 +02:00
|
|
|
|
|
|
|
|
|
|
sub DoUpgrade {
|
2014-06-17 13:14:13 +02:00
|
|
|
|
# The only thing allowed besides upgrading is login and unlock
|
|
|
|
|
|
my $action = lc(GetParam('action', ''));
|
|
|
|
|
|
if (($action eq 'password' or $action eq 'unlock')
|
|
|
|
|
|
and $Action{$action}) {
|
2015-03-29 23:18:07 +02:00
|
|
|
|
return &{$Action{$action}}(GetId());
|
2014-06-17 13:14:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Only admins may upgrade
|
|
|
|
|
|
ReportError(T('Upgrading Database'),
|
|
|
|
|
|
'403 FORBIDDEN', 0,
|
|
|
|
|
|
$q->p(T('This operation is restricted to administrators only...'))
|
|
|
|
|
|
. $q->p(ScriptLink('action=password', T('Login'), 'password')))
|
|
|
|
|
|
unless UserIsAdmin();
|
|
|
|
|
|
|
|
|
|
|
|
ReportError(T('Upgrading Database'),
|
|
|
|
|
|
'403 FORBIDDEN', 0,
|
|
|
|
|
|
$q->p(T('Did the previous upgrade end with an error? A lock was left behind.'))
|
|
|
|
|
|
. $q->p(ScriptLink('action=unlock', T('Unlock wiki'), 'unlock')))
|
|
|
|
|
|
unless RequestLockDir('main');
|
2014-06-06 17:32:44 +02:00
|
|
|
|
|
|
|
|
|
|
print GetHeader('', T('Upgrading Database')),
|
|
|
|
|
|
$q->start_div({-class=>'content upgrade'});
|
|
|
|
|
|
|
2016-06-15 23:21:07 +02:00
|
|
|
|
if (IsFile($IndexFile)) {
|
|
|
|
|
|
Unlink($IndexFile);
|
2014-06-06 17:32:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
print "<p>Renaming files...";
|
|
|
|
|
|
|
2014-06-19 23:00:18 +02:00
|
|
|
|
for my $ns ('', keys %InterSite) {
|
2016-06-22 14:43:28 +02:00
|
|
|
|
next unless IsDir("$DataDir/$ns");
|
2014-06-19 23:00:18 +02:00
|
|
|
|
print "<br />\n<strong>$ns</strong>" if $ns;
|
2014-06-21 05:49:31 -04:00
|
|
|
|
for my $dirname ($PageDir, $KeepDir, $RefererDir, $JoinerDir, $JoinerEmailDir) {
|
|
|
|
|
|
next unless $dirname;
|
|
|
|
|
|
my $dir = $dirname; # copy in order not to modify the original
|
2014-06-19 23:00:18 +02:00
|
|
|
|
$dir =~ s/^$DataDir/$DataDir\/$ns/ if $ns;
|
2016-06-19 11:55:58 +02:00
|
|
|
|
for my $old (Glob("$dir/*/*"), Glob("$dir/*/.*")) {
|
2014-06-21 05:49:31 -04:00
|
|
|
|
next if $old =~ /\/\.\.?$/;
|
2016-06-22 14:43:28 +02:00
|
|
|
|
print "<br />\n$old";
|
2014-06-19 23:00:18 +02:00
|
|
|
|
my $new = $old;
|
|
|
|
|
|
$new =~ s!/([A-Z]|other)/!/!;
|
|
|
|
|
|
if ($old eq $new) {
|
|
|
|
|
|
print " does not fit the pattern!";
|
2016-06-22 14:43:28 +02:00
|
|
|
|
} elsif (not Rename($old, $new)) {
|
|
|
|
|
|
print " → $new failed!";
|
2014-06-19 23:00:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-06-19 11:55:58 +02:00
|
|
|
|
for my $subdir (grep(/\/([A-Z]|other)$/, Glob("$dir/*"), Glob("$dir/.*"))) {
|
2014-06-26 18:52:21 +02:00
|
|
|
|
next if substr($subdir, -2) eq '/.' or substr($subdir, -3) eq '/..';
|
2016-06-15 23:21:07 +02:00
|
|
|
|
RemoveDir($subdir); # ignore errors
|
2014-06-06 17:32:44 +02:00
|
|
|
|
}
|
2014-06-07 17:08:18 +02:00
|
|
|
|
}
|
2014-06-06 17:32:44 +02:00
|
|
|
|
}
|
2014-06-17 13:14:13 +02:00
|
|
|
|
|
|
|
|
|
|
print $q->end_p();
|
|
|
|
|
|
|
2016-06-22 14:43:28 +02:00
|
|
|
|
if (Rename("$ModuleDir/upgrade.pl", "$ModuleDir/upgrade.done")) {
|
2014-06-17 13:14:13 +02:00
|
|
|
|
print $q->p(T("Upgrade complete."))
|
|
|
|
|
|
} else {
|
|
|
|
|
|
print $q->p(T("Upgrade complete. Please remove $ModuleDir/upgade.pl, now."))
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-06-07 17:08:18 +02:00
|
|
|
|
ReleaseLock();
|
2014-06-17 13:14:13 +02:00
|
|
|
|
|
2014-06-06 17:32:44 +02:00
|
|
|
|
print $q->end_p(), $q->end_div();
|
|
|
|
|
|
PrintFooter();
|
|
|
|
|
|
}
|