From 8276336cbefc352078f5947dafa05c0805dac766 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 23 Sep 2009 15:40:35 -0700 Subject: [PATCH] Templates in the trash or clipboard now log and return warnings. fixes bug #11031 --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Template.pm | 31 ++++++++++++++------- lib/WebGUI/i18n/English/Asset_Template.pm | 10 +++++++ t/Asset/Template.t | 33 ++++++++++++++++++++--- 4 files changed, 62 insertions(+), 13 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 413582c00..7ac5f2e2e 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -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 diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index 798ebf0bc..d9330cf0d 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -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; diff --git a/lib/WebGUI/i18n/English/Asset_Template.pm b/lib/WebGUI/i18n/English/Asset_Template.pm index a431ee5da..5b4319033 100644 --- a/lib/WebGUI/i18n/English/Asset_Template.pm +++ b/lib/WebGUI/i18n/English/Asset_Template.pm @@ -369,6 +369,16 @@ Any scratch variables will be available in the template with this syntax:
lastUpdated => 0, context => "Label for a JS file attachment that goes after all the content in the block", }, + + 'template in trash' => { + message => q|Template in trash|, + lastUpdated => 0, + }, + + 'template in clipboard' => { + message => q|Template in clipboard|, + lastUpdated => 0, + }, }; 1; diff --git a/t/Asset/Template.t b/t/Asset/Template.t index 7731a6caa..ad0f3c5bf 100644 --- a/t/Asset/Template.t +++ b/t/Asset/Template.t @@ -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|If clause with no ending tag|, }); -# done checking revision stuff - WebGUI::Test->interceptLogging; my $brokenOutput = $brokenTemplate->process({}); my $logError = $WebGUI::Test::logger_error;