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
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});

View file

@ -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');
####################################################
#