From c76829a4e390987aa6b044ef790ac1d74fa9b6b3 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Thu, 17 Feb 2005 01:11:11 +0000 Subject: [PATCH] lots of bug fixes and a new upgrade feature --- docs/changelog/6.x.x.txt | 2 + docs/gotcha.txt | 7 ++++ docs/maintenance.html | 13 +++++++ docs/upgrades/upgrade_6.2.11-6.3.0.pl | 53 +++++++++++++++++++-------- lib/WebGUI.pm | 15 ++++++++ lib/WebGUI/Session.pm | 1 + sbin/runHourly.pl | 5 +++ sbin/upgrade.pl | 19 +++++++++- 8 files changed, 97 insertions(+), 18 deletions(-) create mode 100644 docs/maintenance.html diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index 1280b7576..cf98860b6 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -6,6 +6,8 @@ - Converted site maps to navigation assets. - Converted file managers to layout assets with file and image assets 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 macros. - Added Folder asset type. diff --git a/docs/gotcha.txt b/docs/gotcha.txt index 7b45f9a25..3d8dd793b 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -9,6 +9,13 @@ save you many hours of grief. 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 new versions of those language files before upgrading. The language file format has a new requirement. Also, the diff --git a/docs/maintenance.html b/docs/maintenance.html new file mode 100644 index 000000000..d626843c9 --- /dev/null +++ b/docs/maintenance.html @@ -0,0 +1,13 @@ + + + + Site Down For Maintenance + + +

Maintenance

+

+ This site is currently undergoing maintenance. Please check back again shortly. +

+ + diff --git a/docs/upgrades/upgrade_6.2.11-6.3.0.pl b/docs/upgrades/upgrade_6.2.11-6.3.0.pl index 4c2a60dd7..0de3ca4ed 100644 --- a/docs/upgrades/upgrade_6.2.11-6.3.0.pl +++ b/docs/upgrades/upgrade_6.2.11-6.3.0.pl @@ -171,17 +171,6 @@ walkTree('0','PBasset000000000000001','000001','2'); mapProductCollateral(); 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"); my $sth = WebGUI::SQL->read("select proxiedWobjectId from WobjectProxy"); 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)); } $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 change proxiedTemplateId overrideTemplateId varchar(22) 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})); print "\t\t\tMigrating submissions for USS ".$wobject->{wobjectId}."\n" unless ($quiet); my $ussId = $namespace->{USS_id}; - my $sth = WebGUI::SQL->read("select * from USS_submission where USS_id=".quote($ussId)); my $usssubrank = 1; my $collabReplyCounter; my $collabViewCounter; my $collabThreadCounter; my %oldestForumPost; + my $sth = WebGUI::SQL->read("select * from USS_submission where USS_id=".quote($ussId)); while (my $submission = $sth->hashRef) { $collabThreadCounter++; $collabViewCounter += $submission->{views}; @@ -1662,9 +1666,9 @@ sub walkTree { subscriptionGroupId=>$threadSubscriptionGroup->groupId }, undef, $id); 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 $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) { $collabViewCounter += $post->{views}; $threadReplyCounter++; @@ -1738,6 +1742,7 @@ sub walkTree { WebGUI::SQL->write("update WobjectProxy set description=".quote($wobject->{description})." where assetId=".quote($wobjectId)); } 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 $i = 1; 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 (?,?,?,?,?)"); 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 - forumThread.forumId=".quote($originalId)); + forumThread.forumId=".quote($originalId)." and forumPost.status<>'deleted'"); 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"; my $threadLineage = $lineage.sprintf("%06d",$threadRank); 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 print "\t\t\t\t\t\t Migrating posts for thread ".$thread->{forumThreadId}."\n"; 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; + 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) { + next if ($thread->{forumPostId} eq ""); print "\t\t\t\t\t\t\t Migrating post ".$post->{forumPostId}."\n"; my $postId = WebGUI::SQL->setRow("asset","assetId",{ assetId=>"new", @@ -2026,6 +2041,7 @@ sub migrateForum { $postRank++; } $posts->finish; + print "\t\t\t\t\t\t\t Setting oldest post for thread ".$thread->{forumThreadId}."\n"; WebGUI::SQL->setRow("Thread","assetId",{ assetId=>$threadId, lastPostId=>$oldestThreadPost{id}, @@ -2037,8 +2053,10 @@ sub migrateForum { } $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; $ratingprep->finish; + print "\t\t\t\t\t\t Setting oldest post for forum ".$originalId."\n"; WebGUI::SQL->setRow("Collaboration","assetId",{ assetId=>$newId, lastPostId=>$oldestForumPost{id}, @@ -2049,6 +2067,9 @@ sub migrateForum { sub fixUrl { my $id = shift; my $url = shift; + if (length($url) > 250) { + $url = substr($url,220); + } $url = WebGUI::Id::generate() unless (defined $url); $url = WebGUI::URL::urlize($url); my ($test) = WebGUI::SQL->quickArray("select url from asset where assetId<>".quote($id)." and url=".quote($url)); diff --git a/lib/WebGUI.pm b/lib/WebGUI.pm index eb8790998..5589ad0cc 100644 --- a/lib/WebGUI.pm +++ b/lib/WebGUI.pm @@ -53,6 +53,20 @@ sub _processOperations { return $output; } +#------------------------------------------------------------------- +sub _upgrading { + my $webguiRoot = shift; + my $output = WebGUI::HTTP::getHeader(); + open(FILE,"<".$webguiRoot."/docs/maintenance.html"); + while () { + $output .= $_; + } + close(FILE); + WebGUI::Session::close(); + return $output; +} + + #------------------------------------------------------------------- sub page { my $webguiRoot = shift; @@ -61,6 +75,7 @@ sub page { my $assetUrl = shift; my $fastcgi = shift; WebGUI::Session::open($webguiRoot,$configFile,$fastcgi) unless ($useExistingSession); + return _upgrading($webguiRoot) if ($session{setting}{specialState} eq "upgrading"); my $output = _processOperations(); if ($output eq "") { my $asset = WebGUI::Asset->newByUrl($assetUrl); diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index 47d7d0563..12fa17fdf 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -327,6 +327,7 @@ sub open { $CGI::POST_MAX=-1; $session{cgi} = CGI->new(); } + return if ($session{setting}{specialState} eq "upgrading"); ###---------------------------- ### evironment variables from web server $session{env} = \%ENV; diff --git a/sbin/runHourly.pl b/sbin/runHourly.pl index bd6e2259d..815037dd2 100644 --- a/sbin/runHourly.pl +++ b/sbin/runHourly.pl @@ -84,6 +84,11 @@ if (opendir (CONFDIR,$confdir)) { print "\nProcessing ".$file.":\n" if ($verbose); my $startTime = time(); 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}); foreach $namespace (keys %plugins) { my $taskTime = time(); diff --git a/sbin/upgrade.pl b/sbin/upgrade.pl index 060a6d8bd..2ae60ebdb 100644 --- a/sbin/upgrade.pl +++ b/sbin/upgrade.pl @@ -171,8 +171,12 @@ foreach my $file (@files) { my $dbh = DBI->connect($config{$file}{dsn},$config{$file}{dbuser},$config{$file}{dbpass}); ($config{$file}{version}) = WebGUI::SQL->quickArray("select webguiVersion from webguiVersion 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; - rmtree($config->get("uploadsPath").$slash."temp"); } else { delete $config{$file}; 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); closedir(DIR); 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 ($3 eq "sql") { 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}; $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) {