- namespacing all classes

- moving all phpunit tests into tests/php
- moving all extensions from _config.php into config.yml and removing obsolete _config.php
- moving GridFieldSubsiteDetailForm_ItemRequest into own file

(cherry picked from commit ee02828)
This commit is contained in:
Tim Kung 2017-04-23 22:23:34 +02:00 committed by Werner M. Krauß
parent d8e72f3ac9
commit 5d3af16aaf
32 changed files with 721 additions and 609 deletions

View File

@ -1,60 +1,11 @@
--- ---
Name: subsiteconfig Name: subsiteconfig
After:
- 'framework/*'
--- ---
SilverStripe\AssetAdmin\Controller\AssetAdmin:
treats_subsite_0_as_global: true
SilverStripe\Control\Director: SilverStripe\Control\Director:
rules: rules:
SubsiteXHRController: SilverStripe\Subsites\Controller\SubsiteXHRController SubsiteXHRController: SilverStripe\Subsites\Controller\SubsiteXHRController
SilverStripe\AssetAdmin\Controller\AssetAdmin:
treats_subsite_0_as_global: true
extensions:
- SilverStripe\Subsites\Extensions\SubsiteMenuExtension
SilverStripe\CMS\Model\SiteTree:
extensions:
- SilverStripe\Subsites\Extensions\SiteTreeSubsites
SilverStripe\CMS\Controllers\ContentController:
extensions:
- SilverStripe\Subsites\Extensions\ControllerSubsites
SilverStripe\CMS\Controllers\CMSPageAddController:
extensions:
- SilverStripe\Subsites\Extensions\CMSPageAddControllerExtension
SilverStripe\Admin\LeftAndMain:
extensions:
- SilverStripe\Subsites\Extensions\LeftAndMainSubsites
- SilverStripe\Subsites\Extensions\ControllerSubsites
SilverStripe\Security\Group:
extensions:
- SilverStripe\Subsites\Extensions\GroupSubsites
SilverStripe\Assets\File:
extensions:
- SilverStripe\Subsites\Extensions\FileSubsites
SilverStripe\CMS\Model\ErrorPage:
extensions:
- SilverStripe\Subsites\Extensions\ErrorPageSubsite
SilverStripe\SiteConfig\SiteConfig:
extensions:
- SilverStripe\Subsites\Extensions\SiteConfigSubsites
SilverStripe\Admin\SecurityAdmin:
extensions:
- SilverStripe\Subsites\Extensions\SubsiteMenuExtension
SilverStripe\CMS\Controllers\CMSMain:
extensions:
- SilverStripe\Subsites\Extensions\SubsiteMenuExtension
SilverStripe\CMS\Controllers\CMSPagesController:
extensions:
- SilverStripe\Subsites\Extensions\SubsiteMenuExtension
SilverStripe\Subsites\Admin\SubsiteAdmin:
extensions:
- SilverStripe\Subsites\Extensions\SubsiteMenuExtension

65
_config/extensions.yml Normal file
View File

@ -0,0 +1,65 @@
---
Name: subsiteextensions
After:
- 'framework/*'
---
SilverStripe\CMS\Model\SiteTree:
extensions:
- SilverStripe\Subsites\Extensions\SiteTreeSubsites
SilverStripe\CMS\Controllers\ContentController:
extensions:
- SilverStripe\Subsites\Extensions\ControllerSubsites
SilverStripe\CMS\Controllers\CMSPageAddController:
extensions:
- SilverStripe\Subsites\Extensions\CMSPageAddControllerExtension
SilverStripe\Admin\LeftAndMain:
extensions:
- SilverStripe\Subsites\Extensions\LeftAndMainSubsites
- SilverStripe\Subsites\Extensions\ControllerSubsites
SilverStripe\Security\Group:
extensions:
- SilverStripe\Subsites\Extensions\GroupSubsites
SilverStripe\Assets\File:
extensions:
- SilverStripe\Subsites\Extensions\FileSubsites
SilverStripe\CMS\Model\ErrorPage:
extensions:
- SilverStripe\Subsites\Extensions\ErrorPageSubsite
SilverStripe\SiteConfig\SiteConfig:
extensions:
- SilverStripe\Subsites\Extensions\SiteConfigSubsites
SilverStripe\Reports\Report:
extensions:
- SilverStripe\Subsites\SubsiteReportWrapper
SilverStripe\AssetAdmin\Controller\AssetAdmin:
extensions:
- SilverStripe\Subsites\Extensions\SubsiteMenuExtension
SilverStripe\Admin\SecurityAdmin:
extensions:
- SilverStripe\Subsites\Extensions\SubsiteMenuExtension
SilverStripe\CMS\Controllers\CMSMain:
extensions:
- SilverStripe\Subsites\Extensions\SubsiteMenuExtension
SilverStripe\CMS\Controllers\CMSPagesController:
extensions:
- SilverStripe\Subsites\Extensions\SubsiteMenuExtension
SilverStripe\Subsites\SubsiteAdmin:
extensions:
- SilverStripe\Subsites\Extensions\SubsiteMenuExtension
SilverStripe\CMS\Controllers\CMSPageSettingsController:
extensions:
- SilverStripe\Subsites\Extensions\SubsiteMenuExtension

View File

@ -1,8 +1,6 @@
<?php <?php
namespace SilverStripe\Subsites\Extensions; namespace SilverStripe\Subsites\Extensions;
use SilverStripe\Core\Extension; use SilverStripe\Core\Extension;
use SilverStripe\Forms\HiddenField; use SilverStripe\Forms\HiddenField;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;

