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);
CREATE TABLE StoryArchive (
assetId CHAR(22) BINARY NOT NULL,
revisionDate BIGINT NOT NULL,
storiesPerPage INTEGER,
groupToPost CHAR(22) BINARY,
templateId CHAR(22) BINARY,
storyTemplateId CHAR(22) BINARY,
editStoryTemplateId CHAR(22) BINARY,
archiveAfter INT(11),
richEditorId CHAR(22) BINARY,
approvalWorkflowId CHAR(22) BINARY DEFAULT 'pbworkflow000000000003',
assetId CHAR(22) BINARY NOT NULL,
revisionDate BIGINT NOT NULL,
storiesPerPage INTEGER,
groupToPost CHAR(22) BINARY,
templateId CHAR(22) BINARY,
storyTemplateId CHAR(22) BINARY,
editStoryTemplateId CHAR(22) BINARY,
keywordListTemplateId CHAR(22) BINARY,
archiveAfter INT(11),
richEditorId CHAR(22) BINARY,
approvalWorkflowId CHAR(22) BINARY DEFAULT 'pbworkflow000000000003',
PRIMARY KEY ( assetId, revisionDate )
)
EOARCHIVE

View file

@ -123,6 +123,14 @@ sub definition {
namespace => '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('<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({
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 {
'&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.
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);
}

View file

@ -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;

View file

@ -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;

View file

@ -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'
);
}
#----------------------------------------------------------------------------