API: Deprecate static methods in favour of Config API.

This commit is contained in:
Will Rossiter 2013-05-24 19:46:15 +12:00
parent fc1e7bd8a2
commit 20e3e5f019
5 changed files with 45 additions and 13 deletions

View File

@ -1,3 +1,4 @@
<?php <?php
Deprecation::notification_version('1.0', 'staticpublisher');
define('STATIC_MODULE_DIR', dirname(__FILE__)); define('STATIC_MODULE_DIR', dirname(__FILE__));

View File

@ -17,6 +17,7 @@ class FilesystemPublisher extends StaticPublisher {
/** /**
* @var string * @var string
*
* @config * @config
*/ */
private static $static_base_url = null; private static $static_base_url = null;

View File

@ -3,22 +3,27 @@
* @package staticpublisher * @package staticpublisher
*/ */
abstract class StaticPublisher extends DataExtension { abstract class StaticPublisher extends DataExtension {
/** /**
* Defines whether to output information about publishing or not. By * Defines whether to output information about publishing or not. By
* default, this is off, and should be turned on when you want debugging * default, this is off, and should be turned on when you want debugging
* (for example, in a cron task). * (for example, in a cron task).
* *
* @var boolean * @var boolean
*
* @config
*/ */
protected static $echo_progress = false; private static $echo_progress = false;
/** /**
* Realtime static publishing... the second a page is saved, it is * Realtime static publishing... the second a page is saved, it is
* written to the cache. * written to the cache.
* *
* @var boolean * @var boolean
*
* @config
*/ */
public static $disable_realtime = false; private static $disable_realtime = false;
/** /**
* This is the current static publishing theme, which can be set at any * This is the current static publishing theme, which can be set at any
@ -27,8 +32,10 @@ abstract class StaticPublisher extends DataExtension {
* _config.php * _config.php
* *
* @var string * @var string
*
* @config
*/ */
protected static $static_publisher_theme = false; private static $static_publisher_theme = false;
/** /**
* @var boolean includes a timestamp at the bottom of the generated HTML * @var boolean includes a timestamp at the bottom of the generated HTML
@ -50,32 +57,45 @@ abstract class StaticPublisher extends DataExtension {
abstract function unpublishPages($pages); abstract function unpublishPages($pages);
/** /**
* @deprecated
* @param string * @param string
*/ */
public static function set_static_publisher_theme($theme) { public static function set_static_publisher_theme($theme) {
self::$static_publisher_theme=$theme; Deprecation::notice('1.0', 'Use the new config system. SSViewer.static_publisher_theme');
Config::inst()->update('StaticPublisher', 'static_publisher_theme', $theme);
} }
/** /**
* @deprecated
*
* @return string * @return string
*/ */
public static function static_publisher_theme() { 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 * @return boolean
*/ */
public static function echo_progress() { 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. * @deprecated
* @see StaticPublisher::$echo_progress *
*/ */
public static function set_echo_progress($progress) { 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);
} }
/** /**

View File

@ -5,7 +5,7 @@
class RebuildStaticCacheTask extends BuildTask { class RebuildStaticCacheTask extends BuildTask {
public function run($request) { public function run($request) {
StaticPublisher::set_echo_progress(true); Config::inst()->update('StaticPublisher', 'echo_progress', true);
$page = singleton('Page'); $page = singleton('Page');

View File

@ -1,4 +1,5 @@
<?php <?php
/** /**
* Tests for the {@link FilesystemPublisher} class. * Tests for the {@link FilesystemPublisher} class.
* *
@ -122,6 +123,7 @@ class FilesystemPublisherTest extends SapphireTest {
*/ */
public function testHasCalledParentConstructor() { public function testHasCalledParentConstructor() {
$fsp = new FilesystemPublisher('.', '.html'); $fsp = new FilesystemPublisher('.', '.html');
$this->assertEquals($fsp->class, 'FilesystemPublisher'); $this->assertEquals($fsp->class, 'FilesystemPublisher');
} }
@ -146,7 +148,7 @@ class FilesystemPublisherTest extends SapphireTest {
//We can set the static_publishing theme to something completely different: //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 //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(); $current_theme = StaticPublisher::static_publisher_theme();
$this->assertNotEquals($current_theme, $default_theme, 'The static publisher theme overrides the custom 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->URLSegment = strtolower(__CLASS__).'-level-2-1';
$l2_1->ParentID = $l1->ID; $l2_1->ParentID = $l1->ID;
$l2_1->write(); $l2_1->write();
$l2_1->doPublish(); $l2_1->doPublish();
$response = Director::test($l2_1->AbsoluteLink()); $response = Director::test($l2_1->AbsoluteLink());
@ -176,11 +179,15 @@ class FilesystemPublisherTest extends SapphireTest {
$l2_2->ParentID = $l1->ID; $l2_2->ParentID = $l1->ID;
$l2_2->write(); $l2_2->write();
$l2_2->doPublish(); $l2_2->doPublish();
$response = Director::test($l2_2->AbsoluteLink()); $response = Director::test($l2_2->AbsoluteLink());
$this->assertEquals(trim($response->getBody()), "linkcurrent", "current page is level 2-2"); $this->assertEquals(trim($response->getBody()), "linkcurrent", "current page is level 2-2");
} }
} }
/**
* @package staticpublisher
*/
class StaticPublisherTestPage extends Page implements TestOnly { class StaticPublisherTestPage extends Page implements TestOnly {
private static $allowed_children = array( private static $allowed_children = array(
@ -197,6 +204,9 @@ class StaticPublisherTestPage extends Page implements TestOnly {
} }
} }
/**
* @package staticpublisher
*/
class StaticPublisherTestPage_Controller extends Page_Controller { class StaticPublisherTestPage_Controller extends Page_Controller {
} }