View File

@ -1,8 +1,6 @@
<?php <?php
namespace SilverStripe\Subsites\Extensions; namespace SilverStripe\Subsites\Extensions;
use SilverStripe\Core\Extension; use SilverStripe\Core\Extension;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\View\SSViewer; use SilverStripe\View\SSViewer;
@ -12,6 +10,7 @@ use SilverStripe\View\SSViewer;
*/ */
class ControllerSubsites extends Extension class ControllerSubsites extends Extension
{ {
public function controllerAugmentInit() public function controllerAugmentInit()
{ {
if ($subsite = Subsite::currentSubsite()) { if ($subsite = Subsite::currentSubsite()) {
@ -27,4 +26,5 @@ class ControllerSubsites extends Extension
return $subsite; return $subsite;
} }
} }
} }

View File

@ -10,6 +10,7 @@ use SilverStripe\Subsites\Model\Subsite;
class ErrorPageSubsite extends DataExtension class ErrorPageSubsite extends DataExtension
{ {
/** /**
* Alter file path to generated a static (static) error page file to handle error page template on different sub-sites * Alter file path to generated a static (static) error page file to handle error page template on different sub-sites
* *
@ -49,4 +50,5 @@ class ErrorPageSubsite extends DataExtension
return $filepath; return $filepath;
} }
} }

View File

@ -2,7 +2,6 @@
namespace SilverStripe\Subsites\Extensions; namespace SilverStripe\Subsites\Extensions;
use SilverStripe\Assets\Folder; use SilverStripe\Assets\Folder;
use SilverStripe\Control\Session; use SilverStripe\Control\Session;
use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\DropdownField;
@ -13,8 +12,6 @@ use SilverStripe\ORM\DataQuery;
use SilverStripe\ORM\Queries\SQLSelect; use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\Security\Permission; use SilverStripe\Security\Permission;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
/** /**
* Extension for the File object to add subsites support * Extension for the File object to add subsites support
* *

View File

@ -1,20 +1,24 @@
<?php <?php
use SilverStripe\View\Requirements; namespace SilverStripe\Subsites\Extensions;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Security\Member;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\Core\Config\Config;
use SilverStripe\View\ArrayData;
use SilverStripe\Security\Permission;
use SilverStripe\Control\Session;
use SilverStripe\Admin\CMSMenu; use SilverStripe\Admin\CMSMenu;
use SilverStripe\Security\Security;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\Session;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Extension; use SilverStripe\Core\Extension;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\HiddenField;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Security\Security;
use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\View\ArrayData;
use SilverStripe\View\Requirements;
/** /**
* Decorator designed to add subsites support to LeftAndMain * Decorator designed to add subsites support to LeftAndMain
* *
@ -22,6 +26,7 @@ use SilverStripe\Core\Extension;
*/ */
class LeftAndMainSubsites extends Extension class LeftAndMainSubsites extends Extension
{ {
private static $allowed_actions = array('CopyToSubsite'); private static $allowed_actions = array('CopyToSubsite');
/** /**
@ -351,4 +356,5 @@ class LeftAndMainSubsites extends Extension
$newPage->ID $newPage->ID
)); ));
} }
} }

View File

@ -66,4 +66,5 @@ class SiteConfigSubsites extends DataExtension
{ {
$fields->push(new HiddenField('SubsiteID', 'SubsiteID', Subsite::currentSubsiteID())); $fields->push(new HiddenField('SubsiteID', 'SubsiteID', Subsite::currentSubsiteID()));
} }
} }

View File

@ -5,24 +5,24 @@ namespace SilverStripe\Subsites\Extensions;
use Page; use Page;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\ORM\DataQuery;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\InlineFormAction;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\Core\Config\Config;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Member;
use SilverStripe\View\SSViewer;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
use SilverStripe\Control\HTTP; use SilverStripe\Control\HTTP;
use SilverStripe\Core\Convert; use SilverStripe\Core\Convert;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\InlineFormAction;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\ORM\DataExtension; use SilverStripe\ORM\DataExtension;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataQuery;
use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\Security\Member;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\View\SSViewer;
/** /**
@ -30,6 +30,7 @@ use SilverStripe\Subsites\Model\Subsite;
*/ */
class SiteTreeSubsites extends DataExtension class SiteTreeSubsites extends DataExtension
{ {
private static $has_one = [ private static $has_one = [
'Subsite' => Subsite::class, // The subsite that this page belongs to 'Subsite' => Subsite::class, // The subsite that this page belongs to
]; ];
@ -420,4 +421,5 @@ class SiteTreeSubsites extends DataExtension
} }
} }
} }
} }

View File

