changed upgrade to use WebGUI::Setting API

This commit is contained in:
JT Smith 2005-09-10 18:06:41 +00:00
parent 62d1c58ae4
commit 1a841c60f9

View file

@ -20,6 +20,8 @@ use File::Path;
use Getopt::Long; use Getopt::Long;
use strict; use strict;
use WebGUI::Config; use WebGUI::Config;
use WebGUI::Session;
use WebGUI::Setting;
use WebGUI::SQL; use WebGUI::SQL;
my $help; my $help;
@ -164,8 +166,11 @@ foreach my $filename (keys %{$configs}) {
order by dateApplied desc, webguiVersion desc limit 1",$dbh); order by dateApplied desc, webguiVersion desc limit 1",$dbh);
unless ($history) { unless ($history) {
print "\tPreparing site for upgrade.\n" unless ($quiet); print "\tPreparing site for upgrade.\n" unless ($quiet);
$dbh->do("replace into settings (name,value) values ('specialState','upgrading')") unless ($history); WebGUI::Session::open($webguiRoot,$filename);
rmtree($configs->{$filename}{uploadsPath}.$slash."temp"); WebGUI::Setting::remove('specialState');
WebGUI::Setting::add('specialState','upgrading');
WebGUI::Session::close();
rmtree($configs->{$filename}{uploadsPath}.$slash."temp");
} }
$dbh->disconnect; $dbh->disconnect;
} else { } else {
@ -220,21 +225,21 @@ print "\nREADY TO BEGIN UPGRADES\n" unless ($quiet);
my $notRun = 1; my $notRun = 1;
chdir($upgradesPath); chdir($upgradesPath);
foreach my $config (keys %config) { foreach my $filename (keys %config) {
my $clicmd = $config{$config}{mysqlCLI} || $mysql; my $clicmd = $config{$filename}{mysqlCLI} || $mysql;
my $dumpcmd = $config{$config}{mysqlDump} || $mysqldump; my $dumpcmd = $config{$filename}{mysqlDump} || $mysqldump;
my $backupTo = $config{$config}{backupPath} || $backupDir; my $backupTo = $config{$filename}{backupPath} || $backupDir;
mkdir($backupTo); mkdir($backupTo);
while ($upgrade{$config{$config}{version}}{sql} ne "" || $upgrade{$config{$config}{version}}{pl} ne "") { while ($upgrade{$config{$filename}{version}}{sql} ne "" || $upgrade{$config{$filename}{version}}{pl} ne "") {
my $upgrade = $upgrade{$config{$config}{version}}{from}; my $upgrade = $upgrade{$config{$filename}{version}}{from};
unless ($skipBackup) { unless ($skipBackup) {
print "\n".$config{$config}{db}." ".$upgrade{$upgrade}{from}."-".$upgrade{$upgrade}{to}."\n" unless ($quiet); print "\n".$config{$filename}{db}." ".$upgrade{$upgrade}{from}."-".$upgrade{$upgrade}{to}."\n" unless ($quiet);
print "\tBacking up $config{$config}{db} ($upgrade{$upgrade}{from})..." unless ($quiet); print "\tBacking up $config{$filename}{db} ($upgrade{$upgrade}{from})..." unless ($quiet);
my $cmd = $dumpcmd." -u".$config{$config}{dbuser}." -p".$config{$config}{dbpass}; my $cmd = $dumpcmd." -u".$config{$filename}{dbuser}." -p".$config{$filename}{dbpass};
$cmd .= " --host=".$config{$config}{host} if ($config{$config}{host}); $cmd .= " --host=".$config{$filename}{host} if ($config{$filename}{host});
$cmd .= " --port=".$config{$config}{port} if ($config{$config}{port}); $cmd .= " --port=".$config{$filename}{port} if ($config{$filename}{port});
$cmd .= " --add-drop-table --databases ".$config{$config}{db}." > " $cmd .= " --add-drop-table --databases ".$config{$filename}{db}." > "
.$backupTo.$slash.$config{$config}{db}."_".$upgrade{$upgrade}{from}.".sql"; .$backupTo.$slash.$config{$filename}{db}."_".$upgrade{$upgrade}{from}.".sql";
unless (system($cmd)) { unless (system($cmd)) {
print "OK\n" unless ($quiet); print "OK\n" unless ($quiet);
} else { } else {
@ -244,10 +249,10 @@ foreach my $config (keys %config) {
} }
if ($upgrade{$upgrade}{sql} ne "") { if ($upgrade{$upgrade}{sql} ne "") {
print "\tUpgrading to ".$upgrade{$upgrade}{to}."..." unless ($quiet); print "\tUpgrading to ".$upgrade{$upgrade}{to}."..." unless ($quiet);
my $cmd = $clicmd." -u".$config{$config}{dbuser}." -p".$config{$config}{dbpass}; my $cmd = $clicmd." -u".$config{$filename}{dbuser}." -p".$config{$filename}{dbpass};
$cmd .= " --host=".$config{$config}{host} if ($config{$config}{host}); $cmd .= " --host=".$config{$filename}{host} if ($config{$filename}{host});
$cmd .= " --port=".$config{$config}{port} if ($config{$config}{port}); $cmd .= " --port=".$config{$filename}{port} if ($config{$filename}{port});
$cmd .= " --database=".$config{$config}{db}." < ".$upgrade{$upgrade}{sql}; $cmd .= " --database=".$config{$filename}{db}." < ".$upgrade{$upgrade}{sql};
unless (system($cmd)) { unless (system($cmd)) {
print "OK\n" unless ($quiet); print "OK\n" unless ($quiet);
} else { } else {
@ -256,27 +261,21 @@ foreach my $config (keys %config) {
} }
} }
if ($upgrade{$upgrade}{pl} ne "") { if ($upgrade{$upgrade}{pl} ne "") {
my $cmd = $perl." ".$upgrade{$upgrade}{pl}." --configFile=".$config; my $cmd = $perl." ".$upgrade{$upgrade}{pl}." --configFile=".$filename;
$cmd .= " --quiet" if ($quiet); $cmd .= " --quiet" if ($quiet);
if (system($cmd)) { if (system($cmd)) {
print "\tProcessing upgrade executable failed!\n"; print "\tProcessing upgrade executable failed!\n";
fatalError(); fatalError();
} }
} }
$config{$config}{version} = $upgrade{$upgrade}{to}; $config{$filename}{version} = $upgrade{$upgrade}{to};
$notRun = 0; $notRun = 0;
} }
WebGUI::Session::open("../..",$filename);
print "\tSetting site upgrade completed..." unless ($quiet); print "\tSetting site upgrade completed..." unless ($quiet);
my $cmd = $clicmd." -u".$config{$config}{dbuser}." -p".$config{$config}{dbpass}; WebGUI::Setting::remove('specialState');
$cmd .= " --host=".$config{$config}{host} if ($config{$config}{host}); WebGUI::Session::close();
$cmd .= " --port=".$config{$config}{port} if ($config{$config}{port}); print "OK\n" unless ($quiet);
$cmd .= " --database=".$config{$config}{db}." -e \"delete from settings where name='specialState'\"";
unless (system($cmd)) {
print "OK\n" unless ($quiet);
} else {
print "Failed!\n" unless ($quiet);
fatalError();
}
} }
if ($notRun) { if ($notRun) {