From 51c8e8639e9b5f1c258f21f640df2a6cf2af12df Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 18 Mar 2013 11:47:15 +0100 Subject: [PATCH] API Marked statics private, use Config API instead (#8317) See "Static configuration properties are now immutable, you must use Config API." in the 3.1 change log for details. --- code/controllers/AssetAdmin.php | 19 +-- code/controllers/CMSFileAddController.php | 10 +- code/controllers/CMSMain.php | 18 +-- code/controllers/CMSPageAddController.php | 12 +- code/controllers/CMSPageEditController.php | 10 +- code/controllers/CMSPageHistoryController.php | 16 +-- .../controllers/CMSPageSettingsController.php | 10 +- code/controllers/CMSPagesController.php | 12 +- code/controllers/CMSSettingsController.php | 12 +- code/controllers/ContentController.php | 6 +- code/controllers/ModelAsController.php | 6 +- code/controllers/ReportAdmin.php | 12 +- code/controllers/RootURLController.php | 13 +- code/controllers/SilverStripeNavigator.php | 12 +- code/controllers/StaticExporter.php | 4 +- code/forms/SiteTreeURLSegmentField.php | 2 +- code/model/ErrorPage.php | 33 +++-- code/model/RedirectorPage.php | 11 +- code/model/SiteConfig.php | 19 ++- code/model/SiteTree.php | 134 ++++++++++-------- code/model/SiteTreeFileExtension.php | 2 +- code/model/VirtualPage.php | 18 +-- code/reports/Report.php | 14 +- .../ContentControllerSearchExtension.php | 2 +- code/staticpublisher/FilesystemPublisher.php | 43 ++++-- .../RsyncMultiHostPublisher.php | 26 ++-- code/staticpublisher/StaticPublisher.php | 49 +++++-- tasks/RebuildStaticCacheTask.php | 6 +- tasks/RemoveOrphanedPagesTask.php | 2 +- tasks/SiteTreeMaintenanceTask.php | 2 +- tasks/UpgradeSiteTreePermissionSchemaTask.php | 3 +- tests/controller/CMSMainTest.php | 12 +- .../CMSPageHistoryControllerTest.php | 2 +- tests/controller/CMSSiteTreeFilterTest.php | 2 +- tests/controller/ContentControllerTest.php | 18 +-- tests/controller/ModelAsControllerTest.php | 10 +- tests/controller/RootURLControllerTest.php | 6 +- .../controller/SilverStripeNavigatorTest.php | 2 +- tests/model/ErrorPageTest.php | 12 +- tests/model/FileLinkTrackingTest.php | 2 +- tests/model/RedirectorPageTest.php | 4 +- tests/model/SiteConfigTest.php | 2 +- tests/model/SiteTreeActionsTest.php | 2 +- tests/model/SiteTreeBacklinksTest.php | 4 +- tests/model/SiteTreeBrokenLinksTest.php | 2 +- tests/model/SiteTreeHTMLEditorFieldTest.php | 4 +- tests/model/SiteTreePermissionsTest.php | 2 +- tests/model/SiteTreeTest.php | 54 +++---- tests/model/VirtualPageTest.php | 30 ++-- tests/reports/SideReportTest.php | 4 +- tests/search/CMSMainSearchFormTest.php | 2 +- tests/search/SearchFormTest.php | 2 +- .../FilesystemPublisherTest.php | 28 +--- .../tasks/MigrateSiteTreeLinkingTaskTest.php | 4 +- tests/tasks/RemoveOrphanedPagesTaskTest.php | 4 +- 55 files changed, 414 insertions(+), 338 deletions(-) diff --git a/code/controllers/AssetAdmin.php b/code/controllers/AssetAdmin.php index a1884162..3626982a 100644 --- a/code/controllers/AssetAdmin.php +++ b/code/controllers/AssetAdmin.php @@ -8,21 +8,22 @@ */ class AssetAdmin extends LeftAndMain implements PermissionProvider{ - static $url_segment = 'assets'; + private static $url_segment = 'assets'; - static $url_rule = '/$Action/$ID'; + private static $url_rule = '/$Action/$ID'; - static $menu_title = 'Files'; + private static $menu_title = 'Files'; - public static $tree_class = 'Folder'; + private static $tree_class = 'Folder'; /** + * @config * @see Upload->allowedMaxFileSize * @var int */ - public static $allowed_max_file_size; + private static $allowed_max_file_size; - public static $allowed_actions = array( + private static $allowed_actions = array( 'addfolder', 'delete', 'AddForm', @@ -121,8 +122,8 @@ JS // Category filter if(isset($params['AppCategory'])) { - if(isset(File::$app_categories[$params['AppCategory']])) { - $exts = File::$app_categories[$params['AppCategory']]; + if(isset(File::config()->app_categories[$params['AppCategory']])) { + $exts = File::config()->app_categories[$params['AppCategory']]; } else { $exts = array(); } @@ -470,7 +471,7 @@ JS $record->write(); mkdir($record->FullPath); - chmod($record->FullPath, Filesystem::$file_create_mask); + chmod($record->FullPath, Filesystem::config()->file_create_mask); if($parentRecord) { return $this->redirect(Controller::join_links($this->Link('show'), $parentRecord->ID)); diff --git a/code/controllers/CMSFileAddController.php b/code/controllers/CMSFileAddController.php index bcdfe58d..6c41820a 100644 --- a/code/controllers/CMSFileAddController.php +++ b/code/controllers/CMSFileAddController.php @@ -1,11 +1,11 @@ renderWith(array('AssetAdmin_UploadContent')); diff --git a/code/controllers/CMSMain.php b/code/controllers/CMSMain.php index 8efe5e6d..fbe29135 100644 --- a/code/controllers/CMSMain.php +++ b/code/controllers/CMSMain.php @@ -11,23 +11,23 @@ */ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionProvider { - static $url_segment = 'pages'; + private static $url_segment = 'pages'; - static $url_rule = '/$Action/$ID/$OtherID'; + private static $url_rule = '/$Action/$ID/$OtherID'; // Maintain a lower priority than other administration sections // so that Director does not think they are actions of CMSMain - static $url_priority = 39; + private static $url_priority = 39; - static $menu_title = 'Edit Page'; + private static $menu_title = 'Edit Page'; - static $menu_priority = 10; + private static $menu_priority = 10; - static $tree_class = "SiteTree"; + private static $tree_class = "SiteTree"; - static $subitem_class = "Member"; + private static $subitem_class = "Member"; - static $allowed_actions = array( + private static $allowed_actions = array( 'buildbrokenlinks', 'deleteitems', 'DeleteItemsForm', @@ -1125,7 +1125,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr } public function BatchActionParameters() { - $batchActions = CMSBatchActionHandler::$batch_actions; + $batchActions = CMSBatchActionHandler::config()->batch_actions; $forms = array(); foreach($batchActions as $urlSegment => $batchAction) { diff --git a/code/controllers/CMSPageAddController.php b/code/controllers/CMSPageAddController.php index 7e392536..3824b661 100644 --- a/code/controllers/CMSPageAddController.php +++ b/code/controllers/CMSPageAddController.php @@ -1,13 +1,13 @@ 'handleAction' ); diff --git a/code/controllers/CMSPageSettingsController.php b/code/controllers/CMSPageSettingsController.php index 9c7c4548..1bae5d9e 100644 --- a/code/controllers/CMSPageSettingsController.php +++ b/code/controllers/CMSPageSettingsController.php @@ -5,11 +5,11 @@ */ class CMSPageSettingsController extends CMSMain { - static $url_segment = 'pages/settings'; - static $url_rule = '/$Action/$ID/$OtherID'; - static $url_priority = 42; - static $required_permission_codes = 'CMS_ACCESS_CMSMain'; - static $session_namespace = 'CMSMain'; + private static $url_segment = 'pages/settings'; + private static $url_rule = '/$Action/$ID/$OtherID'; + private static $url_priority = 42; + private static $required_permission_codes = 'CMS_ACCESS_CMSMain'; + private static $session_namespace = 'CMSMain'; public function getEditForm($id = null, $fields = null) { $record = $this->getRecord($id ? $id : $this->currentPageID()); diff --git a/code/controllers/CMSPagesController.php b/code/controllers/CMSPagesController.php index 1df20395..fa940fa8 100644 --- a/code/controllers/CMSPagesController.php +++ b/code/controllers/CMSPagesController.php @@ -5,12 +5,12 @@ */ class CMSPagesController extends CMSMain { - static $url_segment = 'pages'; - static $url_rule = '/$Action/$ID/$OtherID'; - static $url_priority = 40; - static $menu_title = 'Pages'; - static $required_permission_codes = 'CMS_ACCESS_CMSMain'; - static $session_namespace = 'CMSMain'; + private static $url_segment = 'pages'; + private static $url_rule = '/$Action/$ID/$OtherID'; + private static $url_priority = 40; + private static $menu_title = 'Pages'; + private static $required_permission_codes = 'CMS_ACCESS_CMSMain'; + private static $session_namespace = 'CMSMain'; public function LinkPreview() { return false; diff --git a/code/controllers/CMSSettingsController.php b/code/controllers/CMSSettingsController.php index 338e1bf0..b9ec945c 100644 --- a/code/controllers/CMSSettingsController.php +++ b/code/controllers/CMSSettingsController.php @@ -1,12 +1,12 @@ Theme) { - SSViewer::set_theme($config->Theme); + Config::inst()->update('SSViewer', 'theme', $config->Theme); } } @@ -137,7 +137,7 @@ class ContentController extends Controller { // If nested URLs are enabled, and there is no action handler for the current request then attempt to pass // control to a child controller. This allows for the creation of chains of controllers which correspond to a // nested URL. - if($action && SiteTree::nested_urls() && !$this->hasAction($action)) { + if($action && SiteTree::config()->nested_urls && !$this->hasAction($action)) { // See ModelAdController->getNestedController() for similar logic if(class_exists('Translatable')) Translatable::disable_locale_filter(); // look for a page with this URLSegment diff --git a/code/controllers/ModelAsController.php b/code/controllers/ModelAsController.php index 5aeefc1f..90fa2081 100644 --- a/code/controllers/ModelAsController.php +++ b/code/controllers/ModelAsController.php @@ -95,7 +95,7 @@ class ModelAsController extends Controller implements NestedController { sprintf( '"URLSegment" = \'%s\' %s', Convert::raw2sql(rawurlencode($URLSegment)), - (SiteTree::nested_urls() ? 'AND "ParentID" = 0' : null) + (SiteTree::config()->nested_urls ? 'AND "ParentID" = 0' : null) ) ); if(class_exists('Translatable')) Translatable::enable_locale_filter(); @@ -148,10 +148,10 @@ class ModelAsController extends Controller implements NestedController { static public function find_old_page($URLSegment,$parentID = 0, $ignoreNestedURLs = false) { $URLSegment = Convert::raw2sql(rawurlencode($URLSegment)); - $useParentIDFilter = SiteTree::nested_urls() && $parentID; + $useParentIDFilter = SiteTree::config()->nested_urls && $parentID; // First look for a non-nested page that has a unique URLSegment and can be redirected to. - if(SiteTree::nested_urls()) { + if(SiteTree::config()->nested_urls) { $pages = DataObject::get( 'SiteTree', "\"URLSegment\" = '$URLSegment'" . ($useParentIDFilter ? ' AND "ParentID" = ' . (int)$parentID : '') diff --git a/code/controllers/ReportAdmin.php b/code/controllers/ReportAdmin.php index 21067b78..f1f41808 100644 --- a/code/controllers/ReportAdmin.php +++ b/code/controllers/ReportAdmin.php @@ -13,17 +13,15 @@ */ class ReportAdmin extends LeftAndMain implements PermissionProvider { - static $url_segment = 'reports'; + private static $url_segment = 'reports'; - static $url_rule = '/$ReportClass/$Action'; + private static $url_rule = '/$ReportClass/$Action'; - static $menu_title = 'Reports'; + private static $menu_title = 'Reports'; - static $template_path = null; // defaults to (project)/templates/email - - static $tree_class = 'SS_Report'; + private static $tree_class = 'SS_Report'; - public static $url_handlers = array( + private static $url_handlers = array( '$ReportClass/$Action' => 'handleAction' ); diff --git a/code/controllers/RootURLController.php b/code/controllers/RootURLController.php index e13e419f..d6d70766 100644 --- a/code/controllers/RootURLController.php +++ b/code/controllers/RootURLController.php @@ -11,9 +11,10 @@ class RootURLController extends Controller { protected static $is_at_root = false; /** + * @config * @var string */ - protected static $default_homepage_link = 'home'; + private static $default_homepage_link = 'home'; /** * @var string @@ -49,7 +50,7 @@ class RootURLController extends Controller { ) { self::$cached_homepage_link = $link; } else { - self::$cached_homepage_link = self::get_default_homepage_link(); + self::$cached_homepage_link = Config::inst()->get('RootURLController', 'default_homepage_link'); } } } @@ -61,19 +62,23 @@ class RootURLController extends Controller { * Set the URL Segment used for your homepage when it is created by dev/build. * This allows you to use home page URLs other than the default "home". * + * @deprecated 3.2 Use the "RootURLController.default_homepage_link" config setting instead * @param string $urlsegment the URL segment for your home page */ static public function set_default_homepage_link($urlsegment = "home") { - self::$default_homepage_link = $urlsegment; + Deprecation::notice('3.2', 'Use the "RootURLController.default_homepage_link" config setting instead'); + Config::inst()->update('RootURLController', 'default_homepage_link', $urlsegment); } /** * Gets the link that denotes the homepage if there is not one explicitly defined for this HTTP_HOST value. * + * @deprecated 3.2 Use the "RootURLController.default_homepage_link" config setting instead * @return string */ static public function get_default_homepage_link() { - return self::$default_homepage_link; + Deprecation::notice('3.2', 'Use the "RootURLController.default_homepage_link" config setting instead'); + return Config::inst()->get('RootURLController', 'default_homepage_link'); } /** diff --git a/code/controllers/SilverStripeNavigator.php b/code/controllers/SilverStripeNavigator.php index ae3dabe8..3aff0f0c 100644 --- a/code/controllers/SilverStripeNavigator.php +++ b/code/controllers/SilverStripeNavigator.php @@ -219,7 +219,8 @@ class SilverStripeNavigatorItem extends ViewableData { * @subpackage content */ class SilverStripeNavigatorItem_CMSLink extends SilverStripeNavigatorItem { - static $priority = 10; + /** @config */ + private static $priority = 10; public function getHTML() { return sprintf( @@ -257,7 +258,8 @@ class SilverStripeNavigatorItem_CMSLink extends SilverStripeNavigatorItem { * @subpackage content */ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem { - static $priority = 20; + /** @config */ + private static $priority = 20; public function getHTML() { $draftPage = $this->getDraftPage(); @@ -316,7 +318,8 @@ class SilverStripeNavigatorItem_StageLink extends SilverStripeNavigatorItem { * @subpackage content */ class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem { - static $priority = 30; + /** @config */ + private static $priority = 30; public function getHTML() { $livePage = $this->getLivePage(); @@ -369,7 +372,8 @@ class SilverStripeNavigatorItem_LiveLink extends SilverStripeNavigatorItem { * @subpackage content */ class SilverStripeNavigatorItem_ArchiveLink extends SilverStripeNavigatorItem { - static $priority = 40; + /** @config */ + private static $priority = 40; public function getHTML() { $this->recordLink = $this->record->AbsoluteLink(); diff --git a/code/controllers/StaticExporter.php b/code/controllers/StaticExporter.php index 5462a78a..613f2e76 100644 --- a/code/controllers/StaticExporter.php +++ b/code/controllers/StaticExporter.php @@ -22,7 +22,7 @@ */ class StaticExporter extends Controller { - static $allowed_actions = array( + private static $allowed_actions = array( 'index', 'export', ); @@ -58,7 +58,7 @@ class StaticExporter extends Controller { if(isset($_REQUEST['baseurl'])) { $base = $_REQUEST['baseurl']; if(substr($base,-1) != '/') $base .= '/'; - Director::setBaseURL($base); + Config::inst()->update('Director', 'alternate_base_url', $base); } // setup temporary folders diff --git a/code/forms/SiteTreeURLSegmentField.php b/code/forms/SiteTreeURLSegmentField.php index 0cac40d2..3ff94b1d 100644 --- a/code/forms/SiteTreeURLSegmentField.php +++ b/code/forms/SiteTreeURLSegmentField.php @@ -17,7 +17,7 @@ class SiteTreeURLSegmentField extends TextField { */ protected $helpText, $urlPrefix, $urlSuffix; - static $allowed_actions = array( + private static $allowed_actions = array( 'suggest' ); diff --git a/code/model/ErrorPage.php b/code/model/ErrorPage.php index e40b4e5e..e5603b21 100644 --- a/code/model/ErrorPage.php +++ b/code/model/ErrorPage.php @@ -13,20 +13,21 @@ */ class ErrorPage extends Page { - static $db = array( + private static $db = array( "ErrorCode" => "Int", ); - static $defaults = array( + private static $defaults = array( "ShowInMenus" => 0, "ShowInSearch" => 0 ); - static $allowed_children = array(); - - static $description = 'Custom content for different error cases (e.g. "Page not found")'; + private static $allowed_children = array(); - protected static $static_filepath = ASSETS_PATH; + private static $description = 'Custom content for different error cases (e.g. "Page not found")'; + + /** @config */ + private static $static_filepath = ASSETS_PATH; public function canAddChildren($member = null) { return false; } @@ -204,10 +205,10 @@ class ErrorPage extends Page { parent::doPublish(); // Run the page (reset the theme, it might've been disabled by LeftAndMain::init()) - $oldTheme = SSViewer::current_theme(); - SSViewer::set_theme(SSViewer::current_custom_theme()); + $oldTheme = Config::inst()->get('SSViewer', 'theme'); + Config::inst()->update('SSViewer', 'theme', Config::inst()->get('SSViewer', 'custom_theme')); $response = Director::test(Director::makeRelative($this->Link())); - SSViewer::set_theme($oldTheme); + Config::inst()->update('SSViewer', 'theme', $oldTheme); $errorContent = $response->getBody(); @@ -262,27 +263,31 @@ class ErrorPage extends Page { return singleton('ErrorPage')-> alternateFilepathForErrorcode($statusCode, $locale); } if(class_exists('Translatable') && singleton('SiteTree')->hasExtension('Translatable') && $locale && $locale != Translatable::default_locale()) { - return self::$static_filepath . "/error-{$statusCode}-{$locale}.html"; + return self::config()->static_filepath . "/error-{$statusCode}-{$locale}.html"; } else { - return self::$static_filepath . "/error-{$statusCode}.html"; + return self::config()->static_filepath . "/error-{$statusCode}.html"; } } /** * Set the path where static error files are saved through {@link publish()}. * Defaults to /assets. - * + * + * @deprecated 3.2 Use "ErrorPage.static_file_path" instead * @param string $path */ static public function set_static_filepath($path) { - self::$static_filepath = $path; + Deprecation::notice('3.2', 'Use "ErrorPage.static_file_path" instead'); + self::config()->static_filepath = $path; } /** + * @deprecated 3.2 Use "ErrorPage.static_file_path" instead * @return string */ static public function get_static_filepath() { - return self::$static_filepath; + Deprecation::notice('3.2', 'Use "ErrorPage.static_file_path" instead'); + return self::config()->static_filepath; } } diff --git a/code/model/RedirectorPage.php b/code/model/RedirectorPage.php index 28c201f5..55021b23 100644 --- a/code/model/RedirectorPage.php +++ b/code/model/RedirectorPage.php @@ -6,23 +6,22 @@ * @subpackage content */ class RedirectorPage extends Page { - - static $description = 'Redirects to a different internal page'; + private static $description = 'Redirects to a different internal page'; - static $db = array( + private static $db = array( "RedirectionType" => "Enum('Internal,External','Internal')", "ExternalURL" => "Varchar(2083)" // 2083 is the maximum length of a URL in Internet Explorer. ); - static $defaults = array( + private static $defaults = array( "RedirectionType" => "Internal" ); - static $has_one = array( + private static $has_one = array( "LinkTo" => "SiteTree", ); - static $many_many = array( + private static $many_many = array( ); /** diff --git a/code/model/SiteConfig.php b/code/model/SiteConfig.php index c5e3d89e..c80539de 100644 --- a/code/model/SiteConfig.php +++ b/code/model/SiteConfig.php @@ -7,7 +7,7 @@ * @package cms */ class SiteConfig extends DataObject implements PermissionProvider { - static $db = array( + private static $db = array( "Title" => "Varchar(255)", "Tagline" => "Varchar(255)", "Theme" => "Varchar(255)", @@ -16,16 +16,24 @@ class SiteConfig extends DataObject implements PermissionProvider { "CanCreateTopLevelType" => "Enum('LoggedInUsers, OnlyTheseUsers', 'LoggedInUsers')", ); - static $many_many = array( + private static $many_many = array( "ViewerGroups" => "Group", "EditorGroups" => "Group", "CreateTopLevelGroups" => "Group" ); - protected static $disabled_themes = array(); + /** + * @config + * @var array + */ + private static $disabled_themes = array(); + /** + * @deprecated 3.2 Use the "SiteConfig.disabled_themes" config setting instead + */ static public function disable_theme($theme) { - self::$disabled_themes[$theme] = $theme; + Deprecation::notice('3.2', 'Use the "SiteConfig.disabled_themes" config setting instead'); + Config::inst()->update('SiteConfig', 'disabled_themes', array($theme)); } public function populateDefaults() @@ -132,7 +140,8 @@ class SiteConfig extends DataObject implements PermissionProvider { */ public function getAvailableThemes($baseDir = null) { $themes = SSViewer::get_themes($baseDir); - foreach(self::$disabled_themes as $theme) { + $disabled = (array)$this->config()->disabled_themes; + foreach($disabled as $theme) { if(isset($themes[$theme])) unset($themes[$theme]); } return $themes; diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php index 770f2110..50b5052b 100644 --- a/code/model/SiteTree.php +++ b/code/model/SiteTree.php @@ -26,52 +26,58 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid * * Note that this setting is cached when used in the CMS, use the "flush" query parameter to clear it. * + * @config * @var array */ - static $allowed_children = array("SiteTree"); + private static $allowed_children = array("SiteTree"); /** * The default child class for this page. * Note: Value might be cached, see {@link $allowed_chilren}. * + * @config * @var string */ - static $default_child = "Page"; + private static $default_child = "Page"; /** * The default parent class for this page. * Note: Value might be cached, see {@link $allowed_chilren}. * + * @config * @var string */ - static $default_parent = null; + private static $default_parent = null; /** * Controls whether a page can be in the root of the site tree. * Note: Value might be cached, see {@link $allowed_chilren}. * + * @config * @var bool */ - static $can_be_root = true; + private static $can_be_root = true; /** * List of permission codes a user can have to allow a user to create a page of this type. * Note: Value might be cached, see {@link $allowed_chilren}. * + * @config * @var array */ - static $need_permission = null; + private static $need_permission = null; /** * If you extend a class, and don't want to be able to select the old class * in the cms, set this to the old class name. Eg, if you extended Product * to make ImprovedProduct, then you would set $hide_ancestor to Product. * + * @config * @var string */ - static $hide_ancestor = null; + private static $hide_ancestor = null; - static $db = array( + private static $db = array( "URLSegment" => "Varchar(255)", "Title" => "Varchar(255)", "MenuTitle" => "Varchar(100)", @@ -88,27 +94,27 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid "CanEditType" => "Enum('LoggedInUsers, OnlyTheseUsers, Inherit', 'Inherit')", ); - static $indexes = array( + private static $indexes = array( "URLSegment" => true, ); - static $many_many = array( + private static $many_many = array( "LinkTracking" => "SiteTree", "ImageTracking" => "File", "ViewerGroups" => "Group", "EditorGroups" => "Group", ); - static $belongs_many_many = array( + private static $belongs_many_many = array( "BackLinkTracking" => "SiteTree" ); - static $many_many_extraFields = array( + private static $many_many_extraFields = array( "LinkTracking" => array("FieldName" => "Varchar"), "ImageTracking" => array("FieldName" => "Varchar") ); - static $casting = array( + private static $casting = array( "Breadcrumbs" => "HTMLText", "LastEdited" => "SS_Datetime", "Created" => "SS_Datetime", @@ -117,67 +123,64 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid 'AbsoluteLink' => 'Text', ); - static $defaults = array( + private static $defaults = array( "ShowInMenus" => 1, "ShowInSearch" => 1, "CanViewType" => "Inherit", "CanEditType" => "Inherit" ); - static $versioning = array( + private static $versioning = array( "Stage", "Live" ); - static $default_sort = "\"Sort\""; + private static $default_sort = "\"Sort\""; /** * If this is false, the class cannot be created in the CMS by regular content authors, only by ADMINs. * @var boolean + * @config */ - static $can_create = true; - - /** - * @see CMSMain::generateTreeStylingCSS() - */ - static $page_states = array('readonly'); + private static $can_create = true; /** * Icon to use in the CMS page tree. This should be the full filename, relative to the webroot. * Also supports custom CSS rule contents (applied to the correct selector for the tree UI implementation). * * @see CMSMain::generateTreeStylingCSS() - * + * @config * @var string */ - static $icon = null; + private static $icon = null; /** + * @config * @var String Description of the class functionality, typically shown to a user * when selecting which page type to create. Translated through {@link provideI18nEntities()}. */ - static $description = 'Generic content page'; + private static $description = 'Generic content page'; - static $extensions = array( + private static $extensions = array( "Hierarchy", "Versioned('Stage', 'Live')", ); - static $searchable_fields = array( + private static $searchable_fields = array( 'Title', 'Content', ); - static $field_labels = array( + private static $field_labels = array( 'URLSegment' => 'URL' ); /** - * @see SiteTree::nested_urls() + * @config */ private static $nested_urls = true; /** - * @see SiteTree::set_create_default_pages() + * @config */ private static $create_default_pages = true; @@ -192,12 +195,13 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid * of IDs mapped to their boolean permission ability (true=allow, false=deny). * See {@link batch_permission_check()} for details. */ - public static $cache_permissions = array(); + private static $cache_permissions = array(); /** + * @config * @var boolean */ - protected static $enforce_strict_hierarchy = true; + private static $enforce_strict_hierarchy = true; protected $_cache_statusFlags = null; @@ -205,59 +209,77 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid * Determines if the system should avoid orphaned pages * by deleting all children when the their parent is deleted (TRUE), * or rather preserve this data even if its not reachable through any navigation path (FALSE). - * + * + * @deprecated 3.2 Use the "SiteTree.enforce_strict_hierarchy" config setting instead * @param boolean */ static public function set_enforce_strict_hierarchy($to) { - self::$enforce_strict_hierarchy = $to; + Deprecation::notice('3.2', 'Use the "SiteTree.enforce_strict_hierarchy" config setting instead'); + Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', $to); } /** + * @deprecated 3.2 Use the "SiteTree.enforce_strict_hierarchy" config setting instead * @return boolean */ static public function get_enforce_strict_hierarchy() { - return self::$enforce_strict_hierarchy; + Deprecation::notice('3.2', 'Use the "SiteTree.enforce_strict_hierarchy" config setting instead'); + return Config::inst()->get('SiteTree', 'enforce_strict_hierarchy'); } /** * Returns TRUE if nested URLs (e.g. page/sub-page/) are currently enabled on this site. * + * @deprecated 3.2 Use the "SiteTree.nested_urls" config setting instead * @return bool */ static public function nested_urls() { - return self::$nested_urls; + Deprecation::notice('3.2', 'Use the "SiteTree.nested_urls" config setting instead'); + return Config::inst()->get('SiteTree', 'nested_urls'); } + /** + * @deprecated 3.2 Use the "SiteTree.nested_urls" config setting instead + */ static public function enable_nested_urls() { - self::$nested_urls = true; + Deprecation::notice('3.2', 'Use the "SiteTree.nested_urls" config setting instead'); + Config::inst()->update('SiteTree', 'nested_urls', true); } + /** + * @deprecated 3.2 Use the "SiteTree.nested_urls" config setting instead + */ static public function disable_nested_urls() { - self::$nested_urls = false; + Deprecation::notice('3.2', 'Use the "SiteTree.nested_urls" config setting instead'); + Config::inst()->update('SiteTree', 'nested_urls', false); } /** * Set the (re)creation of default pages on /dev/build * + * @deprecated 3.2 Use the "SiteTree.create_default_pages" config setting instead * @param bool $option */ static public function set_create_default_pages($option = true) { - self::$create_default_pages = $option; + Deprecation::notice('3.2', 'Use the "SiteTree.create_default_pages" config setting instead'); + Config::inst()->update('SiteTree', 'create_default_pages', $option); } /** * Return true if default pages should be created on /dev/build. * + * @deprecated 3.2 Use the "SiteTree.create_default_pages" config setting instead * @return bool */ static public function get_create_default_pages() { - return self::$create_default_pages; + Deprecation::notice('3.2', 'Use the "SiteTree.create_default_pages" config setting instead'); + return Config::inst()->get('SiteTree', 'create_default_pages'); } /** * Fetches the {@link SiteTree} object that maps to a link. * - * If you have enabled {@link SiteTree::nested_urls()} on this site, then you can use a nested link such as + * If you have enabled {@link SiteTree::config()->nested_urls} on this site, then you can use a nested link such as * "about-us/staff/", and this function will traverse down the URL chain and grab the appropriate link. * * Note that if no model can be found, this method will fall over to a extended alternateGetByLink method provided @@ -279,17 +301,17 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid // Grab the initial root level page to traverse down from. $URLSegment = array_shift($parts); $sitetree = DataObject::get_one ( - 'SiteTree', "\"URLSegment\" = '$URLSegment'" . (self::nested_urls() ? ' AND "ParentID" = 0' : ''), $cache + 'SiteTree', "\"URLSegment\" = '$URLSegment'" . (self::config()->nested_urls ? ' AND "ParentID" = 0' : ''), $cache ); /// Fall back on a unique URLSegment for b/c. - if(!$sitetree && self::nested_urls() && $page = DataObject::get('SiteTree', "\"URLSegment\" = '$URLSegment'")->First()) { + if(!$sitetree && self::config()->nested_urls && $page = DataObject::get('SiteTree', "\"URLSegment\" = '$URLSegment'")->First()) { return $page; } // Attempt to grab an alternative page from extensions. if(!$sitetree) { - $parentID = self::nested_urls() ? 0 : null; + $parentID = self::config()->nested_urls ? 0 : null; if($alternatives = singleton('SiteTree')->extend('alternateGetByLink', $URLSegment, $parentID)) { foreach($alternatives as $alternative) if($alternative) $sitetree = $alternative; @@ -299,7 +321,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid } // Check if we have any more URL parts to parse. - if(!self::nested_urls() || !count($parts)) return $sitetree; + if(!self::config()->nested_urls || !count($parts)) return $sitetree; // Traverse down the remaining URL segments and grab the relevant SiteTree objects. foreach($parts as $segment) { @@ -438,7 +460,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid * @return string */ public function RelativeLink($action = null) { - if($this->ParentID && self::nested_urls()) { + if($this->ParentID && self::config()->nested_urls) { $base = $this->Parent()->RelativeLink($this->URLSegment); } else { $base = $this->URLSegment; @@ -1275,7 +1297,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid $tags .= "\n"; - $charset = ContentNegotiator::get_encoding(); + $charset = Config::inst()->get('ContentNegotiator', 'encoding'); $tags .= "\n"; if($this->MetaDescription) { $tags .= "MetaDescription) . "\" />\n"; @@ -1322,12 +1344,12 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid parent::requireDefaultRecords(); // default pages - if($this->class == 'SiteTree' && self::get_create_default_pages()) { - if(!SiteTree::get_by_link(RootURLController::get_default_homepage_link())) { + if($this->class == 'SiteTree' && $this->config()->create_default_pages) { + if(!SiteTree::get_by_link(Config::inst()->get('RootURLController', 'default_homepage_link'))) { $homepage = new Page(); $homepage->Title = _t('SiteTree.DEFAULTHOMETITLE', 'Home'); $homepage->Content = _t('SiteTree.DEFAULTHOMECONTENT', '

Welcome to SilverStripe! This is the default homepage. You can edit this page by opening the CMS. You can now access the developer documentation, or begin the tutorials.

'); - $homepage->URLSegment = RootURLController::get_default_homepage_link(); + $homepage->URLSegment = Config::inst()->get('RootURLController', 'default_homepage_link'); $homepage->Sort = 1; $homepage->write(); $homepage->publish('Stage', 'Live'); @@ -1467,7 +1489,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid parent::onBeforeDelete(); // If deleting this page, delete all its children. - if(SiteTree::get_enforce_strict_hierarchy() && $children = $this->Children()) { + if(SiteTree::config()->enforce_strict_hierarchy && $children = $this->Children()) { foreach($children as $child) { $child->delete(); } @@ -1542,20 +1564,20 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid * @return bool */ public function validURLSegment() { - if(self::nested_urls() && $parent = $this->Parent()) { + if(self::config()->nested_urls && $parent = $this->Parent()) { if($controller = ModelAsController::controller_for($parent)) { if($controller instanceof Controller && $controller->hasAction($this->URLSegment)) return false; } } - if(!self::nested_urls() || !$this->ParentID) { + if(!self::config()->nested_urls || !$this->ParentID) { if(class_exists($this->URLSegment) && is_subclass_of($this->URLSegment, 'RequestHandler')) return false; } $IDFilter = ($this->ID) ? "AND \"SiteTree\".\"ID\" <> $this->ID" : null; $parentFilter = null; - if(self::nested_urls()) { + if(self::config()->nested_urls) { if($this->ParentID) { $parentFilter = " AND \"SiteTree\".\"ParentID\" = $this->ParentID"; } else { @@ -1826,13 +1848,13 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid $baseLink = Controller::join_links ( Director::absoluteBaseURL(), - (self::nested_urls() && $this->ParentID ? $this->Parent()->RelativeLink(true) : null) + (self::config()->nested_urls && $this->ParentID ? $this->Parent()->RelativeLink(true) : null) ); $urlsegment = new SiteTreeURLSegmentField("URLSegment", $this->fieldLabel('URLSegment')); $urlsegment->setURLPrefix($baseLink); - $helpText = (self::nested_urls() && count($this->Children())) ? $this->fieldLabel('LinkChangeNote') : ''; - if(!URLSegmentFilter::$default_allow_multibyte) { + $helpText = (self::config()->nested_urls && count($this->Children())) ? $this->fieldLabel('LinkChangeNote') : ''; + if(!Config::inst()->get('URLSegmentFilter', 'default_allow_multibyte')) { $helpText .= $helpText ? '
' : ''; $helpText .= _t('SiteTreeURLSegmentField.HelpChars', ' Special characters are automatically converted or removed.'); } diff --git a/code/model/SiteTreeFileExtension.php b/code/model/SiteTreeFileExtension.php index 4949ccf8..d3224547 100644 --- a/code/model/SiteTreeFileExtension.php +++ b/code/model/SiteTreeFileExtension.php @@ -5,7 +5,7 @@ */ class SiteTreeFileExtension extends DataExtension { - public static $belongs_many_many = array( + private static $belongs_many_many = array( 'BackLinkTracking' => 'SiteTree' ); diff --git a/code/model/VirtualPage.php b/code/model/VirtualPage.php index 293358df..c8e229cb 100644 --- a/code/model/VirtualPage.php +++ b/code/model/VirtualPage.php @@ -7,15 +7,15 @@ */ class VirtualPage extends Page { - static $description = 'Displays the content of another page'; + private static $description = 'Displays the content of another page'; public static $virtualFields; /** * @var Array Define fields that are not virtual - the virtual page must define these fields themselves. - * Note that anything in {@link self::$initially_copied_fields} is implicitly included in this list. + * Note that anything in {@link self::config()->initially_copied_fields} is implicitly included in this list. */ - public static $non_virtual_fields = array( + private static $non_virtual_fields = array( "SecurityTypeID", "OwnerID", "URLSegment", @@ -32,17 +32,17 @@ class VirtualPage extends Page { /** * @var Array Define fields that are initially copied to virtual pages but left modifiable after that. */ - public static $initially_copied_fields = array( + private static $initially_copied_fields = array( 'ShowInMenus', 'ShowInSearch', 'URLSegment', ); - static $has_one = array( + private static $has_one = array( "CopyContentFrom" => "SiteTree", ); - static $db = array( + private static $db = array( "VersionID" => "Int", ); @@ -50,7 +50,7 @@ class VirtualPage extends Page { * Generates the array of fields required for the page type. */ public function getVirtualFields() { - $nonVirtualFields = array_merge(self::$non_virtual_fields, self::$initially_copied_fields); + $nonVirtualFields = array_merge(self::config()->non_virtual_fields, self::config()->initially_copied_fields); $record = $this->CopyContentFrom(); $allFields = $record->db(); @@ -323,7 +323,7 @@ class VirtualPage extends Page { // We also want to copy certain, but only if we're copying the source page for the first // time. After this point, the user is free to customise these for the virtual page themselves. if($this->isChanged('CopyContentFromID', 2) && $this->CopyContentFromID != 0) { - foreach(self::$initially_copied_fields as $fieldName) { + foreach(self::config()->initially_copied_fields as $fieldName) { $this->$fieldName = $source->$fieldName; } } @@ -405,7 +405,7 @@ class VirtualPage extends Page { */ class VirtualPage_Controller extends Page_Controller { - static $allowed_actions = array( + private static $allowed_actions = array( 'loadcontentall' => 'ADMIN', ); diff --git a/code/reports/Report.php b/code/reports/Report.php index ee1ca304..a76b93b4 100644 --- a/code/reports/Report.php +++ b/code/reports/Report.php @@ -63,8 +63,9 @@ class SS_Report extends ViewableData { /** * Reports which should not be collected and returned in get_reports * @var array + * @config */ - public static $excluded_reports = array( + private static $excluded_reports = array( 'SS_Report', 'SS_ReportWrapper', 'SideReportWrapper' @@ -143,11 +144,11 @@ class SS_Report extends ViewableData { */ static public function add_excluded_reports($reportClass) { if (is_array($reportClass)) { - self::$excluded_reports = array_merge(self::$excluded_reports, $reportClass); + self::config()->excluded_reports = array_merge(self::config()->excluded_reports, $reportClass); } else { if (is_string($reportClass)) { //add to the excluded reports, so this report doesn't get used - self::$excluded_reports[] = $reportClass; + self::config()->excluded_reports = array($reportClass); } } } @@ -155,10 +156,13 @@ class SS_Report extends ViewableData { /** * Return an array of excluded reports. That is, reports that will not be included in * the list of reports in report admin in the CMS. + * + * @deprecated 3.2 Use the "Report.excluded_reports" config setting instead * @return array */ static public function get_excluded_reports() { - return self::$excluded_reports; + Deprecation::notice('3.2', 'Use the "Report.excluded_reports" config setting instead'); + return self::config()->excluded_reports; } /** @@ -172,7 +176,7 @@ class SS_Report extends ViewableData { if ($reports && count($reports) > 0) { //collect reports into array with an attribute for 'sort' foreach($reports as $report) { - if (in_array($report, self::$excluded_reports)) continue; //don't use the SS_Report superclass + if (in_array($report, self::config()->excluded_reports)) continue; //don't use the SS_Report superclass $reflectionClass = new ReflectionClass($report); if ($reflectionClass->isAbstract()) continue; //don't use abstract classes diff --git a/code/search/ContentControllerSearchExtension.php b/code/search/ContentControllerSearchExtension.php index 6f8bf48b..01d6e52f 100644 --- a/code/search/ContentControllerSearchExtension.php +++ b/code/search/ContentControllerSearchExtension.php @@ -6,7 +6,7 @@ * @subpackage search */ class ContentControllerSearchExtension extends Extension { - static $allowed_actions = array( + private static $allowed_actions = array( 'SearchForm', 'results', ); diff --git a/code/staticpublisher/FilesystemPublisher.php b/code/staticpublisher/FilesystemPublisher.php index a5432c1d..9ae0952b 100644 --- a/code/staticpublisher/FilesystemPublisher.php +++ b/code/staticpublisher/FilesystemPublisher.php @@ -28,24 +28,29 @@ class FilesystemPublisher extends StaticPublisher { protected $fileExtension = 'html'; /** + * @config * @var String */ - protected static $static_base_url = null; + private static $static_base_url = null; /** + * @config * @var Boolean Use domain based cacheing (put cache files into a domain subfolder) * This must be true if you are using this with the "subsites" module. * Please note that this form of caching requires all URLs to be provided absolute * (not relative to the webroot) via {@link SiteTree->AbsoluteLink()}. */ - public static $domain_based_caching = false; + private static $domain_based_caching = false; /** * Set a different base URL for the static copy of the site. * This can be useful if you are running the CMS on a different domain from the website. + * + * @deprecated 3.2 Use the "FilesystemPublisher.static_base_url" config setting instead */ static public function set_static_base_url($url) { - self::$static_base_url = $url; + Deprecation::notice('3.2', 'Use the "FilesystemPublisher.static_base_url" config setting instead'); + Config::inst()->update('FilesystemPublisher', 'static_base_url', $url); } /** @@ -112,7 +117,7 @@ class FilesystemPublisher extends StaticPublisher { $filename = $urlSegment ? "$urlSegment.$this->fileExtension" : "index.$this->fileExtension"; - if (self::$domain_based_caching) { + if (Config::inst()->get('FilesystemPublisher', 'domain_based_caching')) { if (!$urlParts) continue; // seriously malformed url here... $filename = $urlParts['host'] . '/' . $filename; } @@ -167,15 +172,21 @@ class FilesystemPublisher extends StaticPublisher { // 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()); + $customTheme = Config::inst()->get('StaticPublisher', 'static_publisher_theme'); + if(!$customTheme) + Config::inst()->update('SSViewer', 'theme', Config::inst()->get('SSViewer', 'custom_theme')); else - SSViewer::set_theme(StaticPublisher::static_publisher_theme()); + Config::inst()->update('SSViewer', 'theme', $customTheme); $currentBaseURL = Director::baseURL(); - if(self::$static_base_url) Director::setBaseURL(self::$static_base_url); - if($this->fileExtension == 'php') SSViewer::setOption('rewriteHashlinks', 'php'); - if(StaticPublisher::echo_progress()) echo $this->class.": Publishing to " . self::$static_base_url . "\n"; + $staticBaseUrl = Config::inst()->get('FilesystemPublisher', 'static_base_url'); + if($staticBaseUrl) Config::inst()->update('Director', 'alternate_base_url', $staticBaseUrl); + if($this->fileExtension == 'php') { + Config::inst()->update('SSViewer', 'rewrite_hash_links', 'php'); + } + if(Config::inst()->get('StaticPublisher', 'echo_progress')) { + echo $this->class.": Publishing to " . $staticBaseUrl . "\n"; + } $files = array(); $i = 0; $totalURLs = sizeof($urls); @@ -183,7 +194,7 @@ class FilesystemPublisher extends StaticPublisher { $origUrl = $url; $result[$origUrl] = array('statuscode' => null, 'redirect' => null, 'path' => null); - if(self::$static_base_url) Director::setBaseURL(self::$static_base_url); + if($staticBaseUrl) Config::inst()->update('Director', 'alternate_base_url', $staticBaseUrl); $i++; if($url && !is_string($url)) { @@ -191,7 +202,7 @@ class FilesystemPublisher extends StaticPublisher { continue; } - if(StaticPublisher::echo_progress()) { + if(Config::inst()->get('StaticPublisher', 'echo_progress')) { echo " * Publishing page $i/$totalURLs: $url\n"; flush(); } @@ -241,7 +252,7 @@ class FilesystemPublisher extends StaticPublisher { } } - if(StaticPublisher::$include_caching_metadata) { + if(Config::inst()->get('StaticPublisher', 'include_caching_metadata')) { $content = str_replace( '', sprintf("\n\n", implode(" ", $this->getMetadata($url))), @@ -282,8 +293,10 @@ class FilesystemPublisher extends StaticPublisher { }*/ } - if(self::$static_base_url) Director::setBaseURL($currentBaseURL); - if($this->fileExtension == 'php') SSViewer::setOption('rewriteHashlinks', true); + if(Config::inst()->get('FilesystemPublisher', 'static_base_url')) Config::inst()->update('Director', 'alternate_base_url', $currentBaseURL); + if($this->fileExtension == 'php') { + Config::inst()->update('SSViewer', 'rewrite_hash_links', true); + } $base = BASE_PATH . "/$this->destFolder"; foreach($files as $origUrl => $file) { diff --git a/code/staticpublisher/RsyncMultiHostPublisher.php b/code/staticpublisher/RsyncMultiHostPublisher.php index 957bd03d..0ca03f6b 100644 --- a/code/staticpublisher/RsyncMultiHostPublisher.php +++ b/code/staticpublisher/RsyncMultiHostPublisher.php @@ -11,29 +11,39 @@ */ class RsyncMultiHostPublisher extends FilesystemPublisher { /** + * @config * Array of rsync targets to publish to. These can either be local file names, or scp-style targets, in the form "user@server:path" */ - protected static $targets = array(); + private static $targets = array(); - protected static $excluded_folders = array(); + /** + * @config + * @var array + */ + private static $excluded_folders = array(); /** * Set the targets to publish to. * If target is an scp-style remote path, no password is accepted - we assume key-based authentication to be set up on the application server * initiating the publication. - * + * + * @deprecated 3.2 Use the "RsyncMultiHostPublisher.targets" config setting instead * @param $targets An array of targets to publish to. These can either be local file names, or scp-style targets, in the form "user@server:path" */ static public function set_targets($targets) { - self::$targets = $targets; + Deprecation::notice('3.2', 'Use the "RsyncMultiHostPublisher.targets" config setting instead'); + Config::inst()->update('RsyncMultiHostPublisher', 'targets', $targets); } /** * Specify folders to exclude from the rsync * For example, you could exclude assets. + * + * @deprecated 3.2 Use the "RsyncMultiHostPublisher.excluded_folders" config setting instead */ static public function set_excluded_folders($folders) { - self::$excluded_folders = $folders; + Deprecation::notice('3.2', 'Use the "RsyncMultiHostPublisher.excluded_folders" config setting instead'); + Config::inst()->update('RsyncMultiHostPublisher', 'excluded_folders', $folders); } public function publishPages($urls) { @@ -45,18 +55,18 @@ class RsyncMultiHostPublisher extends FilesystemPublisher { if(isset($_GET['norsync']) && $_GET['norsync']) return; $extraArg = ""; - if(self::$excluded_folders) foreach(self::$excluded_folders as $folder) { + if($this->config()->excluded_folders) foreach($this->config()->excluded_folders as $folder) { $extraArg .= " --exclude " . escapeshellarg($folder); } - foreach(self::$targets as $target) { + foreach((array)$this->config()->targets as $target) { // Transfer non-PHP content from everything to the target; that will ensure that we have all the JS/CSS/etc $rsyncOutput = `cd $base; rsync -av -e ssh --exclude /.htaccess --exclude /web.config --exclude '*.php' --exclude '*.svn' --exclude '*.git' --exclude '*~' $extraArg --delete . $target`; // Then transfer "safe" PHP from the cache/ directory $rsyncOutput .= `cd $base; rsync -av -e ssh --exclude '*.svn' --exclude '*~' $extraArg --delete cache $target`; // Transfer framework/static-main.php to the target $rsyncOutput .= `cd $base; rsync -av -e ssh --delete $framework/static-main.php $target/$framework`; - if(StaticPublisher::echo_progress()) echo $rsyncOutput; + if(Config::inst()->get('StaticPublisher', 'echo_progress')) echo $rsyncOutput; } } diff --git a/code/staticpublisher/StaticPublisher.php b/code/staticpublisher/StaticPublisher.php index 92a2f7a3..095053db 100644 --- a/code/staticpublisher/StaticPublisher.php +++ b/code/staticpublisher/StaticPublisher.php @@ -5,52 +5,71 @@ */ abstract class StaticPublisher extends DataExtension { /** - * Defines whether to output information about publishing or not. By + * @config + * @var boolean Defines whether to output information about publishing or not. By * default, this is off, and should be turned on when you want debugging * (for example, in a cron task) */ - static $echo_progress = false; + private static $echo_progress = false; /** - * Realtime static publishing... the second a page - * is saved, it is written to the cache + * @config + * @var boolean Realtime static publishing... the second a page + * is saved, it is written to the cache */ - static $disable_realtime = false; + private 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 + * @config + * @var boolean 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 Config::inst()->update('SSViewer', 'theme', ) is used * The obvious place to set this is in _config.php */ - static $static_publisher_theme=false; + private static $static_publisher_theme=false; abstract public function publishPages($pages); abstract public function unpublishPages($pages); + /** + * @deprecated 3.2 Use the "StaticPublisher.static_publisher_theme" config setting instead + * @param [type] $theme [description] + */ static public function set_static_publisher_theme($theme){ - self::$static_publisher_theme=$theme; + Deprecation::notice('3.2', 'Use the "StaticPublisher.static_publisher_theme" config setting instead'); + Config::inst()->update('StaticPublisher', 'static_publisher_theme', $theme); } /** + * @config * @var boolean Includes a timestamp at the bottom of the generated HTML of each file, * which can be useful for debugging issues with stale caches etc. */ - static $include_caching_metadata = false; + private static $include_caching_metadata = false; + /** + * @deprecated 3.2 Use the "StaticPublisher.static_publisher_theme" config setting instead + */ static public function static_publisher_theme(){ - return self::$static_publisher_theme; + Deprecation::notice('3.2', 'Use the "StaticPublisher.static_publisher_theme" config setting instead'); + return Config::inst()->get('StaticPublisher', 'static_publisher_theme'); } + /** + * @deprecated 3.2 Use the "StaticPublisher.echo_progress" config setting instead + */ static public function echo_progress() { - return (boolean)self::$echo_progress; + Deprecation::notice('3.2', 'Use the "StaticPublisher.echo_progress" config setting instead'); + return Config::inst()->get('StaticPublisher', 'echo_progress'); } /** * Either turns on (boolean true) or off (boolean false) the progress indicators. + * @deprecated 3.2 Use the "StaticPublisher.echo_progress" config setting instead * @see StaticPublisher::$echo_progress */ static public function set_echo_progress($progress) { - self::$echo_progress = (boolean)$progress; + Deprecation::notice('3.2', 'Use the "StaticPublisher.echo_progress" config setting instead'); + Config::inst()->update('StaticPublisher', 'echo_progress', $progress); } /** @@ -71,7 +90,7 @@ abstract class StaticPublisher extends DataExtension { } public function republish($original) { - if (self::$disable_realtime) return; + if (Config::inst()->get('StaticPublisher', 'disable_realtime')) return; $urls = array(); @@ -109,7 +128,7 @@ abstract class StaticPublisher extends DataExtension { * functionality */ public function onAfterUnpublish($page) { - if (self::$disable_realtime) return; + if (Config::inst()->get('StaticPublisher', 'disable_realtime')) return; // Get the affected URLs if($this->owner->hasMethod('pagesAffectedByUnpublishing')) { diff --git a/tasks/RebuildStaticCacheTask.php b/tasks/RebuildStaticCacheTask.php index 5400beb7..0a903ce6 100644 --- a/tasks/RebuildStaticCacheTask.php +++ b/tasks/RebuildStaticCacheTask.php @@ -7,7 +7,7 @@ */ class RebuildStaticCacheTask extends Controller { - static $allowed_actions = array( + private static $allowed_actions = array( 'index', ); @@ -21,7 +21,7 @@ class RebuildStaticCacheTask extends Controller { } public function index() { - StaticPublisher::set_echo_progress(true); + Config::inst()->update('StaticPublisher', 'echo_progress', true); $page = singleton('Page'); if(!$page->hasMethod('allPagesToCache')) { @@ -92,7 +92,7 @@ class RebuildStaticCacheTask extends Controller { if($removeAll && !isset($_GET['urls']) && $start == 0 && file_exists("../cache")) { echo "Removing stale cache files... \n"; flush(); - if (FilesystemPublisher::$domain_based_caching) { + if (Config::inst()->get('FilesystemPublisher', 'domain_based_caching')) { // Glob each dir, then glob each one of those foreach(glob(BASE_PATH . '/cache/*', GLOB_ONLYDIR) as $cacheDir) { foreach(glob($cacheDir.'/*') as $cacheFile) { diff --git a/tasks/RemoveOrphanedPagesTask.php b/tasks/RemoveOrphanedPagesTask.php index 35fa534a..c48f120e 100644 --- a/tasks/RemoveOrphanedPagesTask.php +++ b/tasks/RemoveOrphanedPagesTask.php @@ -23,7 +23,7 @@ //class RemoveOrphanedPagesTask extends BuildTask { class RemoveOrphanedPagesTask extends Controller { - static $allowed_actions = array( + private static $allowed_actions = array( 'index' => 'ADMIN', 'Form' => 'ADMIN', 'run' => 'ADMIN', diff --git a/tasks/SiteTreeMaintenanceTask.php b/tasks/SiteTreeMaintenanceTask.php index f0370c29..0c84fd54 100644 --- a/tasks/SiteTreeMaintenanceTask.php +++ b/tasks/SiteTreeMaintenanceTask.php @@ -4,7 +4,7 @@ * @subpackage tasks */ class SiteTreeMaintenanceTask extends Controller { - static $allowed_actions = array( + private static $allowed_actions = array( '*' => 'ADMIN' ); diff --git a/tasks/UpgradeSiteTreePermissionSchemaTask.php b/tasks/UpgradeSiteTreePermissionSchemaTask.php index e6d99f45..ae770ada 100644 --- a/tasks/UpgradeSiteTreePermissionSchemaTask.php +++ b/tasks/UpgradeSiteTreePermissionSchemaTask.php @@ -4,7 +4,8 @@ * @subpackage tasks */ class UpgradeSiteTreePermissionSchemaTask extends BuildTask { - static $allowed_actions = array( + + private static $allowed_actions = array( '*' => 'ADMIN' ); diff --git a/tests/controller/CMSMainTest.php b/tests/controller/CMSMainTest.php index f4f9b900..f7dbb0b2 100644 --- a/tests/controller/CMSMainTest.php +++ b/tests/controller/CMSMainTest.php @@ -5,7 +5,7 @@ */ class CMSMainTest extends FunctionalTest { - static $fixture_file = 'CMSMainTest.yml'; + protected static $fixture_file = 'CMSMainTest.yml'; static protected $orig = array(); @@ -78,6 +78,8 @@ class CMSMainTest extends FunctionalTest { 'Done: Published 30 pages', $response->getBody() ); + + $actions = CMSBatchActionHandler::config()->batch_actions; // Some modules (e.g., cmsworkflow) will remove this action $actions = CMSBatchActionHandler::config()->batch_actions; @@ -159,7 +161,7 @@ class CMSMainTest extends FunctionalTest { public function testCanPublishPageWithUnpublishedParentWithStrictHierarchyOff() { $this->logInWithPermission('ADMIN'); - SiteTree::set_enforce_strict_hierarchy(true); + Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', true); $parentPage = $this->objFromFixture('Page','page3'); $childPage = $this->objFromFixture('Page','page1'); @@ -172,7 +174,7 @@ class CMSMainTest extends FunctionalTest { $actions, 'Can publish a page with an unpublished parent with strict hierarchy off' ); - SiteTree::set_enforce_strict_hierarchy(false); + Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', false); } /** @@ -329,7 +331,7 @@ class CMSMainTest extends FunctionalTest { } class CMSMainTest_ClassA extends Page implements TestOnly { - static $allowed_children = array('CMSMainTest_ClassB'); + private static $allowed_children = array('CMSMainTest_ClassB'); } class CMSMainTest_ClassB extends Page implements TestOnly { @@ -337,7 +339,7 @@ class CMSMainTest_ClassB extends Page implements TestOnly { } class CMSMainTest_NotRoot extends Page implements TestOnly { - static $can_be_root = false; + private static $can_be_root = false; } class CMSMainTest_HiddenClass extends Page implements TestOnly, HiddenClass { diff --git a/tests/controller/CMSPageHistoryControllerTest.php b/tests/controller/CMSPageHistoryControllerTest.php index 58ec75d6..18f0d6d5 100755 --- a/tests/controller/CMSPageHistoryControllerTest.php +++ b/tests/controller/CMSPageHistoryControllerTest.php @@ -7,7 +7,7 @@ class CMSPageHistoryControllerTest extends FunctionalTest { - static $fixture_file = 'CMSPageHistoryControllerTest.yml'; + protected static $fixture_file = 'CMSPageHistoryControllerTest.yml'; private $versionUnpublishedCheck, $versionPublishCheck, $versionUnpublishedCheck2; private $page; diff --git a/tests/controller/CMSSiteTreeFilterTest.php b/tests/controller/CMSSiteTreeFilterTest.php index 2e3c79bc..96e18ea0 100644 --- a/tests/controller/CMSSiteTreeFilterTest.php +++ b/tests/controller/CMSSiteTreeFilterTest.php @@ -1,7 +1,7 @@ objFromFixture('Page', 'page1'); diff --git a/tests/controller/ContentControllerTest.php b/tests/controller/ContentControllerTest.php index b290444f..4c8e0377 100644 --- a/tests/controller/ContentControllerTest.php +++ b/tests/controller/ContentControllerTest.php @@ -5,9 +5,9 @@ */ class ContentControllerTest extends FunctionalTest { - public static $fixture_file = 'ContentControllerTest.yml'; + protected static $fixture_file = 'ContentControllerTest.yml'; - public static $use_draft_site = true; + protected static $use_draft_site = true; /** * Test that nested pages, basic actions, and nested/non-nested URL switching works properly @@ -15,7 +15,7 @@ class ContentControllerTest extends FunctionalTest { public function testNestedPages() { RootURLController::reset(); - SiteTree::enable_nested_urls(); + Config::inst()->update('SiteTree', 'nested_urls', true); $this->assertEquals('Home Page', $this->get('/')->getBody()); $this->assertEquals('Home Page', $this->get('/home/index/')->getBody()); @@ -30,7 +30,7 @@ class ContentControllerTest extends FunctionalTest { $this->assertEquals('Third Level Page', $this->get('/home/second-level/third-level/second-index/')->getBody()); RootURLController::reset(); - SiteTree::disable_nested_urls(); + SiteTree::config()->nested_urls = false; $this->assertEquals('Home Page', $this->get('/')->getBody()); $this->assertEquals('Home Page', $this->get('/home/')->getBody()); @@ -51,14 +51,14 @@ class ContentControllerTest extends FunctionalTest { public function testChildrenOf() { $controller = new ContentController(); - SiteTree::enable_nested_urls(); + Config::inst()->update('SiteTree', 'nested_urls', true); $this->assertEquals(1, $controller->ChildrenOf('/')->Count()); $this->assertEquals(1, $controller->ChildrenOf('/home/')->Count()); $this->assertEquals(2, $controller->ChildrenOf('/home/second-level/')->Count()); $this->assertEquals(0, $controller->ChildrenOf('/home/second-level/third-level/')->Count()); - SiteTree::disable_nested_urls(); + SiteTree::config()->nested_urls = false; $this->assertEquals(1, $controller->ChildrenOf('/')->Count()); $this->assertEquals(1, $controller->ChildrenOf('/home/')->Count()); @@ -67,7 +67,7 @@ class ContentControllerTest extends FunctionalTest { } public function testDeepNestedURLs() { - SiteTree::enable_nested_urls(); + Config::inst()->update('SiteTree', 'nested_urls', true); $page = new Page(); $page->URLSegment = 'base-page'; @@ -87,7 +87,7 @@ class ContentControllerTest extends FunctionalTest { } - SiteTree::disable_nested_urls(); + SiteTree::config()->nested_urls = false; } public function testViewDraft(){ @@ -129,7 +129,7 @@ class ContentControllerTest_Page extends Page { } class ContentControllerTest_Page_Controller extends Page_Controller { - public static $allowed_actions = array ( + private static $allowed_actions = array ( 'second_index' ); diff --git a/tests/controller/ModelAsControllerTest.php b/tests/controller/ModelAsControllerTest.php index ef5cc76d..8bdff26f 100644 --- a/tests/controller/ModelAsControllerTest.php +++ b/tests/controller/ModelAsControllerTest.php @@ -7,7 +7,7 @@ class ModelAsControllerTest extends FunctionalTest { protected $usesDatabase = true; - static $fixture_file = 'ModelAsControllerTest.yml'; + protected static $fixture_file = 'ModelAsControllerTest.yml'; protected $autoFollowRedirection = false; @@ -22,8 +22,8 @@ class ModelAsControllerTest extends FunctionalTest { public function setUp() { parent::setUp(); - $this->orig['nested_urls'] = SiteTree::nested_urls(); - SiteTree::enable_nested_urls(); + $this->orig['nested_urls'] = SiteTree::config()->nested_urls; + Config::inst()->update('SiteTree', 'nested_urls', true); } /** @@ -35,7 +35,7 @@ class ModelAsControllerTest extends FunctionalTest { public function tearDown() { if (isset($this->orig['nested_urls']) && !$this->orig['nested_urls']) { - SiteTree::disable_nested_urls(); + SiteTree::config()->nested_urls = false; } parent::tearDown(); } @@ -241,7 +241,7 @@ class ModelAsControllerTest extends FunctionalTest { */ public function testChildOfDraft() { RootURLController::reset(); - SiteTree::enable_nested_urls(); + Config::inst()->update('SiteTree', 'nested_urls', true); $draft = new Page(); $draft->Title = 'Root Leve Draft Page'; diff --git a/tests/controller/RootURLControllerTest.php b/tests/controller/RootURLControllerTest.php index de169983..36659863 100644 --- a/tests/controller/RootURLControllerTest.php +++ b/tests/controller/RootURLControllerTest.php @@ -4,14 +4,14 @@ * @subpackage tests */ class RootURLControllerTest extends SapphireTest { - static $fixture_file = 'RootURLControllerTest.yml'; + protected static $fixture_file = 'RootURLControllerTest.yml'; public function testGetHomepageLink() { $default = $this->objFromFixture('Page', 'home'); - SiteTree::disable_nested_urls(); + SiteTree::config()->nested_urls = false; $this->assertEquals('home', RootURLController::get_homepage_link()); - SiteTree::enable_nested_urls(); + Config::inst()->update('SiteTree', 'nested_urls', true); $this->assertEquals('home', RootURLController::get_homepage_link()); } diff --git a/tests/controller/SilverStripeNavigatorTest.php b/tests/controller/SilverStripeNavigatorTest.php index b0caec3f..5a522b00 100644 --- a/tests/controller/SilverStripeNavigatorTest.php +++ b/tests/controller/SilverStripeNavigatorTest.php @@ -6,7 +6,7 @@ class SilverStripeNavigatorTest extends SapphireTest { - static $fixture_file = 'cms/tests/controller/CMSMainTest.yml'; + protected static $fixture_file = 'cms/tests/controller/CMSMainTest.yml'; public function testGetItems() { $page = $this->objFromFixture('Page', 'page1'); diff --git a/tests/model/ErrorPageTest.php b/tests/model/ErrorPageTest.php index 8e29f2d7..8bd08bdc 100644 --- a/tests/model/ErrorPageTest.php +++ b/tests/model/ErrorPageTest.php @@ -5,7 +5,7 @@ */ class ErrorPageTest extends FunctionalTest { - static $fixture_file = 'ErrorPageTest.yml'; + protected static $fixture_file = 'ErrorPageTest.yml'; protected $orig = array(); @@ -14,20 +14,18 @@ class ErrorPageTest extends FunctionalTest { public function setUp() { parent::setUp(); - $this->orig['ErrorPage_staticfilepath'] = ErrorPage::get_static_filepath(); + $this->orig['ErrorPage_staticfilepath'] = ErrorPage::config()->static_filepath; $this->tmpAssetsPath = sprintf('%s/_tmp_assets_%s', TEMP_FOLDER, rand()); Filesystem::makeFolder($this->tmpAssetsPath . '/ErrorPageTest'); - ErrorPage::set_static_filepath($this->tmpAssetsPath . '/ErrorPageTest'); + ErrorPage::config()->static_filepath = $this->tmpAssetsPath . '/ErrorPageTest'; - $this->orig['Director_environmenttype'] = Director::get_environment_type(); - Director::set_environment_type('live'); + Config::inst()->update('Director', 'environment_type', 'live'); } public function tearDown() { parent::tearDown(); - ErrorPage::set_static_filepath($this->orig['ErrorPage_staticfilepath']); - Director::set_environment_type($this->orig['Director_environmenttype']); + ErrorPage::config()->static_filepath = $this->orig['ErrorPage_staticfilepath']; Filesystem::removeFolder($this->tmpAssetsPath . '/ErrorPageTest'); Filesystem::removeFolder($this->tmpAssetsPath); diff --git a/tests/model/FileLinkTrackingTest.php b/tests/model/FileLinkTrackingTest.php index 9dcf36ea..419af896 100644 --- a/tests/model/FileLinkTrackingTest.php +++ b/tests/model/FileLinkTrackingTest.php @@ -4,7 +4,7 @@ * Tests link tracking to files and images. */ class FileLinkTrackingTest extends SapphireTest { - static $fixture_file = "FileLinkTrackingTest.yml"; + protected static $fixture_file = "FileLinkTrackingTest.yml"; public function setUp() { parent::setUp(); diff --git a/tests/model/RedirectorPageTest.php b/tests/model/RedirectorPageTest.php index a1fd2285..24afdab8 100644 --- a/tests/model/RedirectorPageTest.php +++ b/tests/model/RedirectorPageTest.php @@ -1,8 +1,8 @@ assertContains('blackcandy', $themes, 'Test themes contain blackcandy theme'); $this->assertContains('darkshades', $themes, 'Test themes contain darkshades theme'); - SiteConfig::disable_theme('darkshades'); + SiteConfig::config()->disabled_themes = array('darkshades'); $themes = $config->getAvailableThemes($testThemeBaseDir); $this->assertFalse(in_array('darkshades', $themes), 'Darkshades was disabled - it is no longer available'); diff --git a/tests/model/SiteTreeActionsTest.php b/tests/model/SiteTreeActionsTest.php index e457d0b7..6fad34d1 100644 --- a/tests/model/SiteTreeActionsTest.php +++ b/tests/model/SiteTreeActionsTest.php @@ -14,7 +14,7 @@ */ class SiteTreeActionsTest extends FunctionalTest { - static $fixture_file = 'SiteTreeActionsTest.yml'; + protected static $fixture_file = 'SiteTreeActionsTest.yml'; public function testActionsReadonly() { if(class_exists('SiteTreeCMSWorkflow')) return true; diff --git a/tests/model/SiteTreeBacklinksTest.php b/tests/model/SiteTreeBacklinksTest.php index 9a4b58e8..c64b2678 100644 --- a/tests/model/SiteTreeBacklinksTest.php +++ b/tests/model/SiteTreeBacklinksTest.php @@ -1,7 +1,7 @@ array('SiteTreeBacklinksTest_DOD'), @@ -232,7 +232,7 @@ class SiteTreeBacklinksTest extends SapphireTest { class SiteTreeBacklinksTest_DOD extends DataExtension implements TestOnly { - static $db = array( + private static $db = array( 'ExtraContent' => 'HTMLText', ); diff --git a/tests/model/SiteTreeBrokenLinksTest.php b/tests/model/SiteTreeBrokenLinksTest.php index ee8e763e..67ebc029 100644 --- a/tests/model/SiteTreeBrokenLinksTest.php +++ b/tests/model/SiteTreeBrokenLinksTest.php @@ -4,7 +4,7 @@ * @subpackage tests */ class SiteTreeBrokenLinksTest extends SapphireTest { - static $fixture_file = 'SiteTreeBrokenLinksTest.yml'; + protected static $fixture_file = 'SiteTreeBrokenLinksTest.yml'; public function testBrokenLinksBetweenPages() { $obj = $this->objFromFixture('Page','content'); diff --git a/tests/model/SiteTreeHTMLEditorFieldTest.php b/tests/model/SiteTreeHTMLEditorFieldTest.php index 81481c16..cf2d4107 100644 --- a/tests/model/SiteTreeHTMLEditorFieldTest.php +++ b/tests/model/SiteTreeHTMLEditorFieldTest.php @@ -1,8 +1,8 @@ objFromFixture('SiteTree', 'home'); diff --git a/tests/model/SiteTreePermissionsTest.php b/tests/model/SiteTreePermissionsTest.php index e805b888..93731aff 100644 --- a/tests/model/SiteTreePermissionsTest.php +++ b/tests/model/SiteTreePermissionsTest.php @@ -7,7 +7,7 @@ * @todo Test canCreate() */ class SiteTreePermissionsTest extends FunctionalTest { - static $fixture_file = "SiteTreePermissionsTest.yml"; + protected static $fixture_file = "SiteTreePermissionsTest.yml"; protected $illegalExtensions = array( 'SiteTree' => array('SiteTreeSubsites') diff --git a/tests/model/SiteTreeTest.php b/tests/model/SiteTreeTest.php index f2d4b834..1ccafa70 100644 --- a/tests/model/SiteTreeTest.php +++ b/tests/model/SiteTreeTest.php @@ -4,7 +4,7 @@ * @subpackage tests */ class SiteTreeTest extends SapphireTest { - static $fixture_file = 'SiteTreeTest.yml'; + protected static $fixture_file = 'SiteTreeTest.yml'; protected $illegalExtensions = array( 'SiteTree' => array('SiteTreeSubsites') @@ -27,14 +27,14 @@ class SiteTreeTest extends SapphireTest { $this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 0); // Disable the creation - SiteTree::set_create_default_pages(false); + SiteTree::config()->create_default_pages = false; singleton('SiteTree')->requireDefaultRecords(); // The table should still be empty $this->assertEquals(DB::query('SELECT COUNT("ID") FROM "SiteTree"')->value(), 0); // Enable the creation - SiteTree::set_create_default_pages(true); + SiteTree::config()->create_default_pages = true; singleton('SiteTree')->requireDefaultRecords(); // The table should now have three rows (home, about-us, contact-us) @@ -273,7 +273,7 @@ class SiteTreeTest extends SapphireTest { $product = $this->objFromFixture('Page', 'product1'); $notFound = $this->objFromFixture('ErrorPage', '404'); - SiteTree::disable_nested_urls(); + SiteTree::config()->nested_urls = false; $this->assertEquals($home->ID, SiteTree::get_by_link('/', false)->ID); $this->assertEquals($home->ID, SiteTree::get_by_link('/home/', false)->ID); @@ -282,7 +282,7 @@ class SiteTreeTest extends SapphireTest { $this->assertEquals($product->ID, SiteTree::get_by_link($product->Link(), false)->ID); $this->assertEquals($notFound->ID, SiteTree::get_by_link($notFound->Link(), false)->ID); - SiteTree::enable_nested_urls(); + Config::inst()->update('SiteTree', 'nested_urls', true); $this->assertEquals($home->ID, SiteTree::get_by_link('/', false)->ID); $this->assertEquals($home->ID, SiteTree::get_by_link('/home/', false)->ID); @@ -300,7 +300,7 @@ class SiteTreeTest extends SapphireTest { $about = $this->objFromFixture('Page', 'about'); $staff = $this->objFromFixture('Page', 'staff'); - SiteTree::enable_nested_urls(); + Config::inst()->update('SiteTree', 'nested_urls', true); $this->assertEquals('about-us/', $about->RelativeLink(), 'Matches URLSegment on top level without parameters'); $this->assertEquals('about-us/my-staff/', $staff->RelativeLink(), 'Matches URLSegment plus parent on second level without parameters'); @@ -312,7 +312,7 @@ class SiteTreeTest extends SapphireTest { $parent = $this->objFromFixture('Page', 'about'); $child = $this->objFromFixture('Page', 'staff'); - SiteTree::enable_nested_urls(); + Config::inst()->update('SiteTree', 'nested_urls', true); $child->publish('Stage', 'Live'); $parent->URLSegment = 'changed-on-live'; @@ -326,7 +326,7 @@ class SiteTreeTest extends SapphireTest { } public function testDeleteFromStageOperatesRecursively() { - SiteTree::set_enforce_strict_hierarchy(false); + Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', false); $pageAbout = $this->objFromFixture('Page', 'about'); $pageStaff = $this->objFromFixture('Page', 'staff'); $pageStaffDuplicate = $this->objFromFixture('Page', 'staffduplicate'); @@ -336,7 +336,7 @@ class SiteTreeTest extends SapphireTest { $this->assertFalse(DataObject::get_by_id('Page', $pageAbout->ID)); $this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page); $this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page); - SiteTree::set_enforce_strict_hierarchy(true); + Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', true); } public function testDeleteFromStageOperatesRecursivelyStrict() { @@ -352,7 +352,7 @@ class SiteTreeTest extends SapphireTest { } public function testDeleteFromLiveOperatesRecursively() { - SiteTree::set_enforce_strict_hierarchy(false); + Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', false); $this->logInWithPermission('ADMIN'); $pageAbout = $this->objFromFixture('Page', 'about'); @@ -372,11 +372,11 @@ class SiteTreeTest extends SapphireTest { $this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page); $this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page); Versioned::reading_stage('Stage'); - SiteTree::set_enforce_strict_hierarchy(true); + Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', true); } public function testUnpublishDoesNotDeleteChildrenWithLooseHierachyOn() { - SiteTree::set_enforce_strict_hierarchy(false); + Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', false); $this->logInWithPermission('ADMIN'); $pageAbout = $this->objFromFixture('Page', 'about'); @@ -394,7 +394,7 @@ class SiteTreeTest extends SapphireTest { $this->assertTrue(DataObject::get_by_id('Page', $pageStaff->ID) instanceof Page); $this->assertTrue(DataObject::get_by_id('Page', $pageStaffDuplicate->ID) instanceof Page); Versioned::reading_stage('Stage'); - SiteTree::set_enforce_strict_hierarchy(true); + Config::inst()->update('SiteTree', 'enforce_strict_hierarchy', true); } @@ -634,7 +634,7 @@ class SiteTreeTest extends SapphireTest { */ public function testValidURLSegmentURLSegmentConflicts() { $sitetree = new SiteTree(); - SiteTree::disable_nested_urls(); + SiteTree::config()->nested_urls = false; $sitetree->URLSegment = 'home'; $this->assertFalse($sitetree->validURLSegment(), 'URLSegment conflicts are recognised'); @@ -645,7 +645,7 @@ class SiteTreeTest extends SapphireTest { $sitetree->URLSegment = 'home'; $this->assertFalse($sitetree->validURLSegment(), 'Conflicts are still recognised with a ParentID value'); - SiteTree::enable_nested_urls(); + Config::inst()->update('SiteTree', 'nested_urls', true); $sitetree->ParentID = 0; $sitetree->URLSegment = 'home'; @@ -674,7 +674,7 @@ class SiteTreeTest extends SapphireTest { * @covers SiteTree::validURLSegment */ public function testValidURLSegmentControllerConflicts() { - SiteTree::enable_nested_urls(); + Config::inst()->update('SiteTree', 'nested_urls', true); $sitetree = new SiteTree(); $sitetree->ParentID = $this->idFromFixture('SiteTreeTest_Conflicted', 'parent'); @@ -693,8 +693,8 @@ class SiteTreeTest extends SapphireTest { } public function testURLSegmentMultiByte() { - $origAllow = URLSegmentFilter::$default_allow_multibyte; - URLSegmentFilter::$default_allow_multibyte = true; + $origAllow = Config::inst()->get('URLSegmentFilter', 'default_allow_multibyte'); + Config::inst()->update('URLSegmentFilter', 'default_allow_multibyte', true); $sitetree = new SiteTree(); $sitetree->write(); @@ -709,7 +709,7 @@ class SiteTreeTest extends SapphireTest { $sitetreeLive = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' .$sitetree->ID, false); $this->assertEquals($sitetreeLive->URLSegment, rawurlencode('brötchen')); - URLSegmentFilter::$default_allow_multibyte = $origAllow; + Config::inst()->update('URLSegmentFilter', 'default_allow_multibyte', $origAllow); } public function testVersionsAreCreated() { @@ -895,7 +895,7 @@ class SiteTreeTest_PageNode_Controller extends Page_Controller implements TestOn class SiteTreeTest_Conflicted extends Page implements TestOnly { } class SiteTreeTest_Conflicted_Controller extends Page_Controller implements TestOnly { - public static $allowed_actions = array ( + private static $allowed_actions = array ( 'conflicted-action' ); @@ -917,32 +917,32 @@ class SiteTreeTest_NullHtmlCleaner extends HTMLCleaner { class SiteTreeTest_ClassA extends Page implements TestOnly { - static $need_permission = array('ADMIN', 'CMS_ACCESS_CMSMain'); + private static $need_permission = array('ADMIN', 'CMS_ACCESS_CMSMain'); - static $allowed_children = array('SiteTreeTest_ClassB'); + private static $allowed_children = array('SiteTreeTest_ClassB'); } class SiteTreeTest_ClassB extends Page implements TestOnly { // Also allowed subclasses - static $allowed_children = array('SiteTreeTest_ClassC'); + private static $allowed_children = array('SiteTreeTest_ClassC'); } class SiteTreeTest_ClassC extends Page implements TestOnly { - static $allowed_children = array(); + private static $allowed_children = array(); } class SiteTreeTest_ClassD extends Page implements TestOnly { // Only allows this class, no children classes - static $allowed_children = array('*SiteTreeTest_ClassC'); + private static $allowed_children = array('*SiteTreeTest_ClassC'); } class SiteTreeTest_ClassCext extends SiteTreeTest_ClassC implements TestOnly { // Override SiteTreeTest_ClassC definitions - static $allowed_children = array('SiteTreeTest_ClassB'); + private static $allowed_children = array('SiteTreeTest_ClassB'); } class SiteTreeTest_NotRoot extends Page implements TestOnly { - static $can_be_root = false; + private static $can_be_root = false; } class SiteTreeTest_StageStatusInherit extends SiteTree implements TestOnly { diff --git a/tests/model/VirtualPageTest.php b/tests/model/VirtualPageTest.php index ad383454..695d81cb 100644 --- a/tests/model/VirtualPageTest.php +++ b/tests/model/VirtualPageTest.php @@ -1,7 +1,7 @@ origInitiallyCopiedFields = VirtualPage::$initially_copied_fields; - VirtualPage::$initially_copied_fields[] = 'MyInitiallyCopiedField'; - $this->origNonVirtualField = VirtualPage::$non_virtual_fields; - VirtualPage::$non_virtual_fields[] = 'MyNonVirtualField'; - VirtualPage::$non_virtual_fields[] = 'MySharedNonVirtualField'; + $this->origInitiallyCopiedFields = VirtualPage::config()->initially_copied_fields; + VirtualPage::config()->initially_copied_fields = array('MyInitiallyCopiedField'); + $this->origNonVirtualField = VirtualPage::config()->non_virtual_fields; + $nonVirtual = VirtualPage::config()->non_virtual_fields; + VirtualPage::config()->non_virtual_fields = array('MyNonVirtualField', 'MySharedNonVirtualField'); } public function tearDown() { parent::tearDown(); - VirtualPage::$initially_copied_fields = $this->origInitiallyCopiedFields; - VirtualPage::$non_virtual_fields = $this->origNonVirtualField; + VirtualPage::config()->initially_copied_fields = $this->origInitiallyCopiedFields; + VirtualPage::config()->non_virtual_fields = $this->origNonVirtualField; } /** @@ -579,36 +579,36 @@ class VirtualPageTest extends SapphireTest { class VirtualPageTest_ClassA extends Page implements TestOnly { - static $db = array( + private static $db = array( 'MyInitiallyCopiedField' => 'Text', 'MyVirtualField' => 'Text', 'MyNonVirtualField' => 'Text', ); - static $allowed_children = array('VirtualPageTest_ClassB'); + private static $allowed_children = array('VirtualPageTest_ClassB'); } class VirtualPageTest_ClassB extends Page implements TestOnly { - static $allowed_children = array('VirtualPageTest_ClassC'); + private static $allowed_children = array('VirtualPageTest_ClassC'); } class VirtualPageTest_ClassC extends Page implements TestOnly { - static $allowed_children = array(); + private static $allowed_children = array(); } class VirtualPageTest_NotRoot extends Page implements TestOnly { - static $can_be_root = false; + private static $can_be_root = false; } class VirtualPageTest_VirtualPageSub extends VirtualPage implements TestOnly { - static $db = array( + private static $db = array( 'MyProperty' => 'Varchar', ); } class VirtualPageTest_PageExtension extends DataExtension implements TestOnly { - static $db = array( + private static $db = array( // These fields are just on an extension to simulate shared properties between Page and VirtualPage. // Not possible through direct $db definitions due to VirtualPage inheriting from Page, and Page being defined elsewhere. 'MySharedVirtualField' => 'Text', diff --git a/tests/reports/SideReportTest.php b/tests/reports/SideReportTest.php index 3e12c1e1..1bd557dc 100644 --- a/tests/reports/SideReportTest.php +++ b/tests/reports/SideReportTest.php @@ -6,9 +6,9 @@ class SideReportTest extends SapphireTest { - static $fixture_file = 'SideReportTest.yml'; + protected static $fixture_file = 'SideReportTest.yml'; - static $daysAgo = 14; + private static $daysAgo = 14; public function setUp() { parent::setUp(); diff --git a/tests/search/CMSMainSearchFormTest.php b/tests/search/CMSMainSearchFormTest.php index 4577bea0..0de41ade 100644 --- a/tests/search/CMSMainSearchFormTest.php +++ b/tests/search/CMSMainSearchFormTest.php @@ -1,7 +1,7 @@ orig['domain_based_caching'] = FilesystemPublisher::$domain_based_caching; - FilesystemPublisher::$domain_based_caching = false; + Config::inst()->update('FilesystemPublisher', 'domain_based_caching', false); } public function tearDown() { @@ -27,8 +26,6 @@ class FilesystemPublisherTest extends SapphireTest { SiteTree::remove_extension("FilesystemPublisher('assets/FilesystemPublisherTest-static-folder/')"); - FilesystemPublisher::$domain_based_caching = $this->orig['domain_based_caching']; - if(file_exists(BASE_PATH . '/assets/FilesystemPublisherTest-static-folder')) { Filesystem::removeFolder(BASE_PATH . '/assets/FilesystemPublisherTest-static-folder'); } @@ -82,8 +79,7 @@ class FilesystemPublisherTest extends SapphireTest { } public function testUrlsToPathsWithDomainBasedCaching() { - $origDomainBasedCaching = FilesystemPublisher::$domain_based_caching; - FilesystemPublisher::$domain_based_caching = true; + Config::inst()->update('FilesystemPublisher', 'domain_based_caching', true); $fsp = new FilesystemPublisher('.', 'html'); @@ -107,8 +103,6 @@ class FilesystemPublisherTest extends SapphireTest { array($url => 'domain2.com/parent/child.html'), 'Nested URLsegment path mapping' ); - - FilesystemPublisher::$domain_based_caching = $origDomainBasedCaching; } /** @@ -134,7 +128,7 @@ class FilesystemPublisherTest extends SapphireTest { public function testStaticPublisherTheme(){ //This will be the name of the default theme of this particular project - $default_theme=SSViewer::current_theme(); + $default_theme= Config::inst()->get('SSViewer', 'theme'); $p1 = new Page(); $p1->URLSegment = strtolower(__CLASS__).'-page-1'; @@ -142,21 +136,13 @@ class FilesystemPublisherTest extends SapphireTest { $p1->write(); $p1->doPublish(); - $current_theme=SSViewer::current_custom_theme(); + $current_theme=Config::inst()->get('SSViewer', '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(); + Config::inst()->update('SSViewer', 'theme', null); + $current_theme=Config::inst()->get('SSViewer', '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'); - - } function testPublishPages() { diff --git a/tests/tasks/MigrateSiteTreeLinkingTaskTest.php b/tests/tasks/MigrateSiteTreeLinkingTaskTest.php index 5547a98f..537d2467 100644 --- a/tests/tasks/MigrateSiteTreeLinkingTaskTest.php +++ b/tests/tasks/MigrateSiteTreeLinkingTaskTest.php @@ -5,9 +5,9 @@ */ class MigrateSiteTreeLinkingTaskTest extends SapphireTest { - public static $fixture_file = 'MigrateSiteTreeLinkingTaskTest.yml'; + protected static $fixture_file = 'MigrateSiteTreeLinkingTaskTest.yml'; - public static $use_draft_site = true; + protected static $use_draft_site = true; public function testLinkingMigration() { ob_start(); diff --git a/tests/tasks/RemoveOrphanedPagesTaskTest.php b/tests/tasks/RemoveOrphanedPagesTaskTest.php index 7b09b7f7..e5b4948f 100644 --- a/tests/tasks/RemoveOrphanedPagesTaskTest.php +++ b/tests/tasks/RemoveOrphanedPagesTaskTest.php @@ -32,9 +32,9 @@ */ class RemoveOrphanedPagesTaskTest extends FunctionalTest { - static $fixture_file = 'RemoveOrphanedPagesTaskTest.yml'; + protected static $fixture_file = 'RemoveOrphanedPagesTaskTest.yml'; - static $use_draft_site = false; + protected static $use_draft_site = false; public function setUp() { parent::setUp();