From de34ab3b951a0910eed862ca3ee7502a592c333e Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Fri, 22 Jan 2010 15:25:50 -0800 Subject: [PATCH] fix getLineage. All tests in t/Asset/AssetTrash.t are passing. --- lib/WebGUI/AssetLineage.pm | 21 +++++++++++---------- t/Asset/AssetTrash.t | 11 ++++++----- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index aab261961..d5eeb22d6 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -385,12 +385,13 @@ The maximum amount of entries to return =cut sub getLineage { - my $self = shift; - my $relatives = shift; - my $rules = shift; - my $lineage = $self->get("lineage"); + my $self = shift; + my $session = $self->session; + my $relatives = shift; + my $rules = shift; + my $lineage = $self->lineage; - my $sql = $self->getLineageSql($relatives,$rules); + my $sql = $self->getLineageSql($relatives, $rules); unless ($sql) { return []; @@ -398,7 +399,7 @@ sub getLineage { my @lineage; my %relativeCache; - my $sth = $self->session->db->read($sql); + my $sth = $session->db->read($sql); while (my ($id, $class, $parentId, $version) = $sth->array) { # create whatever type of object was requested my $asset; @@ -406,9 +407,9 @@ sub getLineage { if ($self->getId eq $id) { # possibly save ourselves a hit to the database $asset = $self; } else { - $asset = WebGUI::Asset->new($self->session,$id, $class, $version); + $asset = WebGUI::Asset->newById($session, $id, $version); if (!defined $asset) { # won't catch everything, but it will help some if an asset blows up - $self->session->errorHandler->error("AssetLineage::getLineage - failed to instanciate asset with assetId $id, className $class, and revision $version"); + $session->errorHandler->error("AssetLineage::getLineage - failed to instanciate asset with assetId $id, className $class, and revision $version"); next; } } @@ -455,8 +456,8 @@ sub getLineageIterator { my $assetInfo = $sth->hashRef; return if !$assetInfo; - my $asset = WebGUI::Asset->new( - $self->session, $assetInfo->{assetId}, $assetInfo->{className}, $assetInfo->{revisionDate} + my $asset = WebGUI::Asset->newById( + $self->session, $assetInfo->{assetId}, $assetInfo->{revisionDate} ); if (!$asset) { WebGUI::Error::ObjectNotFound->throw(id => $assetInfo->{assetId}); diff --git a/t/Asset/AssetTrash.t b/t/Asset/AssetTrash.t index ae4e15f3d..2b593ded4 100644 --- a/t/Asset/AssetTrash.t +++ b/t/Asset/AssetTrash.t @@ -57,6 +57,7 @@ my $folder1a2 = $folder1a->addChild({ $versionTag->commit; + #################################################### # # trash @@ -64,11 +65,11 @@ $versionTag->commit; #################################################### is( $topFolder->trash, 1, 'trash: returns 1 if successful' ); -is($topFolder->get('state'), 'trash', '... state set to trash on the trashed asset object'); -is($topFolder->cloneFromDb->get('state'), 'trash', '... state set to trash in db on object'); -is($folder1a->cloneFromDb->get('state'), 'trash-limbo', '... state set to trash-limbo on child #1'); -is($folder1b->cloneFromDb->get('state'), 'trash-limbo', '... state set to trash-limbo on child #2'); -is($folder1a2->cloneFromDb->get('state'), 'trash-limbo', '... state set to trash-limbo on grandchild #1-1'); +is($topFolder->state, 'trash', '... state set to trash on the trashed asset object'); +is($topFolder->cloneFromDb->state, 'trash', '... state set to trash in db on object'); +is($folder1a->cloneFromDb->state, 'trash-limbo', '... state set to trash-limbo on child #1'); +is($folder1b->cloneFromDb->state, 'trash-limbo', '... state set to trash-limbo on child #2'); +is($folder1a2->cloneFromDb->state, 'trash-limbo', '... state set to trash-limbo on grandchild #1-1'); #################################################### #