@ -2,65 +2,11 @@
namespace SilverStripe\Subsites\Forms; namespace SilverStripe\Subsites\Forms;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\GridField\GridFieldDetailForm; use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
use SilverStripe\Subsites\Model\Subsite;
class GridFieldSubsiteDetailForm extends GridFieldDetailForm class GridFieldSubsiteDetailForm extends GridFieldDetailForm
{ {
protected $itemRequestClass = GridFieldSubsiteDetailForm_ItemRequest::class;
}
class GridFieldSubsiteDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest protected $itemRequestClass = 'GridFieldSubsiteDetailForm_ItemRequest';
{
private static $allowed_actions = [
'ItemEditForm',
];
/**
* Builds an item edit form. The arguments to getCMSFields() are the popupController and
* popupFormName, however this is an experimental API and may change.
*
* @todo In the future, we will probably need to come up with a tigher object representing a partially
* complete controller with gaps for extra functionality. This, for example, would be a better way
* of letting Security/login put its log-in form inside a UI specified elsewhere.
*
* @return Form
* @see GridFieldDetailForm_ItemRequest::ItemEditForm()
*/
public function ItemEditForm()
{
$form = parent::ItemEditForm();
if ($this->record->ID == 0) {
$templates = Subsite::get()->sort('Title');
$templateArray = [];
if ($templates) {
$templateArray = $templates->map('ID', 'Title');
}
$templateDropdown = new DropdownField('TemplateID', _t('Subsite.COPYSTRUCTURE', 'Copy structure from:'),
$templateArray);
$templateDropdown->setEmptyString('(' . _t('Subsite.NOTEMPLATE', 'No template') . ')');
$form->Fields()->addFieldToTab('Root.Configuration', $templateDropdown);
}
return $form;
}
public function doSave($data, $form)
{
$new_record = $this->record->ID == 0;
if ($new_record && isset($data['TemplateID']) && !empty($data['TemplateID'])) {
$template = Subsite::get()->byID(intval($data['TemplateID']));
if ($template) {
$this->record = $template->duplicate();
}
}
return parent::doSave($data, $form);
}
} }

View File

@ -0,0 +1,59 @@
<?php
namespace SilverStripe\Subsites\Forms;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
use SilverStripe\Subsites\Model\Subsite;
class GridFieldSubsiteDetailForm_ItemRequest extends GridFieldDetailForm_ItemRequest
{
private static $allowed_actions = array(
'ItemEditForm',
);
/**
* Builds an item edit form. The arguments to getCMSFields() are the popupController and
* popupFormName, however this is an experimental API and may change.
*
* @todo In the future, we will probably need to come up with a tigher object representing a partially
* complete controller with gaps for extra functionality. This, for example, would be a better way
* of letting Security/login put its log-in form inside a UI specified elsewhere.
*
* @return Form
* @see GridFieldDetailForm_ItemRequest::ItemEditForm()
*/
public function ItemEditForm()
{
$form=parent::ItemEditForm();
if ($this->record->ID == 0) {
$templates = Subsite::get()->sort('Title');
$templateArray = array();
if ($templates) {
$templateArray = $templates->map('ID', 'Title');
}
$templateDropdown = new DropdownField('TemplateID', _t('Subsite.COPYSTRUCTURE', 'Copy structure from:'), $templateArray);
$templateDropdown->setEmptyString('(' . _t('Subsite.NOTEMPLATE', 'No template') . ')');
$form->Fields()->addFieldToTab('Root.Configuration', $templateDropdown);
}
return $form;
}
public function doSave($data, $form)
{
$new_record = $this->record->ID == 0;
if ($new_record && isset($data['TemplateID']) && !empty($data['TemplateID'])) {
$template = Subsite::get()->byID(intval($data['TemplateID']));
if ($template) {
$this->record = $template->duplicate();
}
}
return parent::doSave($data, $form);
}
}

View File

