Templates in the trash or clipboard now log and return warnings. fixes bug #11031

This commit is contained in:
Colin Kuskie 2009-09-23 15:40:35 -07:00
parent e4b99f1d6c
commit 8276336cbe
4 changed files with 62 additions and 13 deletions

View file

@ -3,6 +3,7 @@
- fixed #11024: In/Out Board Busted
- fixed #11025: Yo dudely in Wiki Keyword Search Template
- fixed #11027: trash warning but no trash-limbo warning
- fixed #11031: AssetProxy refering to trash-limbo asset
7.8.0
- upgraded YUI to 2.8.0r4

View file

@ -585,21 +585,32 @@ A hash reference containing template variables and loops. Automatically includes
=cut
# TODO: Have this throw an error so we can catch it and print more information
# about the template that has the error. Finding an "ERROR: Error in template"
# in the error log is not very helpful...
sub process {
my $self = shift;
my $vars = shift;
my $self = shift;
my $vars = shift;
my $session = $self->session;
if ($self->get('state') =~ /^trash/) {
my $i18n = WebGUI::International->new($session, 'Asset_Template');
$session->errorHandler->warn('process called on template in trash: '.$self->getId
.'. The template was called through this url: '.$session->asset->get('url'));
return $session->var->isAdminOn ? $i18n->get('template in trash') : '';
}
elsif ($self->get('state') =~ /^clipboard/) {
my $i18n = WebGUI::International->new($session, 'Asset_Template');
$session->errorHandler->warn('process called on template in clipboard: '.$self->getId
.'. The template was called through this url: '.$session->asset->get('url'));
return $session->var->isAdminOn ? $i18n->get('template in clipboard') : '';
}
# Return a JSONinfied version of vars if JSON is the only requested content type.
if ( defined $self->session->request && $self->session->request->headers_in->{Accept} eq 'application/json' ) {
$self->session->http->setMimeType( 'application/json' );
if ( defined $session->request && $session->request->headers_in->{Accept} eq 'application/json' ) {
$session->http->setMimeType( 'application/json' );
return to_json( $vars );
}
$self->prepare unless ($self->{_prepared});
my $parser = $self->getParser($self->session, $self->get("parser"));
my $parser = $self->getParser($session, $self->get("parser"));
my $template = $self->get('usePacked')
? $self->get('templatePacked')
: $self->get('template')
@ -607,8 +618,8 @@ sub process {
my $output;
eval { $output = $parser->process($template, $vars); };
if (my $e = Exception::Class->caught) {
$self->session->log->error(sprintf "Error processing template: %s, %s, %s", $self->getUrl, $self->getId, $e->error);
my $i18n = WebGUI::International->new($self->session, 'Asset_Template');
$session->log->error(sprintf "Error processing template: %s, %s, %s", $self->getUrl, $self->getId, $e->error);
my $i18n = WebGUI::International->new($session, 'Asset_Template');
$output = sprintf $i18n->get('template error').$e->error, $self->getUrl, $self->getId;
}
return $output;

View file

@ -369,6 +369,16 @@ Any scratch variables will be available in the template with this syntax:<br/>
lastUpdated => 0,
context => "Label for a JS file attachment that goes after all the content in the <body> block",
},
'template in trash' => {
message => q|Template in trash|,
lastUpdated => 0,
},
'template in clipboard' => {
message => q|Template in clipboard|,
lastUpdated => 0,
},
};
1;

View file

@ -16,7 +16,7 @@ use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Asset::Template;
use Exception::Class;
use Test::More tests => 39; # increment this value for each test you create
use Test::More tests => 43; # increment this value for each test you create
use Test::Deep;
use JSON qw{ from_json };
@ -123,14 +123,41 @@ is(@$att4, 3, 'rev is proper size');
$template3rev->purgeRevision();
## Check how templates in the trash and clipboard are handled.
$session->asset($importNode);
$session->var->switchAdminOff;
my $trashTemplate = $importNode->addChild({
className => "WebGUI::Asset::Template",
title => 'Trash template',
template => q|Trash Trash Trash Trash|,
});
$trashTemplate->trash;
is($trashTemplate->process, '', 'process: returns nothing when the template is in the trash, and admin mode is off');
$trashTemplate->cut;
is($trashTemplate->process, '', '... returns nothing when the template is in the trash, and admin mode is off');
$session->var->switchAdminOn;
$trashTemplate->trash;
is($trashTemplate->process, 'Template in trash', '... returns message when the template is in the trash, and admin mode is on');
$trashTemplate->cut;
is($trashTemplate->process, 'Template in clipboard', '... returns message when the template is in the trash, and admin mode is on');
$session->var->switchAdminOff;
# Check error logging for bad templates
my $brokenTemplate = $importNode->addChild({
className => "WebGUI::Asset::Template",
title => 'Broken template',
template => q|<tmpl_if unclosedIf>If clause with no ending tag|,
});
# done checking revision stuff
WebGUI::Test->interceptLogging;
my $brokenOutput = $brokenTemplate->process({});
my $logError = $WebGUI::Test::logger_error;