fix getLineage. All tests in t/Asset/AssetTrash.t are passing.

This commit is contained in:
Colin Kuskie 2010-01-22 15:25:50 -08:00
parent 886a896f27
commit de34ab3b95
2 changed files with 17 additions and 15 deletions

View file

@ -385,12 +385,13 @@ The maximum amount of entries to return
=cut =cut
sub getLineage { sub getLineage {
my $self = shift; my $self = shift;
my $relatives = shift; my $session = $self->session;
my $rules = shift; my $relatives = shift;
my $lineage = $self->get("lineage"); my $rules = shift;
my $lineage = $self->lineage;
my $sql = $self->getLineageSql($relatives,$rules); my $sql = $self->getLineageSql($relatives, $rules);
unless ($sql) { unless ($sql) {
return []; return [];
@ -398,7 +399,7 @@ sub getLineage {
my @lineage; my @lineage;
my %relativeCache; my %relativeCache;
my $sth = $self->session->db->read($sql); my $sth = $session->db->read($sql);
while (my ($id, $class, $parentId, $version) = $sth->array) { while (my ($id, $class, $parentId, $version) = $sth->array) {
# create whatever type of object was requested # create whatever type of object was requested
my $asset; my $asset;
@ -406,9 +407,9 @@ sub getLineage {
if ($self->getId eq $id) { # possibly save ourselves a hit to the database if ($self->getId eq $id) { # possibly save ourselves a hit to the database
$asset = $self; $asset = $self;
} else { } 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 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; next;
} }
} }
@ -455,8 +456,8 @@ sub getLineageIterator {
my $assetInfo = $sth->hashRef; my $assetInfo = $sth->hashRef;
return return
if !$assetInfo; if !$assetInfo;
my $asset = WebGUI::Asset->new( my $asset = WebGUI::Asset->newById(
$self->session, $assetInfo->{assetId}, $assetInfo->{className}, $assetInfo->{revisionDate} $self->session, $assetInfo->{assetId}, $assetInfo->{revisionDate}
); );
if (!$asset) { if (!$asset) {
WebGUI::Error::ObjectNotFound->throw(id => $assetInfo->{assetId}); WebGUI::Error::ObjectNotFound->throw(id => $assetInfo->{assetId});

View file

@ -57,6 +57,7 @@ my $folder1a2 = $folder1a->addChild({
$versionTag->commit; $versionTag->commit;
#################################################### ####################################################
# #
# trash # trash
@ -64,11 +65,11 @@ $versionTag->commit;
#################################################### ####################################################
is( $topFolder->trash, 1, 'trash: returns 1 if successful' ); 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->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($topFolder->cloneFromDb->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($folder1a->cloneFromDb->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($folder1b->cloneFromDb->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($folder1a2->cloneFromDb->state, 'trash-limbo', '... state set to trash-limbo on grandchild #1-1');
#################################################### ####################################################
# #