diff --git a/code/staticpublisher/FilesystemPublisher.php b/code/staticpublisher/FilesystemPublisher.php index a02a788d..8548be40 100644 --- a/code/staticpublisher/FilesystemPublisher.php +++ b/code/staticpublisher/FilesystemPublisher.php @@ -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 { } -?> +?> \ No newline at end of file diff --git a/code/staticpublisher/StaticPublisher.php b/code/staticpublisher/StaticPublisher.php index 6831d10e..43309737 100644 --- a/code/staticpublisher/StaticPublisher.php +++ b/code/staticpublisher/StaticPublisher.php @@ -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; + } } -?> +?> \ No newline at end of file diff --git a/tests/FilesystemPublisherTest.php b/tests/FilesystemPublisherTest.php index 11f2d137..49e9cf05 100644 --- a/tests/FilesystemPublisherTest.php +++ b/tests/FilesystemPublisherTest.php @@ -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'); + + + } + } \ No newline at end of file