ENH Use class name instead of self

This commit is contained in:
Steve Boyd 2024-06-05 17:26:56 +12:00
parent dbbfded3e8
commit ad2c5d8ede
7 changed files with 35 additions and 34 deletions

View File

@ -64,6 +64,6 @@ class SubsiteXHRController extends LeftAndMain
*/ */
public function SubsiteList() public function SubsiteList()
{ {
return $this->renderWith(['type' => 'Includes', self::class . '_subsitelist']); return $this->renderWith(['type' => 'Includes', SubsiteXHRController::class . '_subsitelist']);
} }
} }

View File

@ -398,7 +398,7 @@ class SiteTreeSubsites extends DataExtension
SSViewer::set_themes(ThemeResolver::singleton()->getThemeList($subsite)); 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 if (!$ignore_subsite_locale
&& $subsite && $subsite

View File

@ -174,7 +174,7 @@ class Subsite extends DataObject
*/ */
public static function set_allowed_themes($themes) 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; $currentUserId = Security::getCurrentUser() ? Security::getCurrentUser()->ID : 0;
$cacheKey = implode('_', [$host, $currentUserId, static::config()->get('check_is_public')]); $cacheKey = implode('_', [$host, $currentUserId, static::config()->get('check_is_public')]);
if (isset(self::$cache_subsite_for_domain[$cacheKey])) { if (isset(Subsite::$cache_subsite_for_domain[$cacheKey])) {
return self::$cache_subsite_for_domain[$cacheKey]; return Subsite::$cache_subsite_for_domain[$cacheKey];
} }
$SQL_host = Convert::raw2sql($host); $SQL_host = Convert::raw2sql($host);
@ -299,7 +299,7 @@ class Subsite extends DataObject
} }
if ($cacheKey) { if ($cacheKey) {
self::$cache_subsite_for_domain[$cacheKey] = $subsiteID; Subsite::$cache_subsite_for_domain[$cacheKey] = $subsiteID;
} }
return $subsiteID; return $subsiteID;
@ -327,15 +327,15 @@ class Subsite extends DataObject
*/ */
public static function disable_subsite_filter($disabled = true) 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 public static function withDisabledSubsiteFilter(callable $callable, bool $disabled = true): mixed
{ {
$orig = self::$disable_subsite_filter; $orig = Subsite::$disable_subsite_filter;
self::disable_subsite_filter($disabled); Subsite::disable_subsite_filter($disabled);
$ret = $callable(); $ret = $callable();
self::disable_subsite_filter($orig); Subsite::disable_subsite_filter($orig);
return $ret; return $ret;
} }
@ -344,8 +344,8 @@ class Subsite extends DataObject
*/ */
public static function on_db_reset() public static function on_db_reset()
{ {
self::$cache_accessible_sites = []; Subsite::$cache_accessible_sites = [];
self::$cache_subsite_for_domain = []; Subsite::$cache_subsite_for_domain = [];
} }
/** /**
@ -451,8 +451,8 @@ class Subsite extends DataObject
// Cache handling // Cache handling
$cacheKey = $SQL_codes . '-' . $member->ID . '-' . $includeMainSite . '-' . $mainSiteTitle; $cacheKey = $SQL_codes . '-' . $member->ID . '-' . $includeMainSite . '-' . $mainSiteTitle;
if (isset(self::$cache_accessible_sites[$cacheKey])) { if (isset(Subsite::$cache_accessible_sites[$cacheKey])) {
return self::$cache_accessible_sites[$cacheKey]; return Subsite::$cache_accessible_sites[$cacheKey];
} }
$subsites = DataList::create(Subsite::class) $subsites = DataList::create(Subsite::class)
@ -515,7 +515,7 @@ class Subsite extends DataObject
if (!is_array($permCode)) { if (!is_array($permCode)) {
$permCode = [$permCode]; $permCode = [$permCode];
} }
if (self::hasMainSitePermission($member, $permCode)) { if (Subsite::hasMainSitePermission($member, $permCode)) {
$subsites = $subsites->toArray(); $subsites = $subsites->toArray();
$mainSite = new Subsite(); $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; return $subsites;
} }
@ -769,7 +769,7 @@ class Subsite extends DataObject
*/ */
public function allowedThemes() 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); return ArrayLib::valuekey($themes);
} }
@ -956,7 +956,7 @@ JS;
$duplicate = parent::duplicate($doWrite); $duplicate = parent::duplicate($doWrite);
$oldSubsiteID = SubsiteState::singleton()->getSubsiteId(); $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. * Copy data from this object to the given subsite. Does this using an iterative depth-first search.
@ -971,21 +971,21 @@ JS;
if ($children) { if ($children) {
foreach ($children as $child) { 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 = $child->duplicateToSubsite($duplicate, false);
$childClone->ParentID = $destParentID; $childClone->ParentID = $destParentID;
$childClone->writeToStage('Stage'); $childClone->writeToStage('Stage');
$childClone->copyVersionToStage('Stage', 'Live'); $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]); array_push($stack, [$child->ID, $childClone->ID]);
} }
} }
} }
self::changeSubsite($oldSubsiteID); Subsite::changeSubsite($oldSubsiteID);
return $duplicate; return $duplicate;
} }

View File

@ -108,9 +108,9 @@ class SubsiteDomain extends DataObject
public function getCMSFields() public function getCMSFields()
{ {
$protocols = [ $protocols = [
self::PROTOCOL_HTTP => _t(__CLASS__ . '.PROTOCOL_HTTP', 'http://'), SubsiteDomain::PROTOCOL_HTTP => _t(__CLASS__ . '.PROTOCOL_HTTP', 'http://'),
self::PROTOCOL_HTTPS => _t(__CLASS__ . '.PROTOCOL_HTTPS', 'https://'), SubsiteDomain::PROTOCOL_HTTPS => _t(__CLASS__ . '.PROTOCOL_HTTPS', 'https://'),
self::PROTOCOL_AUTOMATIC => _t(__CLASS__ . '.PROTOCOL_AUTOMATIC', 'Automatic') SubsiteDomain::PROTOCOL_AUTOMATIC => _t(__CLASS__ . '.PROTOCOL_AUTOMATIC', 'Automatic')
]; ];
$fields = FieldList::create( $fields = FieldList::create(
WildcardDomainField::create('Domain', $this->fieldLabel('Domain'), null, 255) WildcardDomainField::create('Domain', $this->fieldLabel('Domain'), null, 255)
@ -119,7 +119,7 @@ class SubsiteDomain extends DataObject
'Hostname of this subsite (exclude protocol). Allows wildcards (*).' 'Hostname of this subsite (exclude protocol). Allows wildcards (*).'
)), )),
OptionsetField::create('Protocol', $this->fieldLabel('Protocol'), $protocols) OptionsetField::create('Protocol', $this->fieldLabel('Protocol'), $protocols)
->setValue($this->Protocol ?: self::PROTOCOL_AUTOMATIC) ->setValue($this->Protocol ?: SubsiteDomain::PROTOCOL_AUTOMATIC)
->setDescription(_t( ->setDescription(_t(
__CLASS__ . '.PROTOCOL_DESCRIPTION', __CLASS__ . '.PROTOCOL_DESCRIPTION',
'When generating links to this subsite, use the selected protocol. <br />' . 'When generating links to this subsite, use the selected protocol. <br />' .
@ -169,9 +169,9 @@ class SubsiteDomain extends DataObject
public function getFullProtocol() public function getFullProtocol()
{ {
switch ($this->Protocol) { switch ($this->Protocol) {
case self::PROTOCOL_HTTPS: case SubsiteDomain::PROTOCOL_HTTPS:
return 'https://'; return 'https://';
case self::PROTOCOL_HTTP: case SubsiteDomain::PROTOCOL_HTTP:
return 'http://'; return 'http://';
default: default:
return Director::protocol(); return Director::protocol();

View File

@ -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 ?? [])) { if (in_array($field, $fields ?? [])) {
unset($fields[array_search($field, $fields)]); unset($fields[array_search($field, $fields)]);
} }

View File

@ -22,7 +22,8 @@ class SubsiteReportWrapper extends ReportWrapper
public function parameterFields() public function parameterFields()
{ {
$subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', true); $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( $subsiteField = DropdownField::create(
'Subsite', 'Subsite',
@ -56,8 +57,8 @@ class SubsiteReportWrapper extends ReportWrapper
public function sourceQuery($params) public function sourceQuery($params)
{ {
$subsiteID = (int) ($params['Subsite'] ?? self::SUBSITE_ID_ALL); $subsiteID = (int) ($params['Subsite'] ?? SubsiteReportWrapper::SUBSITE_ID_ALL);
if ($subsiteID === self::SUBSITE_ID_ALL) { if ($subsiteID === SubsiteReportWrapper::SUBSITE_ID_ALL) {
return Subsite::withDisabledSubsiteFilter(function () use ($params) { return Subsite::withDisabledSubsiteFilter(function () use ($params) {
return parent::sourceQuery($params); return parent::sourceQuery($params);
}); });
@ -70,8 +71,8 @@ class SubsiteReportWrapper extends ReportWrapper
public function sourceRecords($params = [], $sort = null, $limit = null) public function sourceRecords($params = [], $sort = null, $limit = null)
{ {
$subsiteID = (int) ($params['Subsite'] ?? self::SUBSITE_ID_ALL); $subsiteID = (int) ($params['Subsite'] ?? SubsiteReportWrapper::SUBSITE_ID_ALL);
if ($subsiteID === self::SUBSITE_ID_ALL) { if ($subsiteID === SubsiteReportWrapper::SUBSITE_ID_ALL) {
return Subsite::withDisabledSubsiteFilter(function () use ($params, $sort, $limit) { return Subsite::withDisabledSubsiteFilter(function () use ($params, $sort, $limit) {
return parent::sourceRecords($params, $sort, $limit); return parent::sourceRecords($params, $sort, $limit);
}); });

View File

@ -15,6 +15,6 @@ class TestErrorPage extends ErrorPage implements TestOnly
*/ */
public static function get_error_filename_spy($statusCode) public static function get_error_filename_spy($statusCode)
{ {
return self::get_error_filename($statusCode); return TestErrorPage::get_error_filename($statusCode);
} }
} }