Finish export code.

Make the list of assets templatable, since the user can see it.
Beginnings of export collateral tests.
This commit is contained in:
Colin Kuskie 2009-04-20 21:18:24 +00:00
parent 12acce6c57
commit d1db12d1e4
6 changed files with 153 additions and 35 deletions

View file

@ -126,16 +126,17 @@ EOSTORY
$db->write(<<EOARCHIVE); $db->write(<<EOARCHIVE);
CREATE TABLE StoryArchive ( CREATE TABLE StoryArchive (
assetId CHAR(22) BINARY NOT NULL, assetId CHAR(22) BINARY NOT NULL,
revisionDate BIGINT NOT NULL, revisionDate BIGINT NOT NULL,
storiesPerPage INTEGER, storiesPerPage INTEGER,
groupToPost CHAR(22) BINARY, groupToPost CHAR(22) BINARY,
templateId CHAR(22) BINARY, templateId CHAR(22) BINARY,
storyTemplateId CHAR(22) BINARY, storyTemplateId CHAR(22) BINARY,
editStoryTemplateId CHAR(22) BINARY, editStoryTemplateId CHAR(22) BINARY,
archiveAfter INT(11), keywordListTemplateId CHAR(22) BINARY,
richEditorId CHAR(22) BINARY, archiveAfter INT(11),
approvalWorkflowId CHAR(22) BINARY DEFAULT 'pbworkflow000000000003', richEditorId CHAR(22) BINARY,
approvalWorkflowId CHAR(22) BINARY DEFAULT 'pbworkflow000000000003',
PRIMARY KEY ( assetId, revisionDate ) PRIMARY KEY ( assetId, revisionDate )
) )
EOARCHIVE EOARCHIVE

View file

@ -123,6 +123,14 @@ sub definition {
namespace => 'Story/Edit', namespace => 'Story/Edit',
defaultValue => 'E3tzZjzhmYoNlAyP2VW33Q', 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 => { archiveAfter => {
tab => 'display', tab => 'display',
fieldType => 'interval', fieldType => 'interval',
@ -202,16 +210,23 @@ sub exportAssetCollateral {
$reportSession->output->print('<br />'); $reportSession->output->print('<br />');
} }
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({ my $keywords = $keywordObj->findKeywords({
asset => $self, asset => $self,
limit => 50, ##This is based on the tagcloud setting limit => 50, ##This is based on the tagcloud setting
}); });
##export session: do we need it? my $listTemplate = WebGUI::Asset->new($session, $self->get('keywordListTemplateId'), 'WebGUI::Asset::Template');
##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
foreach my $keyword (@{ $keywords }) { foreach my $keyword (@{ $keywords }) {
##Keywords may not be URL safe, so urlize them ##Keywords may not be URL safe, so urlize them
my $keyword_url = $self->getKeywordStaticUrl($keyword); my $keyword_url = $self->getKeywordStaticUrl($keyword);
@ -224,39 +239,45 @@ sub exportAssetCollateral {
'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $message . '<br />'); '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $message . '<br />');
} }
# 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. # next, get the contents, open the file, and write the contents to the file.
my $fh = eval { $dest->open('>:utf8') }; my $fh = eval { $dest->open('>:utf8') };
if($@) { if($@) {
WebGUI::Error->throw(error => "can't open " . $dest->absolute->stringify . " for writing: $!");
$exportSession->close; $exportSession->close;
WebGUI::Error->throw(error => "can't open " . $dest->absolute->stringify . " for writing: $!");
} }
$exportSession->asset($selfdupe);
$exportSession->output->setHandle($fh); $exportSession->output->setHandle($fh);
my $contents;
# chunked content is already printed, no need to print it again my $storyIds = $keywordObj->getMatchingAssets({
unless($contents eq 'chunked') { startAsset => $self,
$exportSession->output->print($contents); 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,
};
} }
my $var = {
$exportSession->close; 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 # tell the user we did this asset collateral correctly
if ( $reportSession && !$args->{quiet} ) { if ( $reportSession && !$args->{quiet} ) {
$reportSession->output->print($reporti18n->get('done')); $reportSession->output->print($reporti18n->get('done'));
} }
$fh->flush;
$fh->close;
} }
$exportSession->close;
return $self->next::method($basepath, $args, $reportSession); return $self->next::method($basepath, $args, $reportSession);
} }

View file

@ -65,6 +65,7 @@ our $HELP = {
{ 'name' => 'templateId', }, { 'name' => 'templateId', },
{ 'name' => 'storyTemplateId', }, { 'name' => 'storyTemplateId', },
{ 'name' => 'editStoryTemplateId', }, { 'name' => 'editStoryTemplateId', },
{ 'name' => 'keywordListTemplateId', },
{ 'name' => 'archiveAfter', }, { 'name' => 'archiveAfter', },
{ 'name' => 'richEditorId', }, { 'name' => 'richEditorId', },
{ 'name' => 'approvalWorkflowId', }, { '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; 1;

View file

@ -87,12 +87,30 @@ our $I18N = {
lastUpdated => 0 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' => { 'editStoryTemplateId' => {
message => q|The GUID of the template used to add or edit Story assets.|, message => q|The GUID of the template used to add or edit Story assets.|,
context => q|Template variable|, context => q|Template variable|,
lastUpdated => 0 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' => { 'archive after' => {
message => q|Archive Stories After|, message => q|Archive Stories After|,
context => q|Label in the edit screen and template.|, context => q|Label in the edit screen and template.|,
@ -255,6 +273,30 @@ our $I18N = {
lastUpdated => 0, 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; 1;

View file

@ -18,7 +18,10 @@ use strict;
use lib "$FindBin::Bin/../../lib"; use lib "$FindBin::Bin/../../lib";
use Test::More; use Test::More;
use Test::Deep; use Test::Deep;
use File::Copy qw/mv/;
use File::Path;
use Data::Dumper; use Data::Dumper;
use Path::Class;
use WebGUI::Test; # Must use this before any other WebGUI modules use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Test::Maker::Permission; use WebGUI::Test::Maker::Permission;
@ -58,7 +61,7 @@ $canPostMaker->prepare({
fail => [1, $reader ], fail => [1, $reader ],
}); });
my $tests = 37 my $tests = 38
+ $canPostMaker->plan + $canPostMaker->plan
; ;
plan tests => 1 plan tests => 1
@ -492,6 +495,33 @@ cmp_deeply(
'rssFeedItems' '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'
);
} }
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------