added: getLineageIterator method to simplify working on large sets of assets

This commit is contained in:
Graham Knop 2008-09-05 22:14:04 +00:00
parent 3d5224c93c
commit 29a419e1eb
3 changed files with 86 additions and 1 deletions

View file

@ -380,6 +380,38 @@ sub getLineage {
return \@lineage;
}
#-------------------------------------------------------------------
=head2 getLineageIterator ( relatives,rules )
Takes the same parameters as getLineage, but instead of returning a list
it returns an iterator. Calling the iterator will return instantiated assets,
or undef when there are no more assets available.
=cut
sub getLineageIterator {
my $self = shift;
my $relatives = shift;
my $rules = shift;
my $sql = $self->getLineageSql($relatives, $rules);
my $sth = $self->session->db->read($sql);
my $sub = sub {
my $assetInfo = $sth->hashRef;
return
if !$assetInfo;
my $asset = WebGUI::Asset->new(
$self->session, $assetInfo->{assetId}, $assetInfo->{className}, $assetInfo->{revisionDate}
);
if (!$asset) {
WebGUI::Error::ObjectNotFound->throw(id => $assetInfo->{assetId});
}
return $asset;
};
return $sub;
}
#-------------------------------------------------------------------