added: getLineageIterator method to simplify working on large sets of assets
This commit is contained in:
parent
3d5224c93c
commit
29a419e1eb
3 changed files with 86 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
|||
7.6.0
|
||||
- added: getLineageIterator method to simplify working on large sets of assets
|
||||
- fixed: Syndicated Content doesn't decode alternate character sets
|
||||
- fixed: Some templates ship with isPublic=1
|
||||
- fixed: DataForm export tab delimited doesn't work
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ use WebGUI::Session;
|
|||
use WebGUI::User;
|
||||
|
||||
use WebGUI::Asset;
|
||||
use Test::More tests => 87; # increment this value for each test you create
|
||||
use Test::More tests => 92; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
|
||||
# Test the methods in WebGUI::AssetLineage
|
||||
|
|
@ -442,6 +442,58 @@ cmp_bag(
|
|||
'getLineage: descendants of topFolder',
|
||||
);
|
||||
|
||||
####################################################
|
||||
#
|
||||
# getLineageIterator
|
||||
#
|
||||
####################################################
|
||||
|
||||
sub getListFromIterator {
|
||||
my $iterator = shift;
|
||||
my @items;
|
||||
while (my $item = $iterator->()) {
|
||||
push @items, $item->getId;
|
||||
}
|
||||
return \@items;
|
||||
}
|
||||
|
||||
@snipIds = map { $_->getId } @snippets;
|
||||
my $ids = getListFromIterator($folder->getLineageIterator(['descendants']));
|
||||
cmp_bag(
|
||||
\@snipIds,
|
||||
$ids,
|
||||
'getLineageIterator: get descendants of folder'
|
||||
);
|
||||
|
||||
$ids = getListFromIterator($folder->getLineageIterator(['self','descendants']));
|
||||
unshift @snipIds, $folder->getId;
|
||||
cmp_bag(
|
||||
\@snipIds,
|
||||
$ids,
|
||||
'getLineageIterator: get descendants of folder and self'
|
||||
);
|
||||
|
||||
$ids = getListFromIterator($folder->getLineageIterator(['self','children']));
|
||||
cmp_bag(
|
||||
\@snipIds,
|
||||
$ids,
|
||||
'getLineageIterator: descendants == children if there are no grandchildren'
|
||||
);
|
||||
|
||||
$ids = getListFromIterator($topFolder->getLineageIterator(['self','children']));
|
||||
cmp_bag(
|
||||
[$topFolder->getId, $folder->getId, $folder2->getId, ],
|
||||
$ids,
|
||||
'getLineageIterator: children (no descendants) of topFolder',
|
||||
);
|
||||
|
||||
$ids = getListFromIterator($topFolder->getLineageIterator(['self','descendants']));
|
||||
cmp_bag(
|
||||
[$topFolder->getId, @snipIds, $folder2->getId, $snippet2->getId],
|
||||
$ids,
|
||||
'getLineageIterator: descendants of topFolder',
|
||||
);
|
||||
|
||||
####################################################
|
||||
#
|
||||
# addChild
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue