diff --git a/docs/upgrades/packages-7.7.4/root_import_storymanager.wgpkg b/docs/upgrades/packages-7.7.4/root_import_storymanager.wgpkg index 8e515142a..42da60941 100644 Binary files a/docs/upgrades/packages-7.7.4/root_import_storymanager.wgpkg and b/docs/upgrades/packages-7.7.4/root_import_storymanager.wgpkg differ diff --git a/docs/upgrades/upgrade_7.7.3-7.7.4.pl b/docs/upgrades/upgrade_7.7.3-7.7.4.pl index d4f264908..31e4635ec 100644 --- a/docs/upgrades/upgrade_7.7.3-7.7.4.pl +++ b/docs/upgrades/upgrade_7.7.3-7.7.4.pl @@ -126,16 +126,17 @@ EOSTORY $db->write(< 'Story/Edit', defaultValue => 'E3tzZjzhmYoNlAyP2VW33Q', }, + keywordListTemplateId => { + tab => 'display', + fieldType => 'template', + label => $i18n->get('keyword list template'), + hoverHelp => $i18n->get('keyword list template help'), + namespace => 'StoryArchive/KeywordList', + defaultValue => '0EAJ9EYb9ap2XwfrcXfdLQ', + }, archiveAfter => { tab => 'display', fieldType => 'interval', @@ -202,16 +210,23 @@ sub exportAssetCollateral { $reportSession->output->print('
'); } - my $keywordObj = WebGUI::Keyword->new($session); + # open another session as the user doing the exporting... + my $exportSession = WebGUI::Session->open( + $self->session->config->getWebguiRoot, + $self->session->config->getFilename, + undef, + undef, + $self->session->getId, + ); + + + my $keywordObj = WebGUI::Keyword->new($exportSession); my $keywords = $keywordObj->findKeywords({ asset => $self, limit => 50, ##This is based on the tagcloud setting }); -##export session: do we need it? -##Need to find 50 assets per keyword and make a link list. -##In export mode, tagCloud should call the callback instead of using the func - + my $listTemplate = WebGUI::Asset->new($session, $self->get('keywordListTemplateId'), 'WebGUI::Asset::Template'); foreach my $keyword (@{ $keywords }) { ##Keywords may not be URL safe, so urlize them my $keyword_url = $self->getKeywordStaticUrl($keyword); @@ -224,39 +239,45 @@ sub exportAssetCollateral { '      ' . $message . '
'); } - # open another session as the user doing the exporting... - my $exportSession = WebGUI::Session->open( - $self->session->config->getWebguiRoot, - $self->session->config->getFilename, - undef, - undef, - $self->session->getId, - ); - - my $selfdupe = WebGUI::Asset->newByDynamicClass( $exportSession, $self->getId ); - # next, get the contents, open the file, and write the contents to the file. my $fh = eval { $dest->open('>:utf8') }; if($@) { - WebGUI::Error->throw(error => "can't open " . $dest->absolute->stringify . " for writing: $!"); $exportSession->close; + WebGUI::Error->throw(error => "can't open " . $dest->absolute->stringify . " for writing: $!"); } - $exportSession->asset($selfdupe); $exportSession->output->setHandle($fh); - my $contents; - # chunked content is already printed, no need to print it again - unless($contents eq 'chunked') { - $exportSession->output->print($contents); + my $storyIds = $keywordObj->getMatchingAssets({ + startAsset => $self, + keyword => $keyword, + isa => 'WebGUI::Asset::Story', + rowsPerPage => 50, + }); + my $listOfStories = []; + STORYID: foreach my $storyId (@{ $storyIds }) { + my $story = WebGUI::Asset->newByDynamicClass($session, $storyId); + next STORYID unless $story; + push @{ $listOfStories }, { + title => $story->getTitle, + url => $story->getUrl, + }; } - - $exportSession->close; + my $var = { + asset_loop => $listOfStories, + keyword => $keyword, + }; + my $output = $listTemplate->process($var); + my $contents = $self->processStyle($output); + $exportSession->output->print($contents); # tell the user we did this asset collateral correctly if ( $reportSession && !$args->{quiet} ) { $reportSession->output->print($reporti18n->get('done')); } + $fh->flush; + $fh->close; } + $exportSession->close; return $self->next::method($basepath, $args, $reportSession); } diff --git a/lib/WebGUI/Help/Asset_StoryArchive.pm b/lib/WebGUI/Help/Asset_StoryArchive.pm index 611157351..ed3aa84e4 100644 --- a/lib/WebGUI/Help/Asset_StoryArchive.pm +++ b/lib/WebGUI/Help/Asset_StoryArchive.pm @@ -65,6 +65,7 @@ our $HELP = { { 'name' => 'templateId', }, { 'name' => 'storyTemplateId', }, { 'name' => 'editStoryTemplateId', }, + { 'name' => 'keywordListTemplateId', }, { 'name' => 'archiveAfter', }, { 'name' => 'richEditorId', }, { 'name' => 'approvalWorkflowId', }, @@ -73,6 +74,29 @@ our $HELP = { }, + 'keyword list template' => { + title => 'view template', + body => '', + isa => [ + { namespace => "Asset_Template", + tag => "template variables" + }, + ], + fields => [], + variables => [ + { 'name' => 'asset_loop', + 'variables' => [ + { 'name' => 'title', + description => 'asset title' }, + { 'name' => 'url', + description => 'asset url' }, + ] + }, + { 'name' => 'keyword' }, + ], + related => [] + }, + }; 1; diff --git a/lib/WebGUI/i18n/English/Asset_StoryArchive.pm b/lib/WebGUI/i18n/English/Asset_StoryArchive.pm index 0a6d60bf1..21531acfc 100644 --- a/lib/WebGUI/i18n/English/Asset_StoryArchive.pm +++ b/lib/WebGUI/i18n/English/Asset_StoryArchive.pm @@ -87,12 +87,30 @@ our $I18N = { lastUpdated => 0 }, + 'keyword list template' => { + message => q|Keyword List Template|, + context => q|Label in the edit screen and template.|, + lastUpdated => 0 + }, + + 'keyword list template help' => { + message => q|The Template used to render the list of assets matching a keyword when this StoryArchive is exported.|, + context => q|Hoverhelp in the edit screen and template.|, + lastUpdated => 0 + }, + 'editStoryTemplateId' => { message => q|The GUID of the template used to add or edit Story assets.|, context => q|Template variable|, lastUpdated => 0 }, + 'keywordListTemplateId' => { + message => q|The GUID of the template used to render list of assets matching a keyword when this StoryArchive is exported.|, + context => q|Template variable|, + lastUpdated => 0 + }, + 'archive after' => { message => q|Archive Stories After|, context => q|Label in the edit screen and template.|, @@ -255,6 +273,30 @@ our $I18N = { lastUpdated => 0, }, + 'asset_loop' => { + message => q|A loop containing up to the first 50 assets that match the keyword.|, + context => q|Template variable.|, + lastUpdated => 0, + }, + + 'asset title' => { + message => q|The title of this asset.|, + context => q|Template variable.|, + lastUpdated => 0, + }, + + 'asset url' => { + message => q|The title of this url.|, + context => q|Template variable.|, + lastUpdated => 0, + }, + + 'keyword' => { + message => q|The keyword for this list of assets.|, + context => q|Template variable.|, + lastUpdated => 0, + }, + }; 1; diff --git a/t/Asset/Wobject/StoryArchive.t b/t/Asset/Wobject/StoryArchive.t index 68ed2c435..f3c9dfcd2 100644 --- a/t/Asset/Wobject/StoryArchive.t +++ b/t/Asset/Wobject/StoryArchive.t @@ -18,7 +18,10 @@ use strict; use lib "$FindBin::Bin/../../lib"; use Test::More; use Test::Deep; +use File::Copy qw/mv/; +use File::Path; use Data::Dumper; +use Path::Class; use WebGUI::Test; # Must use this before any other WebGUI modules use WebGUI::Test::Maker::Permission; @@ -58,7 +61,7 @@ $canPostMaker->prepare({ fail => [1, $reader ], }); -my $tests = 37 +my $tests = 38 + $canPostMaker->plan ; plan tests => 1 @@ -492,6 +495,33 @@ cmp_deeply( 'rssFeedItems' ); +################################################################ +# +# export Collateral tests +# +################################################################ + +my $exportStorage = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($exportStorage); +my $basedir = Path::Class::Dir->new($exportStorage->getPath); +$exportStorage->addFileFromScalar('index', 'export story archive content'); +my $assetDir = $basedir->subdir('mystories'); +my $assetFile = $assetDir->file('index.html'); +mkpath($assetDir->stringify); +mv($exportStorage->getPath('index'), $assetFile->stringify); +$archive->exportAssetCollateral($assetFile, {}, $session); + +my $exportedFiles = $exportStorage->getFiles(); +cmp_bag( + $exportedFiles, + [qw/ + keyword_roger.html mystories.rss mystories + keyword_foxtrot.html mystories.atom + keyword_echo.html + /], + 'exportAssetCollateral: correct files exported, including dummy directory' +); + } #----------------------------------------------------------------------------