@ -1,5 +1,7 @@
<?php <?php
namespace SilverStripe\Subsites\Forms;
use SilverStripe\Forms\TextField; use SilverStripe\Forms\TextField;
/** /**
@ -7,6 +9,7 @@ use SilverStripe\Forms\TextField;
*/ */
class WildcardDomainField extends TextField class WildcardDomainField extends TextField
{ {
/** /**
* Validate this field as a valid hostname * Validate this field as a valid hostname
* *
@ -24,6 +27,7 @@ class WildcardDomainField extends TextField
_t("DomainNameField.INVALID_DOMAIN", "Invalid domain name"), _t("DomainNameField.INVALID_DOMAIN", "Invalid domain name"),
"validation" "validation"
); );
return false; return false;
} }
@ -42,4 +46,5 @@ class WildcardDomainField extends TextField
{ {
return 'text wildcarddomain'; return 'text wildcarddomain';
} }
} }

View File

@ -2,7 +2,6 @@
namespace SilverStripe\Subsites\Model; namespace SilverStripe\Subsites\Model;
use SilverStripe\Admin\CMSMenu; use SilverStripe\Admin\CMSMenu;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;
@ -28,9 +27,9 @@ use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\DataList; use SilverStripe\ORM\DataList;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DB; use SilverStripe\ORM\DB;
use SilverStripe\Security\Group;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use SilverStripe\Security\Permission; use SilverStripe\Security\Permission;
use SilverStripe\Security\Group;
use SilverStripe\Versioned\Versioned; use SilverStripe\Versioned\Versioned;
use UnexpectedValueException; use UnexpectedValueException;
@ -120,7 +119,8 @@ class Subsite extends DataObject
* @param array $themes - Numeric array of all themes which are allowed to be selected for all subsites. * @param array $themes - Numeric array of all themes which are allowed to be selected for all subsites.
*/ */
public static function set_allowed_themes($themes) public static function set_allowed_themes($themes)
{self::$allowed_themes = $themes; {
self::$allowed_themes = $themes;
} }
/** /**
@ -147,7 +147,8 @@ class Subsite extends DataObject
* @return int ID of the current subsite instance * @return int ID of the current subsite instance
*/ */
public static function currentSubsiteID() public static function currentSubsiteID()
{$id = null; {
$id = null;
if (isset($_GET['SubsiteID'])) { if (isset($_GET['SubsiteID'])) {
$id = (int)$_GET['SubsiteID']; $id = (int)$_GET['SubsiteID'];
@ -168,13 +169,19 @@ class Subsite extends DataObject
* *
* @param int|Subsite $subsite Either the ID of the subsite, or the subsite object itself * @param int|Subsite $subsite Either the ID of the subsite, or the subsite object itself
*/ */
public static function changeSubsite($subsite) { public static function changeSubsite($subsite)
{
// Session subsite change only meaningful if the session is active. // Session subsite change only meaningful if the session is active.
// Otherwise we risk setting it to wrong value, e.g. if we rely on currentSubsiteID. // Otherwise we risk setting it to wrong value, e.g. if we rely on currentSubsiteID.
if (!Subsite::$use_session_subsiteid) return; if (!Subsite::$use_session_subsiteid) {
return;
}
if(is_object($subsite)) $subsiteID = $subsite->ID; if (is_object($subsite)) {
else $subsiteID = $subsite; $subsiteID = $subsite->ID;
} else {
$subsiteID = $subsite;
}
Session::set('SubsiteID', (int)$subsiteID); Session::set('SubsiteID', (int)$subsiteID);
@ -198,7 +205,8 @@ class Subsite extends DataObject
* @param $host The host to find the subsite for. If not specified, $_SERVER['HTTP_HOST'] is used. * @param $host The host to find the subsite for. If not specified, $_SERVER['HTTP_HOST'] is used.
* @return int Subsite ID * @return int Subsite ID
*/ */
public static function getSubsiteIDForDomain($host = null, $checkPermissions = true) { public static function getSubsiteIDForDomain($host = null, $checkPermissions = true)
{
if ($host == null && isset($_SERVER['HTTP_HOST'])) { if ($host == null && isset($_SERVER['HTTP_HOST'])) {
$host = $_SERVER['HTTP_HOST']; $host = $_SERVER['HTTP_HOST'];
} }
@ -206,7 +214,9 @@ class Subsite extends DataObject
$matchingDomains = null; $matchingDomains = null;
$cacheKey = null; $cacheKey = null;
if ($host) { if ($host) {
if(!self::$strict_subdomain_matching) $host = preg_replace('/^www\./', '', $host); if (!self::$strict_subdomain_matching) {
$host = preg_replace('/^www\./', '', $host);
}
$cacheKey = implode('_', [$host, Member::currentUserID(), self::$check_is_public]); $cacheKey = implode('_', [$host, Member::currentUserID(), self::$check_is_public]);
if (isset(self::$_cache_subsite_for_domain[$cacheKey])) { if (isset(self::$_cache_subsite_for_domain[$cacheKey])) {
@ -218,7 +228,8 @@ class Subsite extends DataObject
SubsiteDomain::class, SubsiteDomain::class,
"'$SQL_host' LIKE replace(\"SubsiteDomain\".\"Domain\",'*','%')", "'$SQL_host' LIKE replace(\"SubsiteDomain\".\"Domain\",'*','%')",
"\"IsPrimary\" DESC" "\"IsPrimary\" DESC"
)->innerJoin('Subsite', "\"Subsite\".\"ID\" = \"SubsiteDomain\".\"SubsiteID\" AND \"Subsite\".\"IsPublic\"=1"); )->innerJoin('Subsite',
"\"Subsite\".\"ID\" = \"SubsiteDomain\".\"SubsiteID\" AND \"Subsite\".\"IsPublic\"=1");
} }
if ($matchingDomains && $matchingDomains->Count()) { if ($matchingDomains && $matchingDomains->Count()) {
@ -240,7 +251,8 @@ class Subsite extends DataObject
} else { } else {
// Default subsite id = 0, the main site // Default subsite id = 0, the main site
$subsiteID = 0; $subsiteID = 0;
}} }
}
if ($cacheKey) { if ($cacheKey) {
self::$_cache_subsite_for_domain[$cacheKey] = $subsiteID; self::$_cache_subsite_for_domain[$cacheKey] = $subsiteID;
@ -258,7 +270,8 @@ class Subsite extends DataObject
* @param string $limit * @param string $limit
* @return DataList * @return DataList
*/ */
public static function get_from_all_subsites($className, $filter = "", $sort = "", $join = "", $limit = "") { public static function get_from_all_subsites($className, $filter = "", $sort = "", $join = "", $limit = "")
{
$result = DataObject::get($className, $filter, $sort, $join, $limit); $result = DataObject::get($className, $filter, $sort, $join, $limit);
$result = $result->setDataQueryParam('Subsite.filter', false); $result = $result->setDataQueryParam('Subsite.filter', false);
return $result; return $result;
@ -354,7 +367,12 @@ class Subsite extends DataObject
* @param $member * @param $member
* @return DataList of {@link Subsite} instances * @return DataList of {@link Subsite} instances
*/ */
public static function accessible_sites($permCode, $includeMainSite = true, $mainSiteTitle = "Main site", $member = null) public static function accessible_sites(
$permCode,
$includeMainSite = true,
$mainSiteTitle = "Main site",
$member = null
)
{ {
// Rationalise member arguments // Rationalise member arguments
if (!$member) { if (!$member) {
@ -368,8 +386,11 @@ class Subsite extends DataObject
} }
// Rationalise permCode argument // Rationalise permCode argument
if(is_array($permCode)) $SQL_codes = "'" . implode("', '", Convert::raw2sql($permCode)) . "'"; if (is_array($permCode)) {
else $SQL_codes = "'" . Convert::raw2sql($permCode) . "'"; $SQL_codes = "'" . implode("', '", Convert::raw2sql($permCode)) . "'";
} else {
$SQL_codes = "'" . Convert::raw2sql($permCode) . "'";
}
// Cache handling // Cache handling
$cacheKey = $SQL_codes . '-' . $member->ID . '-' . $includeMainSite . '-' . $mainSiteTitle; $cacheKey = $SQL_codes . '-' . $member->ID . '-' . $includeMainSite . '-' . $mainSiteTitle;
@ -387,8 +408,11 @@ class Subsite extends DataObject
->innerJoin('Permission', ->innerJoin('Permission',
"\"Group\".\"ID\"=\"Permission\".\"GroupID\" AND \"Permission\".\"Code\" IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')"); "\"Group\".\"ID\"=\"Permission\".\"GroupID\" AND \"Permission\".\"Code\" IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')");
if(!$subsites) $subsites = new ArrayList(); if (!$subsites) {
$subsites = new ArrayList();
}
/** @var DataList $rolesSubsites */
$rolesSubsites = DataList::create(Subsite::class) $rolesSubsites = DataList::create(Subsite::class)
->where("\"Subsite\".\"Title\" != ''") ->where("\"Subsite\".\"Title\" != ''")
->leftJoin('Group_Subsites', "\"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"") ->leftJoin('Group_Subsites', "\"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"")
@ -401,15 +425,19 @@ class Subsite extends DataObject
->innerJoin('PermissionRoleCode', ->innerJoin('PermissionRoleCode',
"\"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\" AND \"PermissionRoleCode\".\"Code\" IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')"); "\"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\" AND \"PermissionRoleCode\".\"Code\" IN ($SQL_codes, 'CMS_ACCESS_LeftAndMain', 'ADMIN')");
if(!$subsites && $rolesSubsites) return $rolesSubsites; if (!$subsites && $rolesSubsites) {
return $rolesSubsites;
}
$subsites = new ArrayList($subsites->toArray()); $subsites = new ArrayList($subsites->toArray());
if($rolesSubsites) foreach($rolesSubsites as $subsite) { if ($rolesSubsites) {
foreach ($rolesSubsites as $subsite) {
if (!$subsites->find('ID', $subsite->ID)) { if (!$subsites->find('ID', $subsite->ID)) {
$subsites->push($subsite); $subsites->push($subsite);
} }
} }
}
if ($includeMainSite) { if ($includeMainSite) {
if (!is_array($permCode)) { if (!is_array($permCode)) {
@ -501,9 +529,13 @@ class Subsite extends DataObject
$member = Member::currentUser(); $member = Member::currentUser();
} }
if(!$member) return false; if (!$member) {
return false;
}
if(!in_array("ADMIN", $permissionCodes)) $permissionCodes[] = "ADMIN"; if (!in_array("ADMIN", $permissionCodes)) {
$permissionCodes[] = "ADMIN";
}
$SQLa_perm = Convert::raw2sql($permissionCodes); $SQLa_perm = Convert::raw2sql($permissionCodes);
$SQL_perms = join("','", $SQLa_perm); $SQL_perms = join("','", $SQLa_perm);
@ -537,7 +569,6 @@ class Subsite extends DataObject
} }
/** /**
*
* @var array * @var array
*/ */
private static $db = [ private static $db = [
@ -556,7 +587,6 @@ class Subsite extends DataObject
]; ];
/** /**
*
* @var array * @var array
*/ */
private static $has_many = [ private static $has_many = [
@ -564,7 +594,6 @@ class Subsite extends DataObject
]; ];
/** /**
*
* @var array * @var array
*/ */
private static $belongs_many_many = [ private static $belongs_many_many = [
@ -572,7 +601,6 @@ class Subsite extends DataObject
]; ];
/** /**
*
* @var array * @var array
*/ */
private static $defaults = [ private static $defaults = [
@ -580,7 +608,6 @@ class Subsite extends DataObject
]; ];
/** /**
*
* @var array * @var array
*/ */
private static $searchable_fields = [ private static $searchable_fields = [
@ -590,7 +617,6 @@ class Subsite extends DataObject
]; ];
/** /**
*
* @var string * @var string
*/ */
private static $default_sort = "\"Title\" ASC"; private static $default_sort = "\"Title\" ASC";
@ -600,7 +626,8 @@ class Subsite extends DataObject
* @return boolean * @return boolean
*/ */
public function canEdit($member = false) public function canEdit($member = false)
{return true; {
return true;
} }
/** /**
@ -620,7 +647,8 @@ class Subsite extends DataObject
} else { } else {
$domainTable = new LiteralField( $domainTable = new LiteralField(
'Domains', 'Domains',
'<p>'._t('Subsite.DOMAINSAVEFIRST', 'You can only add domains after saving for the first time').'</p>' '<p>' . _t('Subsite.DOMAINSAVEFIRST',
'You can only add domains after saving for the first time') . '</p>'
); );
} }
@ -630,7 +658,7 @@ class Subsite extends DataObject
Injector::inst()->get(IntlLocales::class)->getLocales() Injector::inst()->get(IntlLocales::class)->getLocales()
); );
$pageTypeMap = array(); $pageTypeMap = [];
$pageTypes = SiteTree::page_type_classes(); $pageTypes = SiteTree::page_type_classes();
foreach ($pageTypes as $pageType) { foreach ($pageTypes as $pageType) {
$pageTypeMap[$pageType] = singleton($pageType)->i18n_singular_name(); $pageTypeMap[$pageType] = singleton($pageType)->i18n_singular_name();
@ -687,7 +715,8 @@ class Subsite extends DataObject
* @param boolean $includerelations * @param boolean $includerelations
* @return array * @return array
*/ */
public function fieldLabels($includerelations = true) { public function fieldLabels($includerelations = true)
{
$labels = parent::fieldLabels($includerelations); $labels = parent::fieldLabels($includerelations);
$labels['Title'] = _t('Subsites.TitleFieldLabel', 'Subsite Name'); $labels['Title'] = _t('Subsites.TitleFieldLabel', 'Subsite Name');
$labels['RedirectURL'] = _t('Subsites.RedirectURLFieldLabel', 'Redirect URL'); $labels['RedirectURL'] = _t('Subsites.RedirectURLFieldLabel', 'Redirect URL');
@ -703,19 +732,21 @@ class Subsite extends DataObject
} }
/** /**
* Return the themes that can be used with this subsite, as an array of themecode => description * Return the themes that can be used with this subsite, as an array of themecode => description
* *
* @return array * @return array
*/ */
public function allowedThemes() public function allowedThemes()
{if($themes = $this->stat('allowed_themes')) { {
if ($themes = $this->stat('allowed_themes')) {
return ArrayLib::valuekey($themes); return ArrayLib::valuekey($themes);
} else { } else {
$themes = []; $themes = [];
if (is_dir(THEMES_PATH)) { if (is_dir(THEMES_PATH)) {
foreach (scandir(THEMES_PATH) as $theme) { foreach (scandir(THEMES_PATH) as $theme) {
if($theme[0] == '.') {continue;} if ($theme[0] == '.') {
continue;
}
$theme = strtok($theme, '_'); $theme = strtok($theme, '_');
$themes[$theme] = $theme; $themes[$theme] = $theme;
} }
@ -728,7 +759,8 @@ class Subsite extends DataObject
/** /**
* @return string Current locale of the subsite * @return string Current locale of the subsite
*/ */
public function getLanguage() { public function getLanguage()
{
if ($this->getField('Language')) { if ($this->getField('Language')) {
return $this->getField('Language'); return $this->getField('Language');
} else { } else {
@ -740,7 +772,8 @@ class Subsite extends DataObject
* *
* @return ValidationResult * @return ValidationResult
*/ */
public function validate() { public function validate()
{
$result = parent::validate(); $result = parent::validate();
if (!$this->Title) { if (!$this->Title) {
$result->error(_t('Subsite.ValidateTitle', 'Please add a "Title"')); $result->error(_t('Subsite.ValidateTitle', 'Please add a "Title"'));
@ -818,7 +851,8 @@ class Subsite extends DataObject
/** /**
* @todo getClassName is redundant, already stored as a database field? * @todo getClassName is redundant, already stored as a database field?
*/ */
public function getClassName() { public function getClassName()
{
return $this->class; return $this->class;
} }
@ -828,7 +862,8 @@ class Subsite extends DataObject
* @return string - javascript * @return string - javascript
*/ */
public function adminDuplicate() public function adminDuplicate()
{$newItem = $this->duplicate(); {
$newItem = $this->duplicate();
$message = _t( $message = _t(
'Subsite.CopyMessage', 'Subsite.CopyMessage',
'Created a copy of {title}', 'Created a copy of {title}',
@ -844,7 +879,8 @@ JS;
/** /**
* Make this subsite the current one * Make this subsite the current one
*/ */
public function activate() { public function activate()
{
Subsite::changeSubsite($this); Subsite::changeSubsite($this);
} }
@ -875,7 +911,8 @@ JS;
/** /**
* Duplicate this subsite * Duplicate this subsite
*/ */
public function duplicate($doWrite = true) { public function duplicate($doWrite = true)
{
$duplicate = parent::duplicate($doWrite); $duplicate = parent::duplicate($doWrite);
$oldSubsiteID = Session::get('SubsiteID'); $oldSubsiteID = Session::get('SubsiteID');

View File

@ -2,12 +2,13 @@
namespace SilverStripe\Subsites\Model; namespace SilverStripe\Subsites\Model;
use SilverStripe\Control\Director;
use SilverStripe\Control\Controller; use SilverStripe\Control\Controller;
use SilverStripe\Control\Director;
use SilverStripe\Forms\CheckboxField; use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\OptionsetField; use SilverStripe\Forms\OptionsetField;
use SilverStripe\ORM\DataObject; use SilverStripe\ORM\DataObject;
use SilverStripe\Subsites\Forms\WildcardDomainField;
/** /**
@ -38,7 +39,8 @@ class SubsiteDomain extends DataObject
"IsPrimary" => "Boolean", "IsPrimary" => "Boolean",
]; ];
/*** Specifies that this subsite is http only /**
* Specifies that this subsite is http only
*/ */
const PROTOCOL_HTTP = 'http'; const PROTOCOL_HTTP = 'http';
@ -82,11 +84,11 @@ class SubsiteDomain extends DataObject
/*** @config /*** @config
* @var array * @var array
*/ */
private static $casting = array( private static $casting = [
'SubstitutedDomain' => 'Varchar', 'SubstitutedDomain' => 'Varchar',
'FullProtocol' => 'Varchar', 'FullProtocol' => 'Varchar',
'AbsoluteLink' => 'Varchar', 'AbsoluteLink' => 'Varchar',
); ];
/** /**
* Whenever a Subsite Domain is written, rewrite the hostmap * Whenever a Subsite Domain is written, rewrite the hostmap
@ -94,7 +96,8 @@ class SubsiteDomain extends DataObject
* @return void * @return void
*/ */
public function onAfterWrite() public function onAfterWrite()
{Subsite::writeHostMap(); {
Subsite::writeHostMap();
} }
/** /**
@ -103,11 +106,12 @@ class SubsiteDomain extends DataObject
*/ */
public function getCMSFields() public function getCMSFields()
{ {
$protocols = array( $protocols = [
self::PROTOCOL_HTTP => _t('SubsiteDomain.PROTOCOL_HTTP', 'http://'), self::PROTOCOL_HTTP => _t('SubsiteDomain.PROTOCOL_HTTP', 'http://'),
self::PROTOCOL_HTTPS => _t('SubsiteDomain.PROTOCOL_HTTPS', 'https://'), self::PROTOCOL_HTTPS => _t('SubsiteDomain.PROTOCOL_HTTPS', 'https://'),
self::PROTOCOL_AUTOMATIC => _t('SubsiteDomain.PROTOCOL_AUTOMATIC', 'Automatic') self::PROTOCOL_AUTOMATIC => _t('SubsiteDomain.PROTOCOL_AUTOMATIC', 'Automatic')
);$fields = new FieldList( ];
$fields = new FieldList(
WildcardDomainField::create('Domain', $this->fieldLabel('Domain'), null, 255) WildcardDomainField::create('Domain', $this->fieldLabel('Domain'), null, 255)
->setDescription(_t( ->setDescription(_t(
'SubsiteDomain.DOMAIN_DESCRIPTION', 'SubsiteDomain.DOMAIN_DESCRIPTION',
@ -170,16 +174,13 @@ class SubsiteDomain extends DataObject
public function getFullProtocol() public function getFullProtocol()
{ {
switch ($this->Protocol) { switch ($this->Protocol) {
case self::PROTOCOL_HTTPS: case self::PROTOCOL_HTTPS: {
{
return 'https://'; return 'https://';
} }
case self::PROTOCOL_HTTP: case self::PROTOCOL_HTTP: {
{
return 'http://'; return 'http://';
} }
default: default: {
{
return Director::protocol(); return Director::protocol();
} }
} }

View File

@ -18,7 +18,6 @@ use SilverStripe\Subsites\Forms\SubsitesTreeDropdownField;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\View\ArrayData; use SilverStripe\View\ArrayData;
class SubsitesVirtualPage extends VirtualPage class SubsitesVirtualPage extends VirtualPage
{ {

View File

@ -15,9 +15,10 @@ use SilverStripe\Subsites\Model\Subsite;
*/ */
class SubsiteReportWrapper extends ReportWrapper class SubsiteReportWrapper extends ReportWrapper
{ {
///////////////////////////////////////////////////////////////////////////////////////////
// Filtering
/**
* @return FieldList
*/
public function parameterFields() public function parameterFields()
{ {
$subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', true); $subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', true);
@ -44,9 +45,9 @@ class SubsiteReportWrapper extends ReportWrapper
return $fields; return $fields;
} }
/////////////////////////////////////////////////////////////////////////////////////////// /**
// Columns * @return array
*/
public function columns() public function columns()
{ {
$columns = parent::columns(); $columns = parent::columns();
@ -57,6 +58,10 @@ class SubsiteReportWrapper extends ReportWrapper
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Querying // Querying
/**
* @param arary $params
* @return void
*/
public function beforeQuery($params) public function beforeQuery($params)
{ {
// The user has select a few specific sites // The user has select a few specific sites
@ -70,6 +75,10 @@ class SubsiteReportWrapper extends ReportWrapper
Subsite::$force_subsite = join(',', array_keys($options)); Subsite::$force_subsite = join(',', array_keys($options));
} }
} }
/**
* @return void
*/
public function afterQuery() public function afterQuery()
{ {
// Manually manage the subsite filtering // Manually manage the subsite filtering

7
phpunit.xml.dist Normal file
View File

@ -0,0 +1,7 @@
<phpunit bootstrap="framework/tests/bootstrap.php" colors="true">
<testsuite name="Default">
<directory>tests/php</directory>
</testsuite>
</phpunit>

View File

@ -1,6 +1,6 @@
<?php <?php
namespace Subsites\Test\Behaviour; namespace SilverStripe\Subsites\Tests\Behaviour;
if (!class_exists('SilverStripe\BehatExtension\Context\SilverStripeContext')) { if (!class_exists('SilverStripe\BehatExtension\Context\SilverStripeContext')) {
return; return;

View File

@ -1,5 +1,7 @@
<?php <?php
namespace SilverStripe\Subsites\Tests;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
@ -11,7 +13,8 @@ class BaseSubsiteTest extends SapphireTest
parent::setUp(); parent::setUp();
Subsite::$use_session_subsiteid = true; Subsite::$use_session_subsiteid = true;
Subsite::$force_subsite = null;} Subsite::$force_subsite = null;
}
/** /**
* Avoid subsites filtering on fixture fetching. * Avoid subsites filtering on fixture fetching.

View File

@ -1,13 +1,17 @@
<?php <?php
namespace SilverStripe\Subsites\Tests;
use SilverStripe\Assets\File; use SilverStripe\Assets\File;
use SilverStripe\Assets\Folder; use SilverStripe\Assets\Folder;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use SilverStripe\Subsites\Tests\BaseSubsiteTest;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
class FileSubsitesTest extends BaseSubsiteTest class FileSubsitesTest extends BaseSubsiteTest
{ {
public static $fixture_file = 'subsites/tests/SubsiteTest.yml'; public static $fixture_file = 'subsites/tests/SubsiteTest.yml';
/** /**

View File

@ -1,5 +1,7 @@
<?php <?php
namespace SilverStripe\Subsites\Tests;
use SilverStripe\Security\Group; use SilverStripe\Security\Group;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;
use SilverStripe\Subsites\Extensions\GroupSubsites; use SilverStripe\Subsites\Extensions\GroupSubsites;
@ -10,7 +12,6 @@ class GroupSubsitesTest extends BaseSubsiteTest
public static $fixture_file = 'subsites/tests/SubsiteTest.yml'; public static $fixture_file = 'subsites/tests/SubsiteTest.yml';
protected $requireDefaultRecordsFrom = [GroupSubsites::class]; protected $requireDefaultRecordsFrom = [GroupSubsites::class];
public function testTrivialFeatures() public function testTrivialFeatures()
{ {
$this->assertTrue(is_array(singleton('GroupSubsites')->extraStatics())); $this->assertTrue(is_array(singleton('GroupSubsites')->extraStatics()));

View File

@ -1,5 +1,8 @@
<?php <?php
namespace SilverStripe\Subsites\Tests;
use SilverStripe\AssetAdmin\Controller\AssetAdmin;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use SilverStripe\CMS\Controllers\CMSMain; use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\Admin\LeftAndMain; use SilverStripe\Admin\LeftAndMain;
@ -56,7 +59,6 @@ class LeftAndMainSubsitesTest extends FunctionalTest
$subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1'); $subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1');
$subsite2 = $this->objFromFixture(Subsite::class, 'domaintest2'); $subsite2 = $this->objFromFixture(Subsite::class, 'domaintest2');
$subsite3 = $this->objFromFixture(Subsite::class, 'domaintest3'); $subsite3 = $this->objFromFixture(Subsite::class, 'domaintest3');
$ids[] = $subsite1->ID; $ids[] = $subsite1->ID;
$ids[] = $subsite2->ID; $ids[] = $subsite2->ID;
$ids[] = $subsite3->ID; $ids[] = $subsite3->ID;

View File

@ -1,5 +1,7 @@
<?php <?php
namespace SilverStripe\Subsites\Tests;
use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Subsites\Extensions\SiteConfigSubsites; use SilverStripe\Subsites\Extensions\SiteConfigSubsites;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
@ -7,9 +9,9 @@ use SilverStripe\Subsites\Model\Subsite;
class SiteConfigSubsitesTest extends BaseSubsiteTest class SiteConfigSubsitesTest extends BaseSubsiteTest
{ {
static $fixture_file = 'subsites/tests/SubsiteTest.yml'; public static $fixture_file = 'subsites/tests/SubsiteTest.yml';
function testEachSubsiteHasAUniqueSiteConfig() public function testEachSubsiteHasAUniqueSiteConfig()
{ {
$subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1'); $subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1');
$subsite2 = $this->objFromFixture(Subsite::class, 'domaintest2'); $subsite2 = $this->objFromFixture(Subsite::class, 'domaintest2');

View File

@ -1,5 +1,7 @@
<?php <?php
namespace SilverStripe\Subsites\Tests;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\SiteConfig\SiteConfig; use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Forms\FieldList; use SilverStripe\Forms\FieldList;

View File

@ -1,5 +1,7 @@
<?php <?php
namespace SilverStripe\Subsites\Tests;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use SilverStripe\Control\Session; use SilverStripe\Control\Session;
use SilverStripe\Core\Config\Config; use SilverStripe\Core\Config\Config;

View File

@ -1,5 +1,7 @@
<?php <?php
namespace SilverStripe\Subsites\Tests;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use SilverStripe\Control\Session; use SilverStripe\Control\Session;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;

View File

@ -1,9 +1,11 @@
<?php <?php
use SilverStripe\Core\Config\Config; namespace SilverStripe\Subsites\Tests;
use SilverStripe\Control\Director;
use SilverStripe\ORM\DataObject;
use SilverStripe\CMS\Model\SiteTree; use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Control\Director;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\DataObject;
use SilverStripe\Security\Member; use SilverStripe\Security\Member;
use SilverStripe\Subsites\Model\Subsite; use SilverStripe\Subsites\Model\Subsite;
use SilverStripe\Subsites\Model\SubsiteDomain; use SilverStripe\Subsites\Model\SubsiteDomain;

View File

@ -1,5 +1,7 @@
<?php <?php
namespace SilverStripe\Subsites\Tests;
use SilverStripe\Control\Session; use SilverStripe\Control\Session;
use SilverStripe\Dev\FunctionalTest; use SilverStripe\Dev\FunctionalTest;

View File

@ -1,5 +1,7 @@
<?php <?php
namespace SilverStripe\Subsites\Tests;
use SilverStripe\Assets\Filesystem; use SilverStripe\Assets\Filesystem;
use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore; use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore;
use SilverStripe\Control\Director; use SilverStripe\Control\Director;

View File

@ -1,6 +1,9 @@
<?php <?php
namespace SilverStripe\Subsites\Tests;
use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\SapphireTest;
use SilverStripe\Subsites\Forms\WildcardDomainField;
/** /**
* Tests {@see WildcardDomainField} * Tests {@see WildcardDomainField}