Merge commit '469c2b72b4' into WebGUI8. All tests passing.

This commit is contained in:
Colin Kuskie 2010-07-01 10:13:22 -07:00
commit 565cf955d7
147 changed files with 1526 additions and 1283 deletions

View file

@ -118,6 +118,7 @@ sub _fixReplyCount {
my $lastPostId = $asset->getLineage( [ qw{ self descendants } ], {
isa => 'WebGUI::Asset::Post',
orderByClause => 'assetData.revisionDate desc',
limit => 1,
} )->[0];
my $lastPost = eval { WebGUI::Asset->newById( $self->session, $lastPostId ); };
if ( ! Exception::Class->caught() ) {
@ -322,6 +323,53 @@ override cut => sub {
#-------------------------------------------------------------------
=head2 disqualifyAsLastPost ( )
This method should be called whenever something happens to the Post or Thread that would disqualify
it as being the last post in a Thread, or Collaboration System. Good examples are cutting to the
clipboard, trashing, or archiving.
If the Post was the last post, it will find the second to last post for each kind of parent asset,
and update that asset with that Post's information.
=cut
sub disqualifyAsLastPost {
my $self = shift;
my $thread = $self->getThread;
if ($thread->get('lastPostId') eq $self->getId) {
my $secondary_post = $thread->getLineage(['descendants'], {
returnObjects => 1,
includeOnlyClasses => ["WebGUI::Asset::Post", ],
limit => 1,
orderByClause => 'revisionDate,lineage DESC',
})->[0];
if ($secondary_post) { ##Handle edge case for no other
$thread->update({ lastPostId => $secondary_post->getId, lastPostDate => $secondary_post->get('creationDate'), });
}
else {
$thread->update({ lastPostId => '', lastPostDate => '', });
}
}
my $cs = $thread->getParent;
if ($cs->get('lastPostId') eq $self->getId) {
my $secondary_post = $cs->getLineage(['descendants'], {
returnObjects => 1,
includeOnlyClasses => ["WebGUI::Asset::Post","WebGUI::Asset::Post::Thread"],
limit => 1,
orderByClause => 'revisionDate DESC',
})->[0];
if ($secondary_post) { ##Handle edge case for no other
$cs->update({ lastPostId => $secondary_post->getId, lastPostDate => $secondary_post->get('creationDate'), });
}
else {
$cs->update({ lastPostId => '', lastPostDate => '', });
}
}
}
#-------------------------------------------------------------------
=head2 DESTROY
Extend the base method to delete the locally cached thread object.
@ -1109,6 +1157,22 @@ sub postProcess {
#-------------------------------------------------------------------
=head2 publish
Extend the base method to handle updating last post information in the parent Thread
and CS.
=cut
sub publish {
my $self = shift;
$self->next::method(@_);
$self->qualifyAsLastPost;
return 1;
}
#-------------------------------------------------------------------
=head2 purge
Extend the base method to handle cleaning up storage locations.
@ -1156,6 +1220,31 @@ override purgeRevision => sub {
#-------------------------------------------------------------------
=head2 qualifyAsLastPost ( )
This method should be called whenever something happens to the Post or Thread that would qualify
it as being the last post in a Thread, or Collaboration System. Good examples are pasting from
the clipboard, restoring from the trash, or changing the state from archiving.
It checks the parent Thread and CS to see if it is now the last Post, and updates that asset with
its information.
=cut
sub qualifyAsLastPost {
my ($self) = @_;
my $thread = $self->getThread();
if ($self->get('creationDate') > $thread->get('lastPostDate')) {
$thread->update({ lastPostId => $self->getId, lastPostDate => $self->get('creationDate'), });
}
my $cs = $thread->getParent;
if ($self->get('creationDate') > $cs->get('lastPostDate')) {
$cs->update({ lastPostId => $self->getId, lastPostDate => $self->get('creationDate'), });
}
}
#-------------------------------------------------------------------
=head2 rate ( rating )
@ -1260,14 +1349,16 @@ override setParent => sub {
=head2 setStatusArchived ( )
Sets the status of this post to archived.
Sets the status of this post to archived. Updates the parent thread and CS to remove
the lastPost, if this post is the last post.
=cut
sub setStatusArchived {
my ($self) = @_;
$self->update({status=>'archived'});
my ($self) = @_;
$self->update({status=>'archived'});
$self->disqualifyAsLastPost;
}
@ -1276,20 +1367,23 @@ sub setStatusArchived {
=head2 setStatusUnarchived ( )
Sets the status of this post to approved, but does so without any of the normal notifications and other stuff.
Updates the last post information in the parent Thread and CS if applicable.
=cut
sub setStatusUnarchived {
my ($self) = @_;
$self->update({status=>'approved'}) if ($self->status eq "archived");
my ($self) = @_;
$self->update({status=>'approved'}) if ($self->status eq "archived");
$self->qualifyAsLastPost;
}
#-------------------------------------------------------------------
=head2 trash ( )
Moves post to the trash, updates reply counter on thread and recalculates the thread rating.
Moves post to the trash, updates reply counter on thread, recalculates the thread rating,
and updates any lastPost information in the parent Thread, and CS.
=cut
@ -1298,23 +1392,9 @@ override trash => sub {
super();
$self->getThread->sumReplies if ($self->isReply);
$self->getThread->updateThreadRating;
if ($self->getThread->lastPostId eq $self->getId) {
my $threadLineage = $self->getThread->lineage;
my ($id, $date) = $self->session->db->quickArray("select assetId, creationDate from asset where
lineage like ? and assetId<>? and asset.state='published' and className like 'WebGUI::Asset::Post%'
order by creationDate desc",[$threadLineage.'%', $self->getId]);
$self->getThread->update({lastPostId=>$id, lastPostDate=>$date});
}
if ($self->getThread->getParent->lastPostId eq $self->getId) {
my $forumLineage = $self->getThread->getParent->lineage;
my ($id, $date) = $self->session->db->quickArray("select assetId, creationDate from asset where
lineage like ? and assetId<>? and asset.state='published' and className like 'WebGUI::Asset::Post%'
order by creationDate desc",[$forumLineage.'%', $self->getId]);
$self->getThread->getParent->update({lastPostId=>$id, lastPostDate=>$date});
}
$self->disqualifyAsLastPost;
};
#-------------------------------------------------------------------
=head2 prepareView
@ -1513,6 +1593,7 @@ sub www_edit {
$var{'archive.form'} = WebGUI::Form::yesNo($session, {
name=>"archive"
});
$var{'isSubscribedToCs'} = $self->getThread->getParent->isSubscribed;
$var{'form.header'} .= WebGUI::Form::hidden($session, {
name=>"proceed",
value=>"showConfirmation"

View file

@ -211,8 +211,9 @@ sub appendTemplateVarsFileLoop {
my $assetIds = shift;
my $session = $self->session;
for my $assetId (@$assetIds) {
my $asset = WebGUI::Asset->newById($session, $assetId);
ASSET: for my $assetId (@$assetIds) {
my $asset = eval { WebGUI::Asset->newById($session, $assetId); };
next ASSET if Exception::Class->caught();
# Set the parent
$asset->{_parent} = $self;
push @{$var->{file_loop}}, $asset->getTemplateVars;

View file

@ -288,9 +288,14 @@ sub getFolder {
##For a fully automatic commit, save the current tag, create a new one
##with the commit without approval workflow, commit it, then restore
##the original if it exists
my $oldVersionTag = WebGUI::VersionTag->getWorking($session, 'noCreate');
my $newVersionTag = WebGUI::VersionTag->create($session, { workflowId => 'pbworkflow00000000003', });
$newVersionTag->setWorking;
my ($oldVersionTag, $newVersionTag);
$oldVersionTag = WebGUI::VersionTag->getWorking($session, 'noCreate');
if ($self->hasBeenCommitted) {
$newVersionTag = WebGUI::VersionTag->create($session, { workflowId => 'pbworkflow00000000003', });
$newVersionTag->setWorking;
$newVersionTag->set({ name => 'Adding folder '. $folderName. ' to archive '. $self->getUrl});
}
##Call SUPER because my addChild calls getFolder
$folder = $self->addChild({
@ -301,7 +306,7 @@ sub getFolder {
isHidden => 1,
styleTemplateId => $self->styleTemplateId,
});
$newVersionTag->commit();
$newVersionTag->commit() if $newVersionTag;
##Restore the old one, if it exists
$oldVersionTag->setWorking() if $oldVersionTag;

View file

@ -996,20 +996,8 @@ sub getFormPlugin {
eval { WebGUI::Pluggable::load($class) };
if ($class->isa('WebGUI::Form::List')) {
delete $param{size};
my $values = WebGUI::Operation::Shared::secureEval($session,$data->{possibleValues});
if (ref $values eq 'HASH') {
$param{options} = $values;
}
else{
my %options;
tie %options, 'Tie::IxHash';
foreach (split(/\n/x, $data->{possibleValues})) {
s/\s+$//x; # remove trailing spaces
$options{$_} = $_;
}
$param{options} = \%options;
}
$param{options} = $values;
}
if ($data->{fieldType} eq "YesNo") {
@ -3238,7 +3226,7 @@ $self->session->form->process($_) eq "") {
sequenceNumber');
while (my $field = $fields->hashRef) {
if ($field->{searchIn}){
my $searchForm = $self->getFormElement($field);
my $searchForm = $self->getFormPlugin($field, 1);
my $searchTextForm = WebGUI::Form::Text($self->session, {
name=>"field_".$field->{fieldId},
size=>25,
@ -3253,9 +3241,10 @@ sequenceNumber');
push(@searchFields_loop, {
"searchFields_fieldId" => $field->{fieldId},
"searchFields_label" => $field->{label},
"searchFields_form" => $searchForm,
"searchFields_form" => $searchForm->toHtml,
"searchFields_textForm" => $searchTextForm,
"searchFields_is".$fieldType => 1,
"searchFields_listType" => $searchForm->isa('WebGUI::Form::List'),
});
my @searchValue = $session->form->process("field_".$field->{fieldId});