lots of bug fixes and a new upgrade feature

This commit is contained in:
JT Smith 2005-02-17 01:11:11 +00:00
parent 5e9652d873
commit c76829a4e3
8 changed files with 97 additions and 18 deletions

View file

@ -6,6 +6,8 @@
- Converted site maps to navigation assets. - Converted site maps to navigation assets.
- Converted file managers to layout assets with file and image assets - Converted file managers to layout assets with file and image assets
attached. attached.
- Added a new upgrade mechanism that will display a maintenence message
during upgrades. No need to set up anything special for this any longer.
- Added AssetProxy macro, which replaces the Navigation, I, Snippet, and File - Added AssetProxy macro, which replaces the Navigation, I, Snippet, and File
macros. macros.
- Added Folder asset type. - Added Folder asset type.

View file

@ -9,6 +9,13 @@ save you many hours of grief.
6.3.0 6.3.0
-------------------------------------------------------------------- --------------------------------------------------------------------
* This upgrade process will run for a very long time and output a
lot of debug information which will be useful if something
goes wrong. You may wish to pipe the debug info to a log
file like this:
perl upgrade.pl --yourcommandlineoptions > /tmp/upgrade.log
* If you're using languages other than English, you'll need to get * If you're using languages other than English, you'll need to get
new versions of those language files before upgrading. The new versions of those language files before upgrading. The
language file format has a new requirement. Also, the language file format has a new requirement. Also, the

13
docs/maintenance.html Normal file
View file

@ -0,0 +1,13 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Site Down For Maintenance</title>
</head>
<body>
<h1>Maintenance</h1>
<p>
This site is currently undergoing maintenance. Please check back again shortly.
</p>
</body>
</html>

View file

@ -171,17 +171,6 @@ walkTree('0','PBasset000000000000001','000001','2');
mapProductCollateral(); mapProductCollateral();
print "\t\tMaking second round of table structure changes\n" unless ($quiet); print "\t\tMaking second round of table structure changes\n" unless ($quiet);
foreach my $namespace (@allWobjects) {
if (isIn($namespace, @wobjects)) {
WebGUI::SQL->write("alter table ".$namespace." drop column wobjectId");
WebGUI::SQL->write("alter table ".$namespace." add primary key (assetId)");
} elsif (isIn($namespace, qw(Navigation Layout))) {
# do nothing
} else {
WebGUI::SQL->write("alter table ".$namespace." drop primary key");
WebGUI::SQL->write("alter table ".$namespace." add primary key (assetId)");
}
}
WebGUI::SQL->write("alter table WobjectProxy add column shortcutToAssetId varchar(22) not null"); WebGUI::SQL->write("alter table WobjectProxy add column shortcutToAssetId varchar(22) not null");
my $sth = WebGUI::SQL->read("select proxiedWobjectId from WobjectProxy"); my $sth = WebGUI::SQL->read("select proxiedWobjectId from WobjectProxy");
while (my ($wobjectId) = $sth->array) { while (my ($wobjectId) = $sth->array) {
@ -189,6 +178,21 @@ while (my ($wobjectId) = $sth->array) {
WebGUI::SQL->write("update WobjectProxy set shortcutToAssetId=".quote($assetId)." where wobjectId=".quote($wobjectId)); WebGUI::SQL->write("update WobjectProxy set shortcutToAssetId=".quote($assetId)." where wobjectId=".quote($wobjectId));
} }
$sth->finish; $sth->finish;
foreach my $namespace (@allWobjects) {
if (isIn($namespace, qw(SiteMap USS FileManager))) {
# do nothing because these are going away
} elsif (isIn($namespace, @wobjects)) {
WebGUI::SQL->write("delete from ".$namespace." where assetId is null or assetId = ''"); # protect ourselves from crap
WebGUI::SQL->write("alter table ".$namespace." drop column wobjectId");
WebGUI::SQL->write("alter table ".$namespace." add primary key (assetId)");
} elsif (isIn($namespace, qw(Navigation Layout Collaboration Folder))) {
# do nothing because these are new
} else {
WebGUI::SQL->write("delete from ".$namespace." where assetId is null or assetId = ''"); # protect ourselves from crap
WebGUI::SQL->write("alter table ".$namespace." drop primary key");
WebGUI::SQL->write("alter table ".$namespace." add primary key (assetId)");
}
}
WebGUI::SQL->write("alter table WobjectProxy drop proxiedWobjectId"); WebGUI::SQL->write("alter table WobjectProxy drop proxiedWobjectId");
WebGUI::SQL->write("alter table WobjectProxy change proxiedTemplateId overrideTemplateId varchar(22) not null"); WebGUI::SQL->write("alter table WobjectProxy change proxiedTemplateId overrideTemplateId varchar(22) not null");
WebGUI::SQL->write("alter table WobjectProxy change proxyByCriteria shortcutByCriteria int not null"); WebGUI::SQL->write("alter table WobjectProxy change proxyByCriteria shortcutByCriteria int not null");
@ -1598,12 +1602,12 @@ sub walkTree {
WebGUI::SQL->write("update wobject set namespace='Collaboration' where wobjectId=".quote($wobject->{wobjectId})); WebGUI::SQL->write("update wobject set namespace='Collaboration' where wobjectId=".quote($wobject->{wobjectId}));
print "\t\t\tMigrating submissions for USS ".$wobject->{wobjectId}."\n" unless ($quiet); print "\t\t\tMigrating submissions for USS ".$wobject->{wobjectId}."\n" unless ($quiet);
my $ussId = $namespace->{USS_id}; my $ussId = $namespace->{USS_id};
my $sth = WebGUI::SQL->read("select * from USS_submission where USS_id=".quote($ussId));
my $usssubrank = 1; my $usssubrank = 1;
my $collabReplyCounter; my $collabReplyCounter;
my $collabViewCounter; my $collabViewCounter;
my $collabThreadCounter; my $collabThreadCounter;
my %oldestForumPost; my %oldestForumPost;
my $sth = WebGUI::SQL->read("select * from USS_submission where USS_id=".quote($ussId));
while (my $submission = $sth->hashRef) { while (my $submission = $sth->hashRef) {
$collabThreadCounter++; $collabThreadCounter++;
$collabViewCounter += $submission->{views}; $collabViewCounter += $submission->{views};
@ -1662,9 +1666,9 @@ sub walkTree {
subscriptionGroupId=>$threadSubscriptionGroup->groupId subscriptionGroupId=>$threadSubscriptionGroup->groupId
}, undef, $id); }, undef, $id);
my %oldestThreadPost; my %oldestThreadPost;
my $posts = WebGUI::SQL->read("select forumPost.* from forumPost left join forumThread on forumPost.forumThreadId=forumThread.forumThreadId where forumId=".quote($submission->{forumId}));
my $postRank = 1; my $postRank = 1;
my $threadReplyCounter; my $threadReplyCounter;
my $posts = WebGUI::SQL->read("select forumPost.* from forumPost left join forumThread on forumPost.forumThreadId=forumThread.forumThreadId where forumId=".quote($submission->{forumId}));
while (my $post = $posts->hashRef) { while (my $post = $posts->hashRef) {
$collabViewCounter += $post->{views}; $collabViewCounter += $post->{views};
$threadReplyCounter++; $threadReplyCounter++;
@ -1738,6 +1742,7 @@ sub walkTree {
WebGUI::SQL->write("update WobjectProxy set description=".quote($wobject->{description})." where WebGUI::SQL->write("update WobjectProxy set description=".quote($wobject->{description})." where
assetId=".quote($wobjectId)); assetId=".quote($wobjectId));
} elsif ($wobject->{namespace} eq "MessageBoard") { } elsif ($wobject->{namespace} eq "MessageBoard") {
print "\t\t\tMigrating Message Board forums\n" unless ($quiet);
my $forums = WebGUI::SQL->read("select forumId, title, description from MessageBoard_forums where wobjectId=".quote($wobject->{wobjectId})." order by sequenceNumber"); my $forums = WebGUI::SQL->read("select forumId, title, description from MessageBoard_forums where wobjectId=".quote($wobject->{wobjectId})." order by sequenceNumber");
my $i = 1; my $i = 1;
while (my ($fid, $title, $desc) = $forums->array) { while (my ($fid, $title, $desc) = $forums->array) {
@ -1921,9 +1926,14 @@ sub migrateForum {
my $ratingprep = WebGUI::SQL->prepare("insert into Post_rating (assetId, userId, ipAddress, dateOfRating, rating) values (?,?,?,?,?)"); my $ratingprep = WebGUI::SQL->prepare("insert into Post_rating (assetId, userId, ipAddress, dateOfRating, rating) values (?,?,?,?,?)");
print "\t\t\t\t\t Migrating threads for forum $originalId\n"; print "\t\t\t\t\t Migrating threads for forum $originalId\n";
my $threads = WebGUI::SQL->read("select * from forumThread left join forumPost on forumThread.rootPostId=forumPost.forumPostId where my $threads = WebGUI::SQL->read("select * from forumThread left join forumPost on forumThread.rootPostId=forumPost.forumPostId where
forumThread.forumId=".quote($originalId)); forumThread.forumId=".quote($originalId)." and forumPost.status<>'deleted'");
my $threadRank = 1; my $threadRank = 1;
while (my ($thread) = $threads->hashRef) { if ($threads->errorCode>0) {
print "\t\t\t\tWARNING: There was a problem migrating the threads for $originalId\n";
return;
}
while (($threads->errorCode < 1) && (my ($thread) = $threads->hashRef)) {
next if ($thread->{forumThreadId} eq "");
print "\t\t\t\t\t\t Migrating thread ".$thread->{forumThreadId}."\n"; print "\t\t\t\t\t\t Migrating thread ".$thread->{forumThreadId}."\n";
my $threadLineage = $lineage.sprintf("%06d",$threadRank); my $threadLineage = $lineage.sprintf("%06d",$threadRank);
my $threadId = WebGUI::SQL->setRow("asset","assetId",{ my $threadId = WebGUI::SQL->setRow("asset","assetId",{
@ -1979,9 +1989,14 @@ sub migrateForum {
# we're going to give up hierarchy during the upgrade for the sake of simplicity # we're going to give up hierarchy during the upgrade for the sake of simplicity
print "\t\t\t\t\t\t Migrating posts for thread ".$thread->{forumThreadId}."\n"; print "\t\t\t\t\t\t Migrating posts for thread ".$thread->{forumThreadId}."\n";
my %oldestThreadPost; my %oldestThreadPost;
my $posts = WebGUI::SQL->read("select * from forumPost where forumThreadId=".quote($thread->{forumThreadId})." and parentId<>''"); my $posts = WebGUI::SQL->read("select * from forumPost where forumThreadId=".quote($thread->{forumThreadId})." and parentId<>'' and forumPost.status<>'deleted'");
my $postRank = 1; my $postRank = 1;
if ($posts->errorCode>0) {
print "\t\t\t\tWARNING: There was a problem migrating the posts for ".$thread->{forumThreadId}."\n";
next;
}
while (my $post = $posts->hashRef) { while (my $post = $posts->hashRef) {
next if ($thread->{forumPostId} eq "");
print "\t\t\t\t\t\t\t Migrating post ".$post->{forumPostId}."\n"; print "\t\t\t\t\t\t\t Migrating post ".$post->{forumPostId}."\n";
my $postId = WebGUI::SQL->setRow("asset","assetId",{ my $postId = WebGUI::SQL->setRow("asset","assetId",{
assetId=>"new", assetId=>"new",
@ -2026,6 +2041,7 @@ sub migrateForum {
$postRank++; $postRank++;
} }
$posts->finish; $posts->finish;
print "\t\t\t\t\t\t\t Setting oldest post for thread ".$thread->{forumThreadId}."\n";
WebGUI::SQL->setRow("Thread","assetId",{ WebGUI::SQL->setRow("Thread","assetId",{
assetId=>$threadId, assetId=>$threadId,
lastPostId=>$oldestThreadPost{id}, lastPostId=>$oldestThreadPost{id},
@ -2037,8 +2053,10 @@ sub migrateForum {
} }
$threadRank++; $threadRank++;
} }
print "\t\t\t\t WARNING: Couldn't finish processing threads for $originalId because something nasty occured in the database." if ($threads->errorCode > 0);
$threads->finish; $threads->finish;
$ratingprep->finish; $ratingprep->finish;
print "\t\t\t\t\t\t Setting oldest post for forum ".$originalId."\n";
WebGUI::SQL->setRow("Collaboration","assetId",{ WebGUI::SQL->setRow("Collaboration","assetId",{
assetId=>$newId, assetId=>$newId,
lastPostId=>$oldestForumPost{id}, lastPostId=>$oldestForumPost{id},
@ -2049,6 +2067,9 @@ sub migrateForum {
sub fixUrl { sub fixUrl {
my $id = shift; my $id = shift;
my $url = shift; my $url = shift;
if (length($url) > 250) {
$url = substr($url,220);
}
$url = WebGUI::Id::generate() unless (defined $url); $url = WebGUI::Id::generate() unless (defined $url);
$url = WebGUI::URL::urlize($url); $url = WebGUI::URL::urlize($url);
my ($test) = WebGUI::SQL->quickArray("select url from asset where assetId<>".quote($id)." and url=".quote($url)); my ($test) = WebGUI::SQL->quickArray("select url from asset where assetId<>".quote($id)." and url=".quote($url));

View file

@ -53,6 +53,20 @@ sub _processOperations {
return $output; return $output;
} }
#-------------------------------------------------------------------
sub _upgrading {
my $webguiRoot = shift;
my $output = WebGUI::HTTP::getHeader();
open(FILE,"<".$webguiRoot."/docs/maintenance.html");
while (<FILE>) {
$output .= $_;
}
close(FILE);
WebGUI::Session::close();
return $output;
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub page { sub page {
my $webguiRoot = shift; my $webguiRoot = shift;
@ -61,6 +75,7 @@ sub page {
my $assetUrl = shift; my $assetUrl = shift;
my $fastcgi = shift; my $fastcgi = shift;
WebGUI::Session::open($webguiRoot,$configFile,$fastcgi) unless ($useExistingSession); WebGUI::Session::open($webguiRoot,$configFile,$fastcgi) unless ($useExistingSession);
return _upgrading($webguiRoot) if ($session{setting}{specialState} eq "upgrading");
my $output = _processOperations(); my $output = _processOperations();
if ($output eq "") { if ($output eq "") {
my $asset = WebGUI::Asset->newByUrl($assetUrl); my $asset = WebGUI::Asset->newByUrl($assetUrl);

View file

@ -327,6 +327,7 @@ sub open {
$CGI::POST_MAX=-1; $CGI::POST_MAX=-1;
$session{cgi} = CGI->new(); $session{cgi} = CGI->new();
} }
return if ($session{setting}{specialState} eq "upgrading");
###---------------------------- ###----------------------------
### evironment variables from web server ### evironment variables from web server
$session{env} = \%ENV; $session{env} = \%ENV;

View file

@ -84,6 +84,11 @@ if (opendir (CONFDIR,$confdir)) {
print "\nProcessing ".$file.":\n" if ($verbose); print "\nProcessing ".$file.":\n" if ($verbose);
my $startTime = time(); my $startTime = time();
WebGUI::Session::open($webguiRoot,$file); WebGUI::Session::open($webguiRoot,$file);
if ($session{setting}{specialState} eq "upgrading") {
print "\nSkipping because this site is undergoing an upgrade.\n" if ($verbose);
WebGUI::Session::close();
next;
}
WebGUI::Session::refreshUserInfo(3,$session{dbh}); WebGUI::Session::refreshUserInfo(3,$session{dbh});
foreach $namespace (keys %plugins) { foreach $namespace (keys %plugins) {
my $taskTime = time(); my $taskTime = time();

View file

@ -171,8 +171,12 @@ foreach my $file (@files) {
my $dbh = DBI->connect($config{$file}{dsn},$config{$file}{dbuser},$config{$file}{dbpass}); my $dbh = DBI->connect($config{$file}{dsn},$config{$file}{dbuser},$config{$file}{dbpass});
($config{$file}{version}) = WebGUI::SQL->quickArray("select webguiVersion from webguiVersion ($config{$file}{version}) = WebGUI::SQL->quickArray("select webguiVersion from webguiVersion
order by dateApplied desc, webguiVersion desc limit 1",$dbh); order by dateApplied desc, webguiVersion desc limit 1",$dbh);
unless ($history) {
print "\tPreparing site for upgrade.\n" unless ($quiet);
$dbh->do("replace into settings (name,value) values ('specialState','upgrading')") unless ($history);
rmtree($config->get("uploadsPath").$slash."temp");
}
$dbh->disconnect; $dbh->disconnect;
rmtree($config->get("uploadsPath").$slash."temp");
} else { } else {
delete $config{$file}; delete $config{$file};
print "\tSkipping non-MySQL database.\n" unless ($quiet); print "\tSkipping non-MySQL database.\n" unless ($quiet);
@ -206,7 +210,7 @@ opendir(DIR,$upgradesPath) or die "Couldn't open $upgradesPath\n";
my @files = readdir(DIR); my @files = readdir(DIR);
closedir(DIR); closedir(DIR);
foreach my $file (@files) { foreach my $file (@files) {
if ($file =~ /upgrade_(\d+\.\d+\.\d+)-(\d+\.\d+\.\d+)\.(\w+)/) { if ($file =~ /^upgrade_(\d+\.\d+\.\d+)-(\d+\.\d+\.\d+)\.(pl|sql)$/) {
if (checkVersion($1)) { if (checkVersion($1)) {
if ($3 eq "sql") { if ($3 eq "sql") {
print "\tFound upgrade script from $1 to $2.\n" unless ($quiet); print "\tFound upgrade script from $1 to $2.\n" unless ($quiet);
@ -270,6 +274,17 @@ foreach my $config (keys %config) {
$config{$config}{version} = $upgrade{$upgrade}{to}; $config{$config}{version} = $upgrade{$upgrade}{to};
$notRun = 0; $notRun = 0;
} }
print "\tSetting site upgrade completed..." unless ($quiet);
my $cmd = $clicmd." -u".$config{$config}{dbuser}." -p".$config{$config}{dbpass};
$cmd .= " --host=".$config{$config}{host} if ($config{$config}{host});
$cmd .= " --port=".$config{$config}{port} if ($config{$config}{port});
$cmd .= " --database=".$config{$config}{db}." -e \"delete from settings where name='upgrading'\"";
unless (system($cmd)) {
print "OK\n" unless ($quiet);
} else {
print "Failed!\n" unless ($quiet);
fatalError();
}
} }
if ($notRun) { if ($notRun) {