From f1538824f7c1025d7b0a9cf3898f03649dc8bbf3 Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Mon, 9 May 2011 09:59:53 -0500 Subject: [PATCH] rfe #12123: Layouts related for export purposes --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/AssetExportHtml.pm | 32 ++++++++++++++++++++------------ t/Asset/AssetExportHtml.t | 13 +++++++++++-- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index c19972c6f..32c62ea7e 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,6 @@ 7.10.16 - fixed #12121: typ-o Asset_Map.templateIdEditPoint + - rfe #2123: Layouts related for export purposes 7.10.15 - fixed #12117: Thingy - www_searchViaAjax broken diff --git a/lib/WebGUI/AssetExportHtml.pm b/lib/WebGUI/AssetExportHtml.pm index 6db3b6ae7..555788518 100644 --- a/lib/WebGUI/AssetExportHtml.pm +++ b/lib/WebGUI/AssetExportHtml.pm @@ -522,9 +522,13 @@ sub exportGetAssetIds { my $session = $self->session; my $ids = $self->exportGetDescendants( undef, $options->{depth} ); return $ids unless $options->{exportRelated}; - # We want the ids in a descendant order, but we don't want to repeat - # assetIds, so we're using Tie::IxHash to get an ordered set. - tie my %set, 'Tie::IxHash'; + + # We don't particularly care about the order of the assetIds. The only + # thing that might care is the ProgressTree page, and it computes the tree + # by looking at asset lineage anyway. We do want to follow chains of + # related assets though, so we'll use $ids as a queue and push related + # assets onto the end (unless, of course, they're already in the set). + my %set; while (my $id = shift @$ids) { my $asset = WebGUI::Asset->new($session, $id); undef $set{$id}; @@ -623,21 +627,25 @@ sub exportGetDescendants { =head2 exportGetRelatedAssetIds -Normally all an asset's shorcuts, but override if exporting your asset would -invalidate other exported assets. If exportRelated is checked, this will be -called and any assetIds it returns will be exported when your asset is -exported. +Normally all an asset's shorcuts and its container (via $asset->getContainer), +but override if exporting your asset would invalidate other exported assets. +If exportRelated is checked, this will be called and any assetIds it returns +will be exported when your asset is exported. -Note: You should NOT include parents as related assets simply because they're -your parents. If the user wants to export your parent, he can do that. This is -for assets that aren't necessarily in your ancestry. If parents were always -related, exporting anything would export everything. +This method returns an arrayref, and IS ALLOWED to contain the same assetId +more than once. Anyone calling this function should check for duplicates. No +particular order should be assumed. =cut sub exportGetRelatedAssetIds { my $self = shift; - WebGUI::Asset::Shortcut->getShortcutsForAssetId($self->session, $self->getId); + my $related = WebGUI::Asset::Shortcut->getShortcutsForAssetId( + $self->session, + $self->getId + ); + push @$related, $self->getContainer->getId; + return $related; } #------------------------------------------------------------------- diff --git a/t/Asset/AssetExportHtml.t b/t/Asset/AssetExportHtml.t index d8ffdcffd..9a795e6b1 100644 --- a/t/Asset/AssetExportHtml.t +++ b/t/Asset/AssetExportHtml.t @@ -647,9 +647,18 @@ subtest exportRelated => sub { }); $tag->commit(); my $cleanup = guard { $tag->rollback; if ($old) { $old->setWorking(); } }; - cmp_deeply( + + # This will include some folders, because of the way Archive works + my $expected = $archive->getLineage(['self', 'descendants']); + push @$expected, $topic->getId; + + # getContainer should be included; since parent is a Layout, the + # upward-recursion will stop there. + push @$expected, $topic->getContainer->getId; + + cmp_bag( $archive->exportGetAssetIds({ depth => 99, exportRelated => 1}), - superbagof(map { $_->getId } ($topic, $archive, $story)), + $expected, 'exporting archive includes topic with exportRelated' ); is(0, scalar grep { $_ eq $topic->getId }