From ad2c5d8eded8542588fe7cd305d3802f1b0b5059 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 5 Jun 2024 17:26:56 +1200 Subject: [PATCH] ENH Use class name instead of self --- src/Controller/SubsiteXHRController.php | 2 +- src/Extensions/SiteTreeSubsites.php | 2 +- src/Model/Subsite.php | 38 +++++++++---------- src/Model/SubsiteDomain.php | 12 +++--- src/Pages/SubsitesVirtualPage.php | 2 +- src/Reports/SubsiteReportWrapper.php | 11 +++--- .../SiteTreeSubsitesTest/TestErrorPage.php | 2 +- 7 files changed, 35 insertions(+), 34 deletions(-) diff --git a/src/Controller/SubsiteXHRController.php b/src/Controller/SubsiteXHRController.php index 4a52264..db344dc 100644 --- a/src/Controller/SubsiteXHRController.php +++ b/src/Controller/SubsiteXHRController.php @@ -64,6 +64,6 @@ class SubsiteXHRController extends LeftAndMain */ public function SubsiteList() { - return $this->renderWith(['type' => 'Includes', self::class . '_subsitelist']); + return $this->renderWith(['type' => 'Includes', SubsiteXHRController::class . '_subsitelist']); } } diff --git a/src/Extensions/SiteTreeSubsites.php b/src/Extensions/SiteTreeSubsites.php index 8db1a58..b128c36 100644 --- a/src/Extensions/SiteTreeSubsites.php +++ b/src/Extensions/SiteTreeSubsites.php @@ -398,7 +398,7 @@ class SiteTreeSubsites extends DataExtension SSViewer::set_themes(ThemeResolver::singleton()->getThemeList($subsite)); } - $ignore_subsite_locale = Config::inst()->get(self::class, 'ignore_subsite_locale'); + $ignore_subsite_locale = Config::inst()->get(SiteTreeSubsites::class, 'ignore_subsite_locale'); if (!$ignore_subsite_locale && $subsite diff --git a/src/Model/Subsite.php b/src/Model/Subsite.php index 9fd5f2f..15e39e1 100644 --- a/src/Model/Subsite.php +++ b/src/Model/Subsite.php @@ -174,7 +174,7 @@ class Subsite extends DataObject */ public static function set_allowed_themes($themes) { - self::$allowed_themes = $themes; + Subsite::$allowed_themes = $themes; } /** @@ -249,8 +249,8 @@ class Subsite extends DataObject $currentUserId = Security::getCurrentUser() ? Security::getCurrentUser()->ID : 0; $cacheKey = implode('_', [$host, $currentUserId, static::config()->get('check_is_public')]); - if (isset(self::$cache_subsite_for_domain[$cacheKey])) { - return self::$cache_subsite_for_domain[$cacheKey]; + if (isset(Subsite::$cache_subsite_for_domain[$cacheKey])) { + return Subsite::$cache_subsite_for_domain[$cacheKey]; } $SQL_host = Convert::raw2sql($host); @@ -299,7 +299,7 @@ class Subsite extends DataObject } if ($cacheKey) { - self::$cache_subsite_for_domain[$cacheKey] = $subsiteID; + Subsite::$cache_subsite_for_domain[$cacheKey] = $subsiteID; } return $subsiteID; @@ -327,15 +327,15 @@ class Subsite extends DataObject */ public static function disable_subsite_filter($disabled = true) { - self::$disable_subsite_filter = $disabled; + Subsite::$disable_subsite_filter = $disabled; } public static function withDisabledSubsiteFilter(callable $callable, bool $disabled = true): mixed { - $orig = self::$disable_subsite_filter; - self::disable_subsite_filter($disabled); + $orig = Subsite::$disable_subsite_filter; + Subsite::disable_subsite_filter($disabled); $ret = $callable(); - self::disable_subsite_filter($orig); + Subsite::disable_subsite_filter($orig); return $ret; } @@ -344,8 +344,8 @@ class Subsite extends DataObject */ public static function on_db_reset() { - self::$cache_accessible_sites = []; - self::$cache_subsite_for_domain = []; + Subsite::$cache_accessible_sites = []; + Subsite::$cache_subsite_for_domain = []; } /** @@ -451,8 +451,8 @@ class Subsite extends DataObject // Cache handling $cacheKey = $SQL_codes . '-' . $member->ID . '-' . $includeMainSite . '-' . $mainSiteTitle; - if (isset(self::$cache_accessible_sites[$cacheKey])) { - return self::$cache_accessible_sites[$cacheKey]; + if (isset(Subsite::$cache_accessible_sites[$cacheKey])) { + return Subsite::$cache_accessible_sites[$cacheKey]; } $subsites = DataList::create(Subsite::class) @@ -515,7 +515,7 @@ class Subsite extends DataObject if (!is_array($permCode)) { $permCode = [$permCode]; } - if (self::hasMainSitePermission($member, $permCode)) { + if (Subsite::hasMainSitePermission($member, $permCode)) { $subsites = $subsites->toArray(); $mainSite = new Subsite(); @@ -525,7 +525,7 @@ class Subsite extends DataObject } } - self::$cache_accessible_sites[$cacheKey] = $subsites; + Subsite::$cache_accessible_sites[$cacheKey] = $subsites; return $subsites; } @@ -769,7 +769,7 @@ class Subsite extends DataObject */ public function allowedThemes() { - if (($themes = self::$allowed_themes) || ($themes = ThemeResolver::singleton()->getCustomThemeOptions())) { + if (($themes = Subsite::$allowed_themes) || ($themes = ThemeResolver::singleton()->getCustomThemeOptions())) { return ArrayLib::valuekey($themes); } @@ -956,7 +956,7 @@ JS; $duplicate = parent::duplicate($doWrite); $oldSubsiteID = SubsiteState::singleton()->getSubsiteId(); - self::changeSubsite($this->ID); + Subsite::changeSubsite($this->ID); /* * Copy data from this object to the given subsite. Does this using an iterative depth-first search. @@ -971,21 +971,21 @@ JS; if ($children) { foreach ($children as $child) { - self::changeSubsite($duplicate->ID); //Change to destination subsite + Subsite::changeSubsite($duplicate->ID); //Change to destination subsite $childClone = $child->duplicateToSubsite($duplicate, false); $childClone->ParentID = $destParentID; $childClone->writeToStage('Stage'); $childClone->copyVersionToStage('Stage', 'Live'); - self::changeSubsite($this->ID); //Change Back to this subsite + Subsite::changeSubsite($this->ID); //Change Back to this subsite array_push($stack, [$child->ID, $childClone->ID]); } } } - self::changeSubsite($oldSubsiteID); + Subsite::changeSubsite($oldSubsiteID); return $duplicate; } diff --git a/src/Model/SubsiteDomain.php b/src/Model/SubsiteDomain.php index 755f069..8545f54 100644 --- a/src/Model/SubsiteDomain.php +++ b/src/Model/SubsiteDomain.php @@ -108,9 +108,9 @@ class SubsiteDomain extends DataObject public function getCMSFields() { $protocols = [ - self::PROTOCOL_HTTP => _t(__CLASS__ . '.PROTOCOL_HTTP', 'http://'), - self::PROTOCOL_HTTPS => _t(__CLASS__ . '.PROTOCOL_HTTPS', 'https://'), - self::PROTOCOL_AUTOMATIC => _t(__CLASS__ . '.PROTOCOL_AUTOMATIC', 'Automatic') + SubsiteDomain::PROTOCOL_HTTP => _t(__CLASS__ . '.PROTOCOL_HTTP', 'http://'), + SubsiteDomain::PROTOCOL_HTTPS => _t(__CLASS__ . '.PROTOCOL_HTTPS', 'https://'), + SubsiteDomain::PROTOCOL_AUTOMATIC => _t(__CLASS__ . '.PROTOCOL_AUTOMATIC', 'Automatic') ]; $fields = FieldList::create( WildcardDomainField::create('Domain', $this->fieldLabel('Domain'), null, 255) @@ -119,7 +119,7 @@ class SubsiteDomain extends DataObject 'Hostname of this subsite (exclude protocol). Allows wildcards (*).' )), OptionsetField::create('Protocol', $this->fieldLabel('Protocol'), $protocols) - ->setValue($this->Protocol ?: self::PROTOCOL_AUTOMATIC) + ->setValue($this->Protocol ?: SubsiteDomain::PROTOCOL_AUTOMATIC) ->setDescription(_t( __CLASS__ . '.PROTOCOL_DESCRIPTION', 'When generating links to this subsite, use the selected protocol.
' . @@ -169,9 +169,9 @@ class SubsiteDomain extends DataObject public function getFullProtocol() { switch ($this->Protocol) { - case self::PROTOCOL_HTTPS: + case SubsiteDomain::PROTOCOL_HTTPS: return 'https://'; - case self::PROTOCOL_HTTP: + case SubsiteDomain::PROTOCOL_HTTP: return 'http://'; default: return Director::protocol(); diff --git a/src/Pages/SubsitesVirtualPage.php b/src/Pages/SubsitesVirtualPage.php index c19eb40..cd29130 100644 --- a/src/Pages/SubsitesVirtualPage.php +++ b/src/Pages/SubsitesVirtualPage.php @@ -173,7 +173,7 @@ class SubsitesVirtualPage extends VirtualPage } } - foreach (self::$db as $field => $type) { + foreach (SubsitesVirtualPage::$db as $field => $type) { if (in_array($field, $fields ?? [])) { unset($fields[array_search($field, $fields)]); } diff --git a/src/Reports/SubsiteReportWrapper.php b/src/Reports/SubsiteReportWrapper.php index dbfc1e6..9ae3217 100644 --- a/src/Reports/SubsiteReportWrapper.php +++ b/src/Reports/SubsiteReportWrapper.php @@ -22,7 +22,8 @@ class SubsiteReportWrapper extends ReportWrapper public function parameterFields() { $subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', true); - $options = [self::SUBSITE_ID_ALL => _t(__CLASS__ . '.ReportDropdownAll', 'All')] + $subsites->map()->toArray(); + $text = _t(__CLASS__ . '.ReportDropdownAll', 'All'); + $options = [SubsiteReportWrapper::SUBSITE_ID_ALL => $text] + $subsites->map()->toArray(); $subsiteField = DropdownField::create( 'Subsite', @@ -56,8 +57,8 @@ class SubsiteReportWrapper extends ReportWrapper public function sourceQuery($params) { - $subsiteID = (int) ($params['Subsite'] ?? self::SUBSITE_ID_ALL); - if ($subsiteID === self::SUBSITE_ID_ALL) { + $subsiteID = (int) ($params['Subsite'] ?? SubsiteReportWrapper::SUBSITE_ID_ALL); + if ($subsiteID === SubsiteReportWrapper::SUBSITE_ID_ALL) { return Subsite::withDisabledSubsiteFilter(function () use ($params) { return parent::sourceQuery($params); }); @@ -70,8 +71,8 @@ class SubsiteReportWrapper extends ReportWrapper public function sourceRecords($params = [], $sort = null, $limit = null) { - $subsiteID = (int) ($params['Subsite'] ?? self::SUBSITE_ID_ALL); - if ($subsiteID === self::SUBSITE_ID_ALL) { + $subsiteID = (int) ($params['Subsite'] ?? SubsiteReportWrapper::SUBSITE_ID_ALL); + if ($subsiteID === SubsiteReportWrapper::SUBSITE_ID_ALL) { return Subsite::withDisabledSubsiteFilter(function () use ($params, $sort, $limit) { return parent::sourceRecords($params, $sort, $limit); }); diff --git a/tests/php/SiteTreeSubsitesTest/TestErrorPage.php b/tests/php/SiteTreeSubsitesTest/TestErrorPage.php index 93dcd57..04f4815 100644 --- a/tests/php/SiteTreeSubsitesTest/TestErrorPage.php +++ b/tests/php/SiteTreeSubsitesTest/TestErrorPage.php @@ -15,6 +15,6 @@ class TestErrorPage extends ErrorPage implements TestOnly */ public static function get_error_filename_spy($statusCode) { - return self::get_error_filename($statusCode); + return TestErrorPage::get_error_filename($statusCode); } }