From 20e3e5f01946ceb1f094db8522dbfdae95d4a531 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Fri, 24 May 2013 19:46:15 +1200 Subject: [PATCH] API: Deprecate static methods in favour of Config API. --- _config.php | 1 + code/extensions/FilesystemPublisher.php | 1 + code/extensions/StaticPublisher.php | 38 +++++++++++++++++++------ tasks/RebuildStaticCacheTask.php | 4 +-- tests/FilesystemPublisherTest.php | 14 +++++++-- 5 files changed, 45 insertions(+), 13 deletions(-) diff --git a/_config.php b/_config.php index 4580bce..f364132 100644 --- a/_config.php +++ b/_config.php @@ -1,3 +1,4 @@ update('StaticPublisher', 'static_publisher_theme', $theme); } /** + * @deprecated + * * @return string */ public static function static_publisher_theme() { - return self::$static_publisher_theme; + Deprecation::notice('1.0', 'Use the new config system. SSViewer.static_publisher_theme'); + + return Config::inst()->get('StaticPublisher', 'static_publisher_theme'); } /** + * @deprecated + * * @return boolean */ public static function echo_progress() { - return (boolean)self::$echo_progress; + Deprecation::notice('1.0', 'Use the new config system. SSViewer.static_publisher_theme'); + + return Config::inst()->get('StaticPublisher', 'echo_progress'); } /** - * Either turns on (boolean true) or off (boolean false) the progress indicators. - * @see StaticPublisher::$echo_progress + * @deprecated + * */ public static function set_echo_progress($progress) { - self::$echo_progress = (boolean)$progress; + Deprecation::notice('1.0', 'Use the new config system. SSViewer.static_publisher_theme'); + + Config::inst()->get('StaticPublisher', 'echo_progress', $progress); } /** diff --git a/tasks/RebuildStaticCacheTask.php b/tasks/RebuildStaticCacheTask.php index c7f4005..5eb447e 100644 --- a/tasks/RebuildStaticCacheTask.php +++ b/tasks/RebuildStaticCacheTask.php @@ -5,8 +5,8 @@ class RebuildStaticCacheTask extends BuildTask { public function run($request) { - StaticPublisher::set_echo_progress(true); - + Config::inst()->update('StaticPublisher', 'echo_progress', true); + $page = singleton('Page'); if(!$page->hasMethod('allPagesToCache')) { diff --git a/tests/FilesystemPublisherTest.php b/tests/FilesystemPublisherTest.php index 4106308..f843fb5 100644 --- a/tests/FilesystemPublisherTest.php +++ b/tests/FilesystemPublisherTest.php @@ -1,4 +1,5 @@ assertEquals($fsp->class, 'FilesystemPublisher'); } @@ -146,7 +148,7 @@ class FilesystemPublisherTest extends SapphireTest { //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'); + Config::inst()->update('StaticPublisher', 'static_publisher_theme', 'otherTheme'); $current_theme = StaticPublisher::static_publisher_theme(); $this->assertNotEquals($current_theme, $default_theme, 'The static publisher theme overrides the custom theme'); @@ -166,6 +168,7 @@ class FilesystemPublisherTest extends SapphireTest { $l2_1->URLSegment = strtolower(__CLASS__).'-level-2-1'; $l2_1->ParentID = $l1->ID; $l2_1->write(); + $l2_1->doPublish(); $response = Director::test($l2_1->AbsoluteLink()); @@ -175,12 +178,16 @@ class FilesystemPublisherTest extends SapphireTest { $l2_2->URLSegment = strtolower(__CLASS__).'-level-2-2'; $l2_2->ParentID = $l1->ID; $l2_2->write(); - $l2_2->doPublish(); + $l2_2->doPublish(); + $response = Director::test($l2_2->AbsoluteLink()); $this->assertEquals(trim($response->getBody()), "linkcurrent", "current page is level 2-2"); } } +/** + * @package staticpublisher + */ class StaticPublisherTestPage extends Page implements TestOnly { private static $allowed_children = array( @@ -197,6 +204,9 @@ class StaticPublisherTestPage extends Page implements TestOnly { } } +/** + * @package staticpublisher + */ class StaticPublisherTestPage_Controller extends Page_Controller { }