Skip to content

Commit

Permalink
ENH Use class name instead of self
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jun 5, 2024
1 parent dbbfded commit 757b1b6
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/Controller/SubsiteXHRController.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ public function getResponseNegotiator(): PjaxResponseNegotiator
*/
public function SubsiteList()
{
return $this->renderWith(['type' => 'Includes', self::class . '_subsitelist']);
return $this->renderWith(['type' => 'Includes', SubsiteXHRController::class . '_subsitelist']);
}
}
2 changes: 1 addition & 1 deletion src/Extensions/SiteTreeSubsites.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ public static function contentcontrollerInit($controller)
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
Expand Down
38 changes: 19 additions & 19 deletions src/Model/Subsite.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class Subsite extends DataObject
*/
public static function set_allowed_themes($themes)
{
self::$allowed_themes = $themes;
Subsite::$allowed_themes = $themes;
}

/**
Expand Down Expand Up @@ -249,8 +249,8 @@ public static function getSubsiteIDForDomain($host = null, $checkPermissions = t

$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);
Expand Down Expand Up @@ -299,7 +299,7 @@ public static function getSubsiteIDForDomain($host = null, $checkPermissions = t
}

if ($cacheKey) {
self::$cache_subsite_for_domain[$cacheKey] = $subsiteID;
Subsite::$cache_subsite_for_domain[$cacheKey] = $subsiteID;
}

return $subsiteID;
Expand Down Expand Up @@ -327,15 +327,15 @@ public static function get_from_all_subsites($className, $filter = '', $sort = '
*/
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;
}

Expand All @@ -344,8 +344,8 @@ public static function withDisabledSubsiteFilter(callable $callable, bool $disab
*/
public static function on_db_reset()
{
self::$cache_accessible_sites = [];
self::$cache_subsite_for_domain = [];
Subsite::$cache_accessible_sites = [];
Subsite::$cache_subsite_for_domain = [];
}

/**
Expand Down Expand Up @@ -451,8 +451,8 @@ public static function accessible_sites(

// 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)
Expand Down Expand Up @@ -515,7 +515,7 @@ public static function accessible_sites(
if (!is_array($permCode)) {
$permCode = [$permCode];
}
if (self::hasMainSitePermission($member, $permCode)) {
if (Subsite::hasMainSitePermission($member, $permCode)) {
$subsites = $subsites->toArray();

$mainSite = new Subsite();
Expand All @@ -525,7 +525,7 @@ public static function accessible_sites(
}
}

self::$cache_accessible_sites[$cacheKey] = $subsites;
Subsite::$cache_accessible_sites[$cacheKey] = $subsites;

return $subsites;
}
Expand Down Expand Up @@ -769,7 +769,7 @@ public function fieldLabels($includerelations = true)
*/
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);
}

Expand Down Expand Up @@ -956,7 +956,7 @@ public function duplicate(bool $doWrite = true, ?array $manyMany = null): static
$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.
Expand All @@ -971,21 +971,21 @@ public function duplicate(bool $doWrite = true, ?array $manyMany = null): static

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;
}
Expand Down
12 changes: 6 additions & 6 deletions src/Model/SubsiteDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ public function onAfterWrite()
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)
Expand All @@ -119,7 +119,7 @@ public function getCMSFields()
'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 />' .
Expand Down Expand Up @@ -169,9 +169,9 @@ public function Link()
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();
Expand Down
2 changes: 1 addition & 1 deletion src/Pages/SubsitesVirtualPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function getVirtualFields()
}
}

foreach (self::$db as $field => $type) {
foreach (SubsitesVirtualPage::$db as $field => $type) {
if (in_array($field, $fields ?? [])) {
unset($fields[array_search($field, $fields)]);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Reports/SubsiteReportWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ 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();
$options = [SubsiteReportWrapper::SUBSITE_ID_ALL => _t(__CLASS__ . '.ReportDropdownAll', 'All')] + $subsites->map()->toArray();

$subsiteField = DropdownField::create(
'Subsite',
Expand Down Expand Up @@ -56,8 +56,8 @@ public function columns()

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);
});
Expand All @@ -70,8 +70,8 @@ public function sourceQuery($params)

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);
});
Expand Down
2 changes: 1 addition & 1 deletion tests/php/SiteTreeSubsitesTest/TestErrorPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 757b1b6

Please sign in to comment.