Fix thread search URLs when threads are archived, or trashed. Location in the pagination is now found by interrupted linear search.

This commit is contained in:
Colin Kuskie 2010-03-16 18:29:09 -07:00
parent 90cd1ac257
commit a7b4fbc0ed
3 changed files with 99 additions and 59 deletions

View file

@ -349,20 +349,46 @@ for the site.
=cut =cut
sub getCSLinkUrl { sub getCSLinkUrl {
my $self = shift; my $self = shift;
if ($self->get('status') eq 'archived') {
return $self->get('url');
}
my $session = $self->session;
my $url; my $url;
my $cs = $self->getParent; my $cs = $self->getParent;
my $paginator = WebGUI::Paginator->new($self->session, '', $self->getParent->get('threadsPerPage')); my $page_size = $cs->get('threadsPerPage');
my $page_size = $paginator->{_rpp}; ##To make sure defaults are handled correctly. my $sql =<<EOSQL;
my $place = $self->getRank+1; select lineage from asset
my $last_place = $cs->getLastChild->getRank+1; left join Thread using (assetId)
my $page = int(($last_place - $place)/$page_size) + 1; left join assetData using (assetId)
where parentId=?
and className='WebGUI::Asset::Post::Thread'
and state='published'
and status='approved'
group by assetData.assetId
order by Thread.isSticky DESC,
lineage DESC
EOSQL
my $sth = $session->db->read($sql, [$cs->getId]);
my $place = 1; ##1 based indexing
my $found = 0;
my $lineage = $self->get('lineage');
THREAD: while (my $arrayRef = $sth->arrayRef) {
if ($arrayRef->[0] eq $lineage) {
$found = 1;
last THREAD;
}
++$place;
}
$sth->finish;
return $self->get('url') if !$found;
my $page = int($place/$page_size) + 1;
my $page_frag = 'pn='.$page.';sortBy=lineage;sortOrder=desc'; my $page_frag = 'pn='.$page.';sortBy=lineage;sortOrder=desc';
$url = $self->session->url->append($cs->get('url'), $page_frag); $url = $session->url->append($cs->get('url'), $page_frag);
return $url; return $url;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getThreadLinkUrl ( ) =head2 getThreadLinkUrl ( )

View file

@ -1159,66 +1159,68 @@ Collaboration System
=cut =cut
sub getThreadsPaginator { sub getThreadsPaginator {
my $self = shift; my $self = shift;
my $scratchSortBy = $self->getId."_sortBy"; my $scratchSortBy = $self->getId."_sortBy";
my $scratchSortOrder = $self->getId."_sortDir"; my $scratchSortOrder = $self->getId."_sortDir";
my $sortBy = $self->session->form->process("sortBy") my $sortBy = $self->session->form->process("sortBy")
|| $self->session->scratch->get($scratchSortBy) || $self->session->scratch->get($scratchSortBy)
|| $self->get("sortBy"); || $self->get("sortBy");
my $sortOrder = $self->session->form->process("sortOrder") my $sortOrder = $self->session->form->process("sortOrder")
|| $self->session->scratch->get($scratchSortOrder) || $self->session->scratch->get($scratchSortOrder)
|| $self->get("sortOrder"); || $self->get("sortOrder");
if ($sortBy ne $self->session->scratch->get($scratchSortBy) && $self->session->form->process("func") ne "editSave") { if ($sortBy ne $self->session->scratch->get($scratchSortBy) && $self->session->form->process("func") ne "editSave") {
$self->session->scratch->set($scratchSortBy,$self->session->form->process("sortBy")); $self->session->scratch->set($scratchSortBy,$self->session->form->process("sortBy"));
$self->session->scratch->set($scratchSortOrder, $sortOrder); $self->session->scratch->set($scratchSortOrder, $sortOrder);
} elsif ($self->session->form->process("sortBy") && $self->session->form->process("func") ne "editSave") { }
if ($sortOrder eq "asc") { elsif ($self->session->form->process("sortBy") && $self->session->form->process("func") ne "editSave") {
$sortOrder = "desc"; if ($sortOrder eq "asc") {
} else { $sortOrder = "desc";
$sortOrder = "asc"; }
} else {
$self->session->scratch->set($scratchSortOrder, $sortOrder); $sortOrder = "asc";
} }
$sortBy ||= "assetData.revisionDate"; $self->session->scratch->set($scratchSortOrder, $sortOrder);
$sortOrder ||= "desc"; }
$sortBy ||= "assetData.revisionDate";
$sortOrder ||= "desc";
# Sort by the thread rating instead of the post rating. other places don't care about threads. # Sort by the thread rating instead of the post rating. other places don't care about threads.
if ($sortBy eq 'rating') { if ($sortBy eq 'rating') {
$sortBy = 'threadRating'; $sortBy = 'threadRating';
} }
$sortBy = join('.', map { $self->session->db->dbh->quote_identifier($_) } split(/\./, $sortBy)); $sortBy = join('.', map { $self->session->db->dbh->quote_identifier($_) } split(/\./, $sortBy));
my $sql = " my $sql = "
select select
asset.assetId, asset.assetId,
asset.className, asset.className,
assetData.revisionDate as revisionDate assetData.revisionDate as revisionDate
from Thread from Thread
left join asset on Thread.assetId=asset.assetId left join asset on Thread.assetId=asset.assetId
left join Post on Post.assetId=Thread.assetId and Thread.revisionDate = Post.revisionDate left join Post on Post.assetId=Thread.assetId and Thread.revisionDate = Post.revisionDate
left join assetData on assetData.assetId=Thread.assetId and Thread.revisionDate = assetData.revisionDate left join assetData on assetData.assetId=Thread.assetId and Thread.revisionDate = assetData.revisionDate
where where
asset.parentId=".$self->session->db->quote($self->getId)." asset.parentId=".$self->session->db->quote($self->getId)."
and asset.state='published' and asset.state='published'
and asset.className='WebGUI::Asset::Post::Thread' and asset.className='WebGUI::Asset::Post::Thread'
and assetData.revisionDate=( and assetData.revisionDate=(
select select
max(revisionDate) max(revisionDate)
from from
assetData assetData
where where
assetData.assetId=asset.assetId assetData.assetId=asset.assetId
and (status='approved' or status='archived') and (status='approved' or status='archived')
) )
and status='approved' and status='approved'
group by group by
assetData.assetId assetData.assetId
order by order by
Thread.isSticky desc, Thread.isSticky desc,
".$sortBy." ".$sortBy."
".$sortOrder; ".$sortOrder;
my $p = WebGUI::Paginator->new($self->session,$self->getUrl,$self->get("threadsPerPage")); my $p = WebGUI::Paginator->new($self->session,$self->getUrl,$self->get("threadsPerPage"));
$p->setDataByQuery($sql); $p->setDataByQuery($sql);
return $p; return $p;
} }

View file

@ -13,7 +13,7 @@ use strict;
use lib "$FindBin::Bin/../../lib"; use lib "$FindBin::Bin/../../lib";
use WebGUI::Test; use WebGUI::Test;
use WebGUI::Session; use WebGUI::Session;
use Test::More tests => 11; # increment this value for each test you create use Test::More tests => 12; # increment this value for each test you create
use Test::MockObject::Extends; use Test::MockObject::Extends;
use Test::Exception; use Test::Exception;
use WebGUI::Asset::Wobject::Collaboration; use WebGUI::Asset::Wobject::Collaboration;
@ -79,13 +79,25 @@ $collab->update({threadsPerPage => 3, postsPerPage => 10,});
note 'getCSLinkUrl'; note 'getCSLinkUrl';
my @newThreads; my @newThreads;
push @newThreads, $collab->addChild($props, @addArgs); my $threadCount = 15;
push @newThreads, $collab->addChild($props, @addArgs); while ($threadCount--) {
push @newThreads, $collab->addChild($props, @addArgs);
}
my $versionTag2 = WebGUI::VersionTag->getWorking($session);
$versionTag2->commit;
my $csUrl = $collab->get('url'); my $csUrl = $collab->get('url');
like $newThreads[-1]->getCSLinkUrl, qr/^$csUrl/, 'getCsLinkUrl returns URL of the parent CS with no gateway'; like $newThreads[-1]->getCSLinkUrl, qr/^$csUrl/, 'getCsLinkUrl returns URL of the parent CS with no gateway';
like $newThreads[-1]->getCSLinkUrl, qr/\?pn=1/, 'and has the right page number'; like $newThreads[-1]->getCSLinkUrl, qr/\?pn=1/, 'and has the right page number';
like $newThreads[-1]->getCSLinkUrl, qr/\?pn=1;sortBy=lineage;sortOrder=desc/, 'and has the right sort parameters'; like $newThreads[-1]->getCSLinkUrl, qr/\?pn=1;sortBy=lineage;sortOrder=desc/, 'and has the right sort parameters';
like $thread->getCSLinkUrl, qr/\?pn=2/, 'checking 2nd thread on another page'; $thread->restore();
like $thread->getCSLinkUrl, qr/\?pn=6/, 'checking 2nd thread on another page';
$newThreads[0]->archive;
$newThreads[1]->archive;
$newThreads[2]->archive;
like $thread->getCSLinkUrl, qr/\?pn=5/, 'checking thread on another page, with archived threads';
$collab->update({threadsPerPage => 0, postsPerPage => 0,}); $collab->update({threadsPerPage => 0, postsPerPage => 0,});
lives_ok { $uncommittedThread->getCSLinkUrl } '... works when pagination set to 0'; lives_ok { $uncommittedThread->getCSLinkUrl } '... works when pagination set to 0';