BUGFIX: static publishing now uses the last non-null theme, OR the value defined in StaticPublisher::static_publisher_theme. (from r103255)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@111661 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2010-10-04 06:14:49 +00:00
parent 88db7a6a50
commit cdfbc8a604
3 changed files with 57 additions and 2 deletions

View File

@ -99,6 +99,14 @@ class FilesystemPublisher extends StaticPublisher {
increase_time_limit_to();
increase_memory_limit_to();
// Set the appropriate theme for this publication batch.
// This may have been set explicitly via StaticPublisher::static_publisher_theme,
// or we can use the last non-null theme.
if(!StaticPublisher::static_publisher_theme())
SSViewer::set_theme(SSViewer::current_custom_theme());
else
SSViewer::set_theme(StaticPublisher::static_publisher_theme());
$currentBaseURL = Director::baseURL();
if(self::$static_base_url) Director::setBaseURL(self::$static_base_url);
if($this->fileExtension == 'php') SSViewer::setOption('rewriteHashlinks', 'php');
@ -255,4 +263,4 @@ class FilesystemPublisher extends StaticPublisher {
}
?>
?>

View File

@ -17,6 +17,13 @@ abstract class StaticPublisher extends DataObjectDecorator {
*/
static $disable_realtime = false;
/*
* This is the current static publishing theme, which can be set at any point
* If it's not set, then the last non-null theme, set via SSViewer::set_theme() is used
* The obvious place to set this is in _config.php
*/
static $static_publisher_theme=false;
abstract function publishPages($pages);
abstract function unpublishPages($pages);
@ -133,6 +140,14 @@ abstract class StaticPublisher extends DataObjectDecorator {
return $urls;
}
function set_static_publisher_theme($theme){
self::$static_publisher_theme=$theme;
}
function static_publisher_theme(){
return self::$static_publisher_theme;
}
}
?>
?>

View File

@ -71,4 +71,36 @@ class FilesystemPublisherTest extends SapphireTest {
);
}
/*
* These are a few simple tests to check that we will be retrieving the correct theme when we need it
* StaticPublishing needs to be able to retrieve a non-null theme at the time publishPages() is called.
*/
function testStaticPublisherTheme(){
//This will be the name of the default theme of this particular project
$default_theme=SSViewer::current_theme();
$p1 = new Page();
$p1->URLSegment = strtolower(__CLASS__).'-page-1';
$p1->HomepageForDomain = '';
$p1->write();
$p1->doPublish();
$current_theme=SSViewer::current_custom_theme();
$this->assertEquals($current_theme, $default_theme, 'After a standard publication, the theme is correct');
//The CMS sometimes sets the theme to null. Check that the $current_custom_theme is still the default
SSViewer::set_theme(null);
$current_theme=SSViewer::current_custom_theme();
$this->assertEquals($current_theme, $default_theme, 'After a setting the theme to null, the default theme is correct');
//We can set the static_publishing theme to something completely different:
//Static publishing will use this one instead of the current_custom_theme if it is not false
StaticPublisher::set_static_publisher_theme('otherTheme');
$current_theme=StaticPublisher::static_publisher_theme();
$this->assertNotEquals($current_theme, $default_theme, 'The static publisher theme overrides the custom theme');
}
}