Skip to content

Commit

Permalink
BUGFIX: static publishing now uses the last non-null theme, OR the va…
Browse files Browse the repository at this point in the history
…lue 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
  • Loading branch information
Sam Minnee committed Oct 4, 2010
1 parent 88db7a6 commit cdfbc8a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
10 changes: 9 additions & 1 deletion code/staticpublisher/FilesystemPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ function publishPages($urls) {
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');
Expand Down Expand Up @@ -255,4 +263,4 @@ public function getExistingStaticCacheFiles() {

}

?>
?>
17 changes: 16 additions & 1 deletion code/staticpublisher/StaticPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -133,6 +140,14 @@ function externalReferencesFor($content) {

return $urls;
}

function set_static_publisher_theme($theme){
self::$static_publisher_theme=$theme;
}

function static_publisher_theme(){
return self::$static_publisher_theme;
}
}

?>
?>
32 changes: 32 additions & 0 deletions tests/FilesystemPublisherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,36 @@ function testHomepageMapIsWithStaticPublishing() {
);
}

/*
* 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');


}

}

0 comments on commit cdfbc8a

Please sign in to comment.