From 5bc83c4b178d95c4e7e8f0967f604971a7635581 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 26 Jul 2010 09:01:21 -0700 Subject: [PATCH] If the User Function Style template is cut or deleted, use the Fail Safe template instead. Fixes bug #11729 --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Template.pm | 36 ++++++++++++++++++++++++++++++++++++ t/Asset/Template.t | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 318f57153..63f1a2e18 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,6 @@ 7.9.10 - fixed #11721: spamStopWords not in WebGUI.conf.original + - fixed #11729: Trash your User Function Style, and WebGUI locks you out 7.9.9 - fixed #11693: Shopping cart does not show for visitor user diff --git a/lib/WebGUI/Asset/Template.pm b/lib/WebGUI/Asset/Template.pm index 4838d06d5..b2457c0ad 100644 --- a/lib/WebGUI/Asset/Template.pm +++ b/lib/WebGUI/Asset/Template.pm @@ -47,6 +47,24 @@ These methods are available from this class: #------------------------------------------------------------------- +=head2 cut ( ) + +Extend the base method to handle cutting the User Function Style template and destroying your site. +If the current template is the User Function Style template with the Fail Safe template. + +=cut + +sub cut { + my ( $self ) = @_; + my $returnValue = $self->SUPER::cut(); + if ($returnValue && $self->getId eq $self->session->setting->get('userFunctionStyleId')) { + $self->session->setting->set('userFunctionStyleId', 'PBtmpl0000000000000060'); + } + return $returnValue; +} + +#------------------------------------------------------------------- + =head2 definition ( session, definition ) Defines the properties of this asset. @@ -658,6 +676,24 @@ sub processRaw { #------------------------------------------------------------------- +=head2 purge ( ) + +Extend the base method to handle purging the User Function Style template and destroying your site. +If the current template is the User Function Style template with the Fail Safe template. + +=cut + +sub purge { + my $self = shift; + my $returnValue = $self->SUPER::purge; + if ($returnValue && $self->getId eq $self->session->setting->get('userFunctionStyleId')) { + $self->session->setting->set('userFunctionStyleId', 'PBtmpl0000000000000060'); + } + return $returnValue; +} + +#------------------------------------------------------------------- + =head2 update Override update from Asset.pm to handle backwards compatibility with the old diff --git a/t/Asset/Template.t b/t/Asset/Template.t index bfbc0ebb3..fa5b76d1d 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 => 44; # increment this value for each test you create +use Test::More tests => 48; # increment this value for each test you create use Test::Deep; use Data::Dumper; use JSON qw{ from_json }; @@ -183,3 +183,35 @@ WebGUI::Test->restoreLogging; WebGUI::Test->addToCleanup(WebGUI::VersionTag->getWorking($session)); +my $userStyleTemplate = $importNode->addChild({ + className => "WebGUI::Asset::Template", + title => "user function style", + url => "ufs", + template => "user function style", + namespace => 'WebGUI Test Template', +}); + +my $someOtherTemplate = $importNode->addChild({ + className => "WebGUI::Asset::Template", + title => "some other template", + url => "sot", + template => "some other template", + namespace => 'WebGUI Test Template', +}); + +$session->setting->set('userFunctionStyleId', $userStyleTemplate->getId); + +my $purgeCutTag = WebGUI::VersionTag->getWorking($session); +WebGUI::Test->addToCleanup($purgeCutTag); + +is($session->setting->get('userFunctionStyleId'), $userStyleTemplate->getId, 'Setup for cut tests.'); + +$userStyleTemplate->cut; +is($session->setting->get('userFunctionStyleId'), 'PBtmpl0000000000000060', 'cut resets the user function style template to Fail Safe'); + +$userStyleTemplate->publish; +$session->setting->set('userFunctionStyleId', $userStyleTemplate->getId); +is($session->setting->get('userFunctionStyleId'), $userStyleTemplate->getId, 'Reset for purge test'); + +$userStyleTemplate->purge; +is($session->setting->get('userFunctionStyleId'), 'PBtmpl0000000000000060', 'purge resets the user function style template to Fail Safe');