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 644b6f85d..a2e1d991e 100644 --- a/docs/upgrades/upgrade_6.2.11-6.3.0.pl +++ b/docs/upgrades/upgrade_6.2.11-6.3.0.pl @@ -123,7 +123,6 @@ WebGUI::SQL->write("alter table Product_related add assetId varchar(22) not null WebGUI::SQL->write("alter table Product_related add relatedAssetId varchar(22) not null"); WebGUI::SQL->write("alter table Product_related add primary key (assetId,relatedAssetId)"); WebGUI::SQL->write("alter table WobjectProxy add column description mediumtext"); -WebGUI::SQL->write("alter table forum add assetId varchar(22) not null"); @@ -230,9 +229,14 @@ WebGUI::SQL->write("alter table Product_related drop column wobjectId"); WebGUI::SQL->write("alter table Product_specification drop column wobjectId"); WebGUI::SQL->write("alter table Product_related drop column RelatedWobjectId"); WebGUI::SQL->write("alter table Product_accessory drop column AccessoryWobjectId"); -WebGUI::SQL->write("alter table forum drop column forumId"); -WebGUI::SQL->write("alter table forum drop column groupToView"); - +WebGUI::SQL->write("drop table forum"); +WebGUI::SQL->write("drop table forumRead"); +WebGUI::SQL->write("drop table forumPost"); +WebGUI::SQL->write("drop table forumPostRating"); +WebGUI::SQL->write("drop table forumPostAttachment"); +WebGUI::SQL->write("drop table forumSubscription"); +WebGUI::SQL->write("drop table forumThread"); +WebGUI::SQL->write("drop table forumThreadSubscription"); # start migrating non-wobject stuff into assets my %migration; @@ -1066,7 +1070,13 @@ sub walkTree { WebGUI::SQL->write("insert into ImageAsset (assetId, thumbnailSize) values (".quote($imageId).", ".quote($session{setting}{thumbnailSize}).")"); } - # migrate forums + if ($namespace->{allowDiscussion}) { + print "\t\t\tMigrating forum for Article ".$wobject->{wobjectId}."\n" unless ($quiet); + $rank++; + migrateForum($wobject->{forumId},$pageId,$pageLineage,$rank, $wobject->{title},$wobject->{description}, + $wobject->{startDate}, $wobject->{endDate}, $wobject->{ownerId}, $wobject->{groupIdView}, + $wobject->{groupIdView},$page->{styleId}, $page->{printableStyleId}); + } rmtree($session{config}{uploadsPath}.'/'.$wobject->{wobjectId}); } elsif ($wobject->{namespace} eq "SiteMap") { print "\t\t\tConverting SiteMap ".$wobject->{wobjectId}." into Navigation\n" unless ($quiet); @@ -1241,7 +1251,234 @@ sub walkTree { } - +sub migrateForum { + my $originalId = shift; + my $newParentId = shift; + my $newParentLineage = shift; + my $rank = shift; + my $title = shift; + my $description = shift; + my $startDate = shift; + my $endDate = shift; + my $userId = shift; + my $viewGroup = shift; + my $editGroup = shift; + my $styleId = shift; + my $printId = shift; + my $lineage = $newParentLineage.sprintf("%06d",$rank); + my $data = WebGUI::SQL->quickHashRef("select * from forum where forumId=".quote($originalId)); + if ($data->{masterForumId}) { + my $master = WebGUI::SQL->quickHashRef("select * from forum where forumId=".quote($data->{masterForumId})); + $data->{forumTemplateId} = $master->{forumTemplateId}; + $data->{threadTemplateId} = $master->{threadTemplateId}; + $data->{postTemplateId} = $master->{postTemplateId}; + $data->{searchTemplateId} = $master->{searchTemplateId}; + $data->{notificationTemplateId} = $master->{notificationTemplateId}; + $data->{postFormTemplateId} = $master->{postFormTemplateId}; + $data->{postPreviewTemplateId} = $master->{postPreviewTemplateId}; + $data->{archiveAfter} = $master->{archiveAfter}; + $data->{allowRichEdit} = $master->{allowRichEdit}; + $data->{allowReplacements} = $master->{allowReplacements}; + $data->{filterPosts} = $master->{filterPosts}; + $data->{karmaPerPost} = $master->{karmaPerPost}; + $data->{groupToView} = $master->{groupToView}; + $data->{groupToPost} = $master->{groupToPost}; + $data->{groupToView} = $master->{groupToView}; + $data->{groupToModerate} = $master->{groupToModerate}; + $data->{moderatePosts} = $master->{moderatePosts}; + $data->{attachmentsPerPost} = $master->{attachmentsPerPost}; + $data->{addEditStampToPosts} = $master->{addEditStampsToPost}; + $data->{postsPerPage} = $master->{postsPerPage}; + $data->{usePreview} = $master->{usePreview}; + } + my $newId = WebGUI::SQL->setRow("asset","assetId",{ + assetId=>"new", + parentId=>$newParentId, + lineage=>$lineage, + state=>'published', + className=>'WebGUI::Asset::Wobject::Collaboration', + title=>$title, + menuTitle=>$title, + url=>fixUrl("noneyet",$title), + startDate=>$startDate, + endDate=>$endDate, + ownerUserId=>$userId, + groupIdView=>$viewGroup, + groupIdEdit=>$editGroup, + isHidden=>1, + lastUpdated=>time(), + lastUpdatedBy=>'3'}); + WebGUI::SQL->setRow("wobject","assetId",{ + assetId=>$newId, + description=>$description, + styleTemplateId=>$styleId, + printableStyleTemplateId=>$printId + },undef,$newId); + my $subscriptionGroup = WebGUI::Group->new("new"); + $subscriptionGroup->description("The group to store subscriptions for the collaboration system $newId"); + $subscriptionGroup->name($newId); + $subscriptionGroup->showInForms(0); + $subscriptionGroup->isEditable(0); + $subscriptionGroup->deleteGroups(['3']); + my $sth = WebGUI::SQL->read("select userId from forumSubscription where forumId=".quote($originalId)); + my @users; + while (my ($uid) = $sth->array) { + push(@users,$uid); + } + $sth->finish; + $subscriptionGroup->addUsers(\@users); + WebGUI::SQL->setRow("Collaboration","assetId", { + postGroupId=>$data->{groupToPost}, + moderateGroupId=>$data->{groupToModerate}, + moderatePosts=>$data->{moderatePosts}, + karmaPerPost=>$data->{karmaPerPost}, + collaborationTemplateId=>$data->{forumTemplateId}, + threadTemplateId=>$data->{threadTemplateId}, + postFormTemplateId=>$data->{postformTemplateId}, + searchTemplateId=>$data->{searchTemplateId}, + notificationTemplateId=>$data->{notificationTemplateId}, + sortBy=>$data->{sortBy}, + sortOrder=>$data->{sortOrder}, + usePreview=>$data->{usePreview}, + addEditStampToPosts=>$data->{addEditStampToPosts}, + editTimeout=>$data->{editTimeout}, + attachmentsPerPost=>$data->{attachmentsPerPost}, + allowRichEdit=>$data->{allowRichEdit}, + filterCode=>$data->{filterPosts}, + useContentFilter=>$data->{allowReplacements}, + threads=>$data->{threads}, + views=>$data->{views}, + replies=>$data->{replies}, + rating=>$data->{rating}, + archiveAfter=>$data->{archiveAfter}, + postsPerPage=>$data->{postsPerPage}, + threadsPerPage=>$data->{threadsPerPage}, + subscriptionGroupId=>$subscriptionGroup->groupId, + allowReplies=>1 + },undef,$newId); + my %oldestForumPost; + my $ratingprep = WebGUI::SQL->prepare("insert into Post_rating (assetId, userId, ipAddress, dateOfRating, rating) values (?,?,?,?,?)"); + my $threads = WebGUI::SQL->read("select * from forumThread left join forumPost on forumThread.rootPostId=forumPost.forumPostId where + forumThread.forumId=".quote($originalId)); + my $threadRank = 1; + while (my ($thread) = $threads->hashRef) { + my $threadLineage = $lineage.sprintf("%06d",$threadRank); + my $threadId = WebGUI::SQL->setRow("asset","assetId",{ + assetId=>"new", + parentId=>$newId, + lineage=>$threadLineage, + state=>'published', + className=>'WebGUI::Asset::Post::Thread', + title=>$thread->{subject}, + menuTitle=>$thread->{subject}, + url=>fixUrl("noneyet",$title.'/'.$thread->{subject}), + startDate=>$startDate, + endDate=>$endDate, + ownerUserId=>$thread->{userId}, + groupIdView=>$viewGroup, + groupIdEdit=>$editGroup, + isHidden=>1, + lastUpdated=>$thread->{dateOfPost}, + lastUpdatedBy=>$thread->{userId} + }); + WebGUI::SQL->setRow("Post","assetId",{ + assetId=>$threadId, + threadId=>$threadId, + dateSubmitted=>$thread->{dateOfPost}, + dateUpdated=>$thread->{dateOfPost}, + username=>$thread->{username}, + content=>$thread->{message}, + status=>$thread->{status}, + views=>$thread->{views}, + contentType=>$thread->{contentType}, + rating=>$thread->{rating} + },undef,$threadId); + my $threadSubscriptionGroup = WebGUI::Group->new("new"); + $threadSubscriptionGroup->description("The group to store subscriptions for the thread $threadId"); + $threadSubscriptionGroup->name($threadId); + $threadSubscriptionGroup->showInForms(0); + $threadSubscriptionGroup->isEditable(0); + $threadSubscriptionGroup->deleteGroups(['3']); + my $sth = WebGUI::SQL->read("select userId from forumThreadSubscription where forumThreadId=".quote($thread->{forumThreadId})); + my @users; + while (my ($uid) = $sth->array) { + push(@users,$uid); + } + $sth->finish; + $threadSubscriptionGroup->addUsers(\@users); + WebGUI::SQL->setRow("Thread","assetId",{ + assetId=>$threadId, + replies=>$thread->{replies}, + isLocked=>$thread->{isLocked}, + isSticky=>$thread->{isSticky}, + subscriptionGroupId=>$threadSubscriptionGroup->groupId + }, undef, $threadId); + # we're going to give up hierarchy during the upgrade for the sake of simplicity + my %oldestThreadPost; + my $posts = WebGUI::SQL->read("select * from forumPost where forumThreadId=".quote($thread->{forumThreadId})." and parentId<>''"); + my $postRank = 1; + while (my $post = $posts->hashRef) { + my $postId = WebGUI::SQL->setRow("asset","assetId",{ + assetId=>"new", + parentId=>$threadId, + lineage=>$threadLineage.sprintf("%06d",$postRank), + state=>'published', + className=>'WebGUI::Asset::Post', + title=>$post->{subject}, + menuTitle=>$post->{subject}, + url=>fixUrl("noneyet",$title.'/'.$thread->{subject}.'/'.$post->{subject}), + startDate=>$startDate, + endDate=>$endDate, + ownerUserId=>$post->{userId}, + groupIdView=>$viewGroup, + groupIdEdit=>$editGroup, + isHidden=>1, + lastUpdated=>$post->{dateOfPost}, + lastUpdatedBy=>$post->{userId} + }); + if ($oldestThreadPost{date} < $post->{dateOfPost}) { + $oldestThreadPost{date} = $post->{dateOfPost}; + $oldestThreadPost{id} = $postId; + } + WebGUI::SQL->setRow("Post","assetId",{ + assetId=>$postId, + threadId=>$threadId, + dateSubmitted=>$post->{dateOfPost}, + dateUpdated=>$post->{dateOfPost}, + username=>$post->{username}, + content=>$post->{message}, + status=>$post->{status}, + views=>$post->{views}, + contentType=>$post->{contentType}, + rating=>$post->{rating} + },undef,$postId); + my $sth = WebGUI::SQL->read("select userId,ipAddress,dateOfRating,rating from forumPostRating where forumPostId=".$post->{forumPostId}); + while (my ($uid,$ip,$date,$rating) = $sth->array) { + $ratingprep->execute($postId,$uid,$ip,$date,$rating); + } + $sth->finish; + $postRank++; + } + $posts->finish; + WebGUI::SQL->setRow("Thread","assetId",{ + assetId=>$threadId, + lastPostId=>$oldestThreadPost{id}, + lastPostDate=>$oldestThreadPost{date} + }); + if ($oldestForumPost{date} < $oldestThreadPost{date}) { + $oldestForumPost{date} = $oldestThreadPost{date}; + $oldestForumPost{id} = $oldestThreadPost{id}; + } + $threadRank++; + } + $threads->finish; + $ratingprep->finish; + WebGUI::SQL->setRow("Collaboration","assetId",{ + assetId=>$newId, + lastPostId=>$oldestForumPost{id}, + lastPostDate=>$oldestForumPost{date} + }); +} sub fixUrl { my $id = shift; diff --git a/docs/upgrades/upgrade_6.2.11-6.3.0.sql b/docs/upgrades/upgrade_6.2.11-6.3.0.sql index 63f1238b2..61559dea9 100644 --- a/docs/upgrades/upgrade_6.2.11-6.3.0.sql +++ b/docs/upgrades/upgrade_6.2.11-6.3.0.sql @@ -48,7 +48,6 @@ create table asset ( lineage varchar(255) not null, state varchar(35) not null, className varchar(255) not null, - boundToId varchar(22), title varchar(255) not null default 'untitled', menuTitle varchar(255) not null default 'untitled', url varchar(255) not null, diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 795c3d42a..0a1400f1a 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1848,14 +1848,6 @@ sub purge { } WebGUI::SQL->write("delete from metaData_values where assetId = ".quote($self->getId)); WebGUI::SQL->commit; - # eliminate anything bound to this asset - my $sth = WebGUI::SQL->read("select assetId,className from asset where boundToId=".quote($self->getId)); - while (my ($id, $class) = $sth->array) { - my $asset = WebGUI::Asset->newByDynamicClass($id,$class); - if (defined $asset) { - $asset->purgeTree; - } - } $self = undef; return 1; } diff --git a/lib/WebGUI/Asset/Post/Thread.pm b/lib/WebGUI/Asset/Post/Thread.pm index bb9a50b25..b75055944 100644 --- a/lib/WebGUI/Asset/Post/Thread.pm +++ b/lib/WebGUI/Asset/Post/Thread.pm @@ -42,10 +42,10 @@ sub createSubscriptionGroup { my $self = shift; my $group = WebGUI::Group->new("new"); $group->name($self->getId); - $group->description("The group to store subscriptions for the collaboration system ".$self->getId); + $group->description("The group to store subscriptions for the thread ".$self->getId); $group->isEditable(0); $group->showInForms(0); - $group->deleteGroups([3]); # admins don't want to be auto subscribed to this thing + $group->deleteGroups(['3']); # admins don't want to be auto subscribed to this thing $self->update({ subscriptionGroupId=>$group->groupId }); diff --git a/lib/WebGUI/Group.pm b/lib/WebGUI/Group.pm index 09215c0ae..e9a0cbd6a 100755 --- a/lib/WebGUI/Group.pm +++ b/lib/WebGUI/Group.pm @@ -56,7 +56,9 @@ This package provides an object-oriented way of managing WebGUI groups and group $g->addGroups(\@arr); + $g->addUsers(\@arr); $g->deleteGroups(\@arr); + $g->deleteUsers(\@arr); $g->delete; =head1 METHODS @@ -93,6 +95,22 @@ sub addGroups { #------------------------------------------------------------------- +=head2 addUsers ( users ) + +Adds users to this group. + +=head3 users + +An array reference containing the list of user ids to add to this group. + +=cut + +sub addUsers { + WebGUI::Grouping::addUsersToGroups($_[1],[$_[0]->{_groupId}]); +} + +#------------------------------------------------------------------- + =head2 autoAdd ( [ value ] ) Returns an boolean stating whether users can add themselves to this group. @@ -184,6 +202,22 @@ sub deleteGroups { WebGUI::Grouping::deleteGroupsFromGroups($_[1],[$_[0]->{_groupId}]); } +#------------------------------------------------------------------- + +=head2 deleteUsers ( users ) + +Deletes users from this group. + +=head3 users + +An array reference containing the list of user ids to delete from this group. + +=cut + +sub deleteUsers { + WebGUI::Grouping::deleteUsersFromGroups($_[1],[$_[0]->{_groupId}]); +} + #-------------------------------------------------------------------