From 76e9693f4b60d24e4e3eb705521946cc5e556123 Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Mon, 4 Apr 2011 16:13:58 -0500 Subject: [PATCH] Export related assets --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Story.pm | 20 ++++++++++++ lib/WebGUI/AssetExportHtml.pm | 56 ++++++++++++++++++++++++++++++-- lib/WebGUI/i18n/English/Asset.pm | 9 +++++ t/Asset/Story.t | 8 ++++- 5 files changed, 91 insertions(+), 3 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 7ae8e5f54..0c6f4b14f 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -7,6 +7,7 @@ - Snippets can now select a template parser (instead of being restricted to the configured default) - fixed #12081: addrees not in addressbook after user change in session - fixed #12089: Cannot refund item in transaction if the sku no longer exists. + - rfe #12085: Export Related Story Topics 7.10.12 - fixed #12072: Product, related and accessory assets diff --git a/lib/WebGUI/Asset/Story.pm b/lib/WebGUI/Asset/Story.pm index b8b515455..4a854197d 100644 --- a/lib/WebGUI/Asset/Story.pm +++ b/lib/WebGUI/Asset/Story.pm @@ -240,6 +240,26 @@ sub exportAssetData { #------------------------------------------------------------------- +=head2 exportGetRelatedAssetIds + +Overriden to include any topics in which this story would appear. + +=cut + +sub exportGetRelatedAssetIds { + my $self = shift; + my $rel = $self->SUPER::exportGetRelatedAssetIds(@_); + push @$rel, @{ + WebGUI::Keyword->new($self->session)->getMatchingAssets({ + keywords => WebGUI::Keyword::string2list($self->get('keywords')), + isa => 'WebGUI::Asset::Wobject::StoryTopic', + }) + }; + return $rel; +} + +#------------------------------------------------------------------- + =head2 formatDuration ( $lastUpdated ) Format the time since this story was last updated. If it is longer than 1 week, then diff --git a/lib/WebGUI/AssetExportHtml.pm b/lib/WebGUI/AssetExportHtml.pm index 52d5ad09c..2387a5992 100644 --- a/lib/WebGUI/AssetExportHtml.pm +++ b/lib/WebGUI/AssetExportHtml.pm @@ -422,7 +422,7 @@ sub exportBranch { $asset->$report('done'); }; - my $assetIds = $self->exportGetDescendants(undef, $depth); + my $assetIds = $self->exportGetAssetIds($options); foreach my $assetId ( @{$assetIds} ) { $exportAsset->( $assetId ); } @@ -510,6 +510,33 @@ sub exportCheckExportable { #------------------------------------------------------------------- +=head2 exportGetAssetIds ( options ) + +Gets the ids of all the assets to be exported in this run as an arrayref. +Takes the same options spec as exportBranch. + +=cut + +sub exportGetAssetIds { + my ($self, $options) = @_; + 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'; + while (my $id = shift @$ids) { + my $asset = WebGUI::Asset->new($session, $id); + undef $set{$id}; + for my $id (@{ $asset->exportGetRelatedAssetIds }) { + push(@$ids, $id) unless exists $set{$id}; + } + } + return [ keys %set ]; +} + +#------------------------------------------------------------------- + =head2 exportGetDescendants ( user, depth ) Gets the descendants of this asset for exporting, walking the lineage as the @@ -594,6 +621,24 @@ sub exportGetDescendants { #------------------------------------------------------------------- +=head2 exportGetRelatedAssetIds + +Normally the empty arrayref, 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. + +=cut + +sub exportGetRelatedAssetIds { [] } + +#------------------------------------------------------------------- + =head2 exportGetUrlAsPath ( index ) Translates an asset's URL into an appropriate path and filename for exporting. For @@ -670,7 +715,7 @@ sub exportInFork { my $session = $process->session; my $self = WebGUI::Asset->new( $session, delete $args->{assetId} ); $args->{indexFileName} = delete $args->{index}; - my $assetIds = $self->exportGetDescendants( undef, $args->{depth} ); + my $assetIds = $self->exportGetAssetIds($args); my $tree = WebGUI::ProgressTree->new( $session, $assetIds ); $process->update( sub { $tree->json } ); my %reports = ( @@ -948,6 +993,12 @@ sub www_export { -name => "depth", -value => 99, ); + $f->yesNo( + -label => $i18n->get('Export Related Assets'), + -hoverHelp => $i18n->get('Export Related Assets description'), + -name => "exportRelated", + -value => '', + ); $f->selectBox( -label => $i18n->get('Export as user'), -hoverHelp => $i18n->get('Export as user description'), @@ -1014,6 +1065,7 @@ sub www_exportStatus { my $form = $session->form; my @vars = qw( index depth userId extrasUploadsAction rootUrlAction exportUrl + exportRelated ); $self->forkWithStatusPage({ plugin => 'ProgressTree', diff --git a/lib/WebGUI/i18n/English/Asset.pm b/lib/WebGUI/i18n/English/Asset.pm index 51b7f256b..7ee513e38 100644 --- a/lib/WebGUI/i18n/English/Asset.pm +++ b/lib/WebGUI/i18n/English/Asset.pm @@ -808,6 +808,15 @@ case of the check box list, then enter one per line. The total amount of data i context => q|Field label for the Export Page operation|, message => q|Depth|, }, + 'Export Related Assets' => { + lastUpdated => 1301501028, + context => q|Field label for the Export Page operation|, + message => q|Export Related Assets|, + }, + 'Export Related Assets description' => { + lastUpdated => 1301501028, + message => q|Include related assets in export?|, + }, '964' => { lastUpdated => 1052850265, message => q|Manage system trash.|, diff --git a/t/Asset/Story.t b/t/Asset/Story.t index 122a464c1..92f939427 100644 --- a/t/Asset/Story.t +++ b/t/Asset/Story.t @@ -84,7 +84,7 @@ WebGUI::Test->addToCleanup($storage1, $storage2); # ############################################################ -my $tests = 46; +my $tests = 47; plan tests => 1 + $tests + $canEditMaker->plan @@ -266,6 +266,12 @@ cmp_deeply( 'getCrumbTrail: with topic set' ); +is_deeply( + $story->exportGetRelatedAssetIds, + [ $topic->getId ], + 'exportGetRelatedAssetIds', +); + $story->topic(''); ############################################################