Merge pull request #575 from creative-commoners/pulls/3.2/remove-self

ENH Use class name instead of self
This commit is contained in:
Guy Sartorelli 2024-06-17 12:50:25 +12:00 committed by GitHub
commit 51dc3dcd2d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 35 additions and 34 deletions

View File

@ -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']);
}
}

View File

@ -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

View File

@ -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;
}

View File

@ -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. <br />' .
@ -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();

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

View File

@ -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);
});

View File

@ -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);
}
}