mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
- 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:
parent
d8e72f3ac9
commit
5d3af16aaf
@ -1,60 +1,11 @@
|
||||
---
|
||||
Name: subsiteconfig
|
||||
After:
|
||||
- 'framework/*'
|
||||
---
|
||||
SilverStripe\AssetAdmin\Controller\AssetAdmin:
|
||||
treats_subsite_0_as_global: true
|
||||
|
||||
SilverStripe\Control\Director:
|
||||
rules:
|
||||
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
65
_config/extensions.yml
Normal 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
|
@ -1,8 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Extensions;
|
||||
|
||||
|
||||
use SilverStripe\Core\Extension;
|
||||
use SilverStripe\Forms\HiddenField;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
|
@ -1,8 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Extensions;
|
||||
|
||||
|
||||
use SilverStripe\Core\Extension;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
use SilverStripe\View\SSViewer;
|
||||
@ -12,6 +10,7 @@ use SilverStripe\View\SSViewer;
|
||||
*/
|
||||
class ControllerSubsites extends Extension
|
||||
{
|
||||
|
||||
public function controllerAugmentInit()
|
||||
{
|
||||
if ($subsite = Subsite::currentSubsite()) {
|
||||
@ -27,4 +26,5 @@ class ControllerSubsites extends Extension
|
||||
return $subsite;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ use SilverStripe\Subsites\Model\Subsite;
|
||||
|
||||
class ErrorPageSubsite extends DataExtension
|
||||
{
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Extensions;
|
||||
|
||||
|
||||
use SilverStripe\Assets\Folder;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Forms\DropdownField;
|
||||
@ -13,8 +12,6 @@ use SilverStripe\ORM\DataQuery;
|
||||
use SilverStripe\ORM\Queries\SQLSelect;
|
||||
use SilverStripe\Security\Permission;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
|
||||
|
||||
/**
|
||||
* Extension for the File object to add subsites support
|
||||
*
|
||||
|
@ -1,20 +1,24 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\View\Requirements;
|
||||
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;
|
||||
namespace SilverStripe\Subsites\Extensions;
|
||||
|
||||
use SilverStripe\Admin\CMSMenu;
|
||||
use SilverStripe\Security\Security;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Core\Convert;
|
||||
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
|
||||
*
|
||||
@ -22,6 +26,7 @@ use SilverStripe\Core\Extension;
|
||||
*/
|
||||
class LeftAndMainSubsites extends Extension
|
||||
{
|
||||
|
||||
private static $allowed_actions = array('CopyToSubsite');
|
||||
|
||||
/**
|
||||
@ -351,4 +356,5 @@ class LeftAndMainSubsites extends Extension
|
||||
$newPage->ID
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,9 +17,9 @@ use SilverStripe\Subsites\Model\Subsite;
|
||||
*/
|
||||
class SiteConfigSubsites extends DataExtension
|
||||
{
|
||||
private static $has_one = [
|
||||
'Subsite' => Subsite::class, // The subsite that this page belongs to
|
||||
];
|
||||
private static $has_one = [
|
||||
'Subsite' => Subsite::class, // The subsite that this page belongs to
|
||||
];
|
||||
|
||||
/**
|
||||
* Update any requests to limit the results to the current site
|
||||
@ -66,4 +66,5 @@ class SiteConfigSubsites extends DataExtension
|
||||
{
|
||||
$fields->push(new HiddenField('SubsiteID', 'SubsiteID', Subsite::currentSubsiteID()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,24 +5,24 @@ namespace SilverStripe\Subsites\Extensions;
|
||||
|
||||
use Page;
|
||||
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\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\HTTP;
|
||||
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\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\View\SSViewer;
|
||||
|
||||
|
||||
/**
|
||||
@ -30,6 +30,7 @@ use SilverStripe\Subsites\Model\Subsite;
|
||||
*/
|
||||
class SiteTreeSubsites extends DataExtension
|
||||
{
|
||||
|
||||
private static $has_one = [
|
||||
'Subsite' => Subsite::class, // The subsite that this page belongs to
|
||||
];
|
||||
@ -50,11 +51,11 @@ class SiteTreeSubsites extends DataExtension
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update any requests to limit the results to the current site
|
||||
* @param SQLSelect $query
|
||||
* @param DataQuery $dataQuery
|
||||
*/
|
||||
/**
|
||||
* Update any requests to limit the results to the current site
|
||||
* @param SQLSelect $query
|
||||
* @param DataQuery $dataQuery
|
||||
*/
|
||||
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null)
|
||||
{
|
||||
if (Subsite::$disable_subsite_filter) {
|
||||
@ -114,16 +115,16 @@ class SiteTreeSubsites extends DataExtension
|
||||
$fields->addFieldsToTab(
|
||||
'Root.Main',
|
||||
ToggleCompositeField::create('SubsiteOperations',
|
||||
_t('SiteTreeSubsites.SubsiteOperations', 'Subsite Operations'),
|
||||
array(
|
||||
new DropdownField("CopyToSubsiteID", _t('SiteTreeSubsites.CopyToSubsite', "Copy page to subsite"), $subsitesMap),
|
||||
new CheckboxField("CopyToSubsiteWithChildren", _t('SiteTreeSubsites.CopyToSubsiteWithChildren', 'Include children pages?')),
|
||||
$copyAction = new InlineFormAction(
|
||||
"copytosubsite",
|
||||
_t('SiteTreeSubsites.CopyAction', "Copy")
|
||||
)
|
||||
)
|
||||
)->setHeadingLevel(4)
|
||||
_t('SiteTreeSubsites.SubsiteOperations', 'Subsite Operations'),
|
||||
array(
|
||||
new DropdownField("CopyToSubsiteID", _t('SiteTreeSubsites.CopyToSubsite', "Copy page to subsite"), $subsitesMap),
|
||||
new CheckboxField("CopyToSubsiteWithChildren", _t('SiteTreeSubsites.CopyToSubsiteWithChildren', 'Include children pages?')),
|
||||
$copyAction = new InlineFormAction(
|
||||
"copytosubsite",
|
||||
_t('SiteTreeSubsites.CopyAction', "Copy")
|
||||
)
|
||||
)
|
||||
)->setHeadingLevel(4)
|
||||
);
|
||||
|
||||
|
||||
@ -276,10 +277,10 @@ class SiteTreeSubsites extends DataExtension
|
||||
Subsite::changeSubsite($oldSubsite);
|
||||
|
||||
if($includeChildren) {
|
||||
foreach($this->owner->AllChildren() as $child) {
|
||||
$child->duplicateToSubsite($subsiteID, $includeChildren, $page->ID);
|
||||
}
|
||||
}
|
||||
foreach($this->owner->AllChildren() as $child) {
|
||||
$child->duplicateToSubsite($subsiteID, $includeChildren, $page->ID);
|
||||
}
|
||||
}
|
||||
|
||||
return $page;
|
||||
}
|
||||
@ -420,4 +421,5 @@ class SiteTreeSubsites extends DataExtension
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,65 +2,11 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Forms;
|
||||
|
||||
|
||||
use SilverStripe\Forms\DropdownField;
|
||||
use SilverStripe\Forms\GridField\GridFieldDetailForm;
|
||||
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
|
||||
|
||||
class GridFieldSubsiteDetailForm extends GridFieldDetailForm
|
||||
{
|
||||
protected $itemRequestClass = GridFieldSubsiteDetailForm_ItemRequest::class;
|
||||
}
|
||||
|
||||
class GridFieldSubsiteDetailForm_ItemRequest extends GridFieldDetailForm_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);
|
||||
}
|
||||
|
||||
protected $itemRequestClass = 'GridFieldSubsiteDetailForm_ItemRequest';
|
||||
|
||||
}
|
||||
|
59
code/forms/GridFieldSubsiteDetailForm_ItemRequest.php
Normal file
59
code/forms/GridFieldSubsiteDetailForm_ItemRequest.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Forms;
|
||||
|
||||
use SilverStripe\Forms\TextField;
|
||||
|
||||
/**
|
||||
@ -7,6 +9,7 @@ use SilverStripe\Forms\TextField;
|
||||
*/
|
||||
class WildcardDomainField extends TextField
|
||||
{
|
||||
|
||||
/**
|
||||
* Validate this field as a valid hostname
|
||||
*
|
||||
@ -24,6 +27,7 @@ class WildcardDomainField extends TextField
|
||||
_t("DomainNameField.INVALID_DOMAIN", "Invalid domain name"),
|
||||
"validation"
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -42,4 +46,5 @@ class WildcardDomainField extends TextField
|
||||
{
|
||||
return 'text wildcarddomain';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Model;
|
||||
|
||||
|
||||
use SilverStripe\Admin\CMSMenu;
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Control\Director;
|
||||
@ -28,9 +27,9 @@ use SilverStripe\ORM\ArrayList;
|
||||
use SilverStripe\ORM\DataList;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\DB;
|
||||
use SilverStripe\Security\Group;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Security\Permission;
|
||||
use SilverStripe\Security\Group;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use UnexpectedValueException;
|
||||
|
||||
@ -106,7 +105,7 @@ class Subsite extends DataObject
|
||||
*/
|
||||
public static $check_is_public = true;
|
||||
|
||||
/*** @return array
|
||||
/*** @return array
|
||||
*/
|
||||
private static $summary_fields = [
|
||||
'Title',
|
||||
@ -115,39 +114,41 @@ class Subsite extends DataObject
|
||||
];
|
||||
|
||||
/**
|
||||
* Set allowed themes
|
||||
*
|
||||
* @param array $themes - Numeric array of all themes which are allowed to be selected for all subsites.
|
||||
*/
|
||||
public static function set_allowed_themes($themes)
|
||||
{self::$allowed_themes = $themes;
|
||||
}
|
||||
* Set allowed themes
|
||||
*
|
||||
* @param array $themes - Numeric array of all themes which are allowed to be selected for all subsites.
|
||||
*/
|
||||
public static function set_allowed_themes($themes)
|
||||
{
|
||||
self::$allowed_themes = $themes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the subsite currently set in the session.
|
||||
*
|
||||
* @uses ControllerSubsites->controllerAugmentInit()
|
||||
* @return Subsite
|
||||
*/
|
||||
public static function currentSubsite()
|
||||
{// get_by_id handles caching so we don't have to
|
||||
return DataObject::get_by_id(Subsite::class, self::currentSubsiteID());
|
||||
}
|
||||
/**
|
||||
* Gets the subsite currently set in the session.
|
||||
*
|
||||
* @uses ControllerSubsites->controllerAugmentInit()
|
||||
* @return Subsite
|
||||
*/
|
||||
public static function currentSubsite()
|
||||
{// get_by_id handles caching so we don't have to
|
||||
return DataObject::get_by_id(Subsite::class, self::currentSubsiteID());
|
||||
}
|
||||
|
||||
/**
|
||||
* This function gets the current subsite ID from the session. It used in the backend so Ajax requests
|
||||
* use the correct subsite. The frontend handles subsites differently. It calls getSubsiteIDForDomain
|
||||
* directly from ModelAsController::getNestedController. Only gets Subsite instances which have their
|
||||
* {@link IsPublic} flag set to TRUE.
|
||||
*
|
||||
* You can simulate subsite access without creating virtual hosts by appending ?SubsiteID=<ID> to the request.
|
||||
*
|
||||
* @todo Pass $request object from controller so we don't have to rely on $_GET
|
||||
*
|
||||
* @return int ID of the current subsite instance
|
||||
*/
|
||||
public static function currentSubsiteID()
|
||||
{$id = null;
|
||||
/**
|
||||
* This function gets the current subsite ID from the session. It used in the backend so Ajax requests
|
||||
* use the correct subsite. The frontend handles subsites differently. It calls getSubsiteIDForDomain
|
||||
* directly from ModelAsController::getNestedController. Only gets Subsite instances which have their
|
||||
* {@link IsPublic} flag set to TRUE.
|
||||
*
|
||||
* You can simulate subsite access without creating virtual hosts by appending ?SubsiteID=<ID> to the request.
|
||||
*
|
||||
* @todo Pass $request object from controller so we don't have to rely on $_GET
|
||||
*
|
||||
* @return int ID of the current subsite instance
|
||||
*/
|
||||
public static function currentSubsiteID()
|
||||
{
|
||||
$id = null;
|
||||
|
||||
if (isset($_GET['SubsiteID'])) {
|
||||
$id = (int)$_GET['SubsiteID'];
|
||||
@ -155,114 +156,126 @@ class Subsite extends DataObject
|
||||
$id = Session::get('SubsiteID');
|
||||
}
|
||||
|
||||
if($id === null) {
|
||||
$id = self::getSubsiteIDForDomain();
|
||||
}
|
||||
if ($id === null) {
|
||||
$id = self::getSubsiteIDForDomain();
|
||||
}
|
||||
|
||||
return (int)$id;
|
||||
}
|
||||
return (int)$id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Switch to another subsite through storing the subsite identifier in the current PHP session.
|
||||
* Only takes effect when {@link Subsite::$use_session_subsiteid} is set to TRUE.
|
||||
*
|
||||
* @param int|Subsite $subsite Either the ID of the subsite, or the subsite object itself
|
||||
*/
|
||||
public static function changeSubsite($subsite) {
|
||||
// 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.
|
||||
if (!Subsite::$use_session_subsiteid) return;
|
||||
/**
|
||||
* Switch to another subsite through storing the subsite identifier in the current PHP session.
|
||||
* Only takes effect when {@link Subsite::$use_session_subsiteid} is set to TRUE.
|
||||
*
|
||||
* @param int|Subsite $subsite Either the ID of the subsite, or the subsite object itself
|
||||
*/
|
||||
public static function changeSubsite($subsite)
|
||||
{
|
||||
// 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.
|
||||
if (!Subsite::$use_session_subsiteid) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(is_object($subsite)) $subsiteID = $subsite->ID;
|
||||
else $subsiteID = $subsite;
|
||||
if (is_object($subsite)) {
|
||||
$subsiteID = $subsite->ID;
|
||||
} else {
|
||||
$subsiteID = $subsite;
|
||||
}
|
||||
|
||||
Session::set('SubsiteID', (int)$subsiteID);
|
||||
Session::set('SubsiteID', (int)$subsiteID);
|
||||
|
||||
// Set locale
|
||||
if (is_object($subsite) && $subsite->Language != '') {
|
||||
$locale = i18n::get_locale_from_lang($subsite->Language);
|
||||
if($locale) {
|
||||
i18n::set_locale($locale);
|
||||
}
|
||||
}
|
||||
// Set locale
|
||||
if (is_object($subsite) && $subsite->Language != '') {
|
||||
$locale = i18n::get_locale_from_lang($subsite->Language);
|
||||
if ($locale) {
|
||||
i18n::set_locale($locale);
|
||||
}
|
||||
}
|
||||
|
||||
Permission::flush_permission_cache();
|
||||
}
|
||||
Permission::flush_permission_cache();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a matching subsite for the given host, or for the current HTTP_HOST.
|
||||
* Supports "fuzzy" matching of domains by placing an asterisk at the start of end of the string,
|
||||
* for example matching all subdomains on *.example.com with one subsite,
|
||||
* and all subdomains on *.example.org on another.
|
||||
*
|
||||
* @param $host The host to find the subsite for. If not specified, $_SERVER['HTTP_HOST'] is used.
|
||||
* @return int Subsite ID
|
||||
*/
|
||||
public static function getSubsiteIDForDomain($host = null, $checkPermissions = true) {
|
||||
if($host == null && isset($_SERVER['HTTP_HOST'])) {
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
}
|
||||
/**
|
||||
* Get a matching subsite for the given host, or for the current HTTP_HOST.
|
||||
* Supports "fuzzy" matching of domains by placing an asterisk at the start of end of the string,
|
||||
* for example matching all subdomains on *.example.com with one subsite,
|
||||
* and all subdomains on *.example.org on another.
|
||||
*
|
||||
* @param $host The host to find the subsite for. If not specified, $_SERVER['HTTP_HOST'] is used.
|
||||
* @return int Subsite ID
|
||||
*/
|
||||
public static function getSubsiteIDForDomain($host = null, $checkPermissions = true)
|
||||
{
|
||||
if ($host == null && isset($_SERVER['HTTP_HOST'])) {
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
}
|
||||
|
||||
$matchingDomains = null;
|
||||
$cacheKey = null;
|
||||
if ($host) {
|
||||
if(!self::$strict_subdomain_matching) $host = preg_replace('/^www\./', '', $host);
|
||||
$matchingDomains = null;
|
||||
$cacheKey = null;
|
||||
if ($host) {
|
||||
if (!self::$strict_subdomain_matching) {
|
||||
$host = preg_replace('/^www\./', '', $host);
|
||||
}
|
||||
|
||||
$cacheKey = implode('_', [$host, Member::currentUserID(), self::$check_is_public]);
|
||||
if (isset(self::$_cache_subsite_for_domain[$cacheKey])) {
|
||||
return self::$_cache_subsite_for_domain[$cacheKey];
|
||||
}
|
||||
|
||||
$SQL_host = Convert::raw2sql($host);
|
||||
$matchingDomains = DataObject::get(
|
||||
SubsiteDomain::class,
|
||||
"'$SQL_host' LIKE replace(\"SubsiteDomain\".\"Domain\",'*','%')",
|
||||
"\"IsPrimary\" DESC"
|
||||
)->innerJoin('Subsite', "\"Subsite\".\"ID\" = \"SubsiteDomain\".\"SubsiteID\" AND \"Subsite\".\"IsPublic\"=1");
|
||||
}
|
||||
$SQL_host = Convert::raw2sql($host);
|
||||
$matchingDomains = DataObject::get(
|
||||
SubsiteDomain::class,
|
||||
"'$SQL_host' LIKE replace(\"SubsiteDomain\".\"Domain\",'*','%')",
|
||||
"\"IsPrimary\" DESC"
|
||||
)->innerJoin('Subsite',
|
||||
"\"Subsite\".\"ID\" = \"SubsiteDomain\".\"SubsiteID\" AND \"Subsite\".\"IsPublic\"=1");
|
||||
}
|
||||
|
||||
if($matchingDomains && $matchingDomains->Count()) {
|
||||
$subsiteIDs = array_unique($matchingDomains->column('SubsiteID'));
|
||||
$subsiteDomains = array_unique($matchingDomains->column('Domain'));
|
||||
if(sizeof($subsiteIDs) > 1) {
|
||||
throw new UnexpectedValueException(sprintf(
|
||||
"Multiple subsites match on '%s': %s",
|
||||
$host,
|
||||
implode(',', $subsiteDomains)
|
||||
));
|
||||
}
|
||||
if ($matchingDomains && $matchingDomains->Count()) {
|
||||
$subsiteIDs = array_unique($matchingDomains->column('SubsiteID'));
|
||||
$subsiteDomains = array_unique($matchingDomains->column('Domain'));
|
||||
if (sizeof($subsiteIDs) > 1) {
|
||||
throw new UnexpectedValueException(sprintf(
|
||||
"Multiple subsites match on '%s': %s",
|
||||
$host,
|
||||
implode(',', $subsiteDomains)
|
||||
));
|
||||
}
|
||||
|
||||
$subsiteID = $subsiteIDs[0];
|
||||
} else {
|
||||
if($default = DataObject::get_one(Subsite::class, "\"DefaultSite\" = 1")) {
|
||||
// Check for a 'default' subsite
|
||||
$subsiteID = $default->ID;
|
||||
} else {
|
||||
// Default subsite id = 0, the main site
|
||||
$subsiteID = 0;
|
||||
}}
|
||||
$subsiteID = $subsiteIDs[0];
|
||||
} else {
|
||||
if ($default = DataObject::get_one(Subsite::class, "\"DefaultSite\" = 1")) {
|
||||
// Check for a 'default' subsite
|
||||
$subsiteID = $default->ID;
|
||||
} else {
|
||||
// Default subsite id = 0, the main site
|
||||
$subsiteID = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if ($cacheKey) {
|
||||
self::$_cache_subsite_for_domain[$cacheKey] = $subsiteID;
|
||||
}
|
||||
if ($cacheKey) {
|
||||
self::$_cache_subsite_for_domain[$cacheKey] = $subsiteID;
|
||||
}
|
||||
|
||||
return $subsiteID;
|
||||
}
|
||||
return $subsiteID;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $className
|
||||
* @param string $filter
|
||||
* @param string $sort
|
||||
* @param string $join
|
||||
* @param string $limit
|
||||
* @return DataList
|
||||
*/
|
||||
public static function get_from_all_subsites($className, $filter = "", $sort = "", $join = "", $limit = "") {
|
||||
$result = DataObject::get($className, $filter, $sort, $join, $limit);
|
||||
$result = $result->setDataQueryParam('Subsite.filter', false);
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @param string $className
|
||||
* @param string $filter
|
||||
* @param string $sort
|
||||
* @param string $join
|
||||
* @param string $limit
|
||||
* @return DataList
|
||||
*/
|
||||
public static function get_from_all_subsites($className, $filter = "", $sort = "", $join = "", $limit = "")
|
||||
{
|
||||
$result = DataObject::get($className, $filter, $sort, $join, $limit);
|
||||
$result = $result->setDataQueryParam('Subsite.filter', false);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the sub-site filtering; queries will select from all subsites
|
||||
@ -290,18 +303,18 @@ class Subsite extends DataObject
|
||||
{
|
||||
$subsites = Subsite::get();
|
||||
|
||||
if($includeMainSite) {
|
||||
$subsites = $subsites->toArray();
|
||||
if ($includeMainSite) {
|
||||
$subsites = $subsites->toArray();
|
||||
|
||||
$mainSite = new Subsite();
|
||||
$mainSite->Title = $mainSiteTitle;
|
||||
array_unshift($subsites, $mainSite);
|
||||
$mainSite = new Subsite();
|
||||
$mainSite->Title = $mainSiteTitle;
|
||||
array_unshift($subsites, $mainSite);
|
||||
|
||||
$subsites = ArrayList::create($subsites);
|
||||
}
|
||||
$subsites = ArrayList::create($subsites);
|
||||
}
|
||||
|
||||
return $subsites;
|
||||
}
|
||||
return $subsites;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns an ArrayList of the subsites accessible to the current user.
|
||||
@ -322,27 +335,27 @@ class Subsite extends DataObject
|
||||
$member = DataObject::get_by_id(Member::class, $member);
|
||||
}
|
||||
|
||||
$subsites = new ArrayList();
|
||||
$subsites = new ArrayList();
|
||||
|
||||
// Collect subsites for all sections.
|
||||
$menu = CMSMenu::get_viewable_menu_items();
|
||||
foreach($menu as $candidate) {
|
||||
if ($candidate->controller) {
|
||||
$accessibleSites = singleton($candidate->controller)->sectionSites(
|
||||
$includeMainSite,
|
||||
$mainSiteTitle,
|
||||
$member
|
||||
);
|
||||
// Collect subsites for all sections.
|
||||
$menu = CMSMenu::get_viewable_menu_items();
|
||||
foreach ($menu as $candidate) {
|
||||
if ($candidate->controller) {
|
||||
$accessibleSites = singleton($candidate->controller)->sectionSites(
|
||||
$includeMainSite,
|
||||
$mainSiteTitle,
|
||||
$member
|
||||
);
|
||||
|
||||
// Replace existing keys so no one site appears twice.
|
||||
$subsites->merge($accessibleSites);
|
||||
}
|
||||
}
|
||||
// Replace existing keys so no one site appears twice.
|
||||
$subsites->merge($accessibleSites);
|
||||
}
|
||||
}
|
||||
|
||||
$subsites->removeDuplicates();
|
||||
$subsites->removeDuplicates();
|
||||
|
||||
return $subsites;
|
||||
}
|
||||
return $subsites;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the subsites that the current user can access by given permission.
|
||||
@ -354,7 +367,12 @@ class Subsite extends DataObject
|
||||
* @param $member
|
||||
* @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
|
||||
if (!$member) {
|
||||
@ -367,15 +385,18 @@ class Subsite extends DataObject
|
||||
$member = DataObject::get_by_id(Member::class, $member);
|
||||
}
|
||||
|
||||
// Rationalise permCode argument
|
||||
if(is_array($permCode)) $SQL_codes = "'" . implode("', '", Convert::raw2sql($permCode)) . "'";
|
||||
else $SQL_codes = "'" . Convert::raw2sql($permCode) . "'";
|
||||
// Rationalise permCode argument
|
||||
if (is_array($permCode)) {
|
||||
$SQL_codes = "'" . implode("', '", Convert::raw2sql($permCode)) . "'";
|
||||
} else {
|
||||
$SQL_codes = "'" . Convert::raw2sql($permCode) . "'";
|
||||
}
|
||||
|
||||
// Cache handling
|
||||
$cacheKey = $SQL_codes . '-' . $member->ID . '-' . $includeMainSite . '-' . $mainSiteTitle;
|
||||
if(isset(self::$_cache_accessible_sites[$cacheKey])) {
|
||||
return self::$_cache_accessible_sites[$cacheKey];
|
||||
}
|
||||
// Cache handling
|
||||
$cacheKey = $SQL_codes . '-' . $member->ID . '-' . $includeMainSite . '-' . $mainSiteTitle;
|
||||
if (isset(self::$_cache_accessible_sites[$cacheKey])) {
|
||||
return self::$_cache_accessible_sites[$cacheKey];
|
||||
}
|
||||
|
||||
$subsites = DataList::create(Subsite::class)
|
||||
->where("\"Subsite\".\"Title\" != ''")
|
||||
@ -387,8 +408,11 @@ class Subsite extends DataObject
|
||||
->innerJoin('Permission',
|
||||
"\"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)
|
||||
->where("\"Subsite\".\"Title\" != ''")
|
||||
->leftJoin('Group_Subsites', "\"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"")
|
||||
@ -401,15 +425,19 @@ class Subsite extends DataObject
|
||||
->innerJoin('PermissionRoleCode',
|
||||
"\"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(!$subsites->find('ID', $subsite->ID)) {
|
||||
$subsites->push($subsite);
|
||||
}
|
||||
}
|
||||
if ($rolesSubsites) {
|
||||
foreach ($rolesSubsites as $subsite) {
|
||||
if (!$subsites->find('ID', $subsite->ID)) {
|
||||
$subsites->push($subsite);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($includeMainSite) {
|
||||
if (!is_array($permCode)) {
|
||||
@ -501,43 +529,46 @@ class Subsite extends DataObject
|
||||
$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);
|
||||
$SQL_perms = join("','", $SQLa_perm);
|
||||
$memberID = (int)$member->ID;
|
||||
$SQLa_perm = Convert::raw2sql($permissionCodes);
|
||||
$SQL_perms = join("','", $SQLa_perm);
|
||||
$memberID = (int)$member->ID;
|
||||
|
||||
// Count this user's groups which can access the main site
|
||||
$groupCount = DB::query("
|
||||
SELECT COUNT(\"Permission\".\"ID\")
|
||||
FROM \"Permission\"
|
||||
INNER JOIN \"Group\" ON \"Group\".\"ID\" = \"Permission\".\"GroupID\" AND \"Group\".\"AccessAllSubsites\" = 1
|
||||
INNER JOIN \"Group_Members\" ON \"Group_Members\".\"GroupID\" = \"Permission\".\"GroupID\"
|
||||
WHERE \"Permission\".\"Code\" IN ('$SQL_perms')
|
||||
AND \"MemberID\" = {$memberID}
|
||||
")->value();
|
||||
// Count this user's groups which can access the main site
|
||||
$groupCount = DB::query("
|
||||
SELECT COUNT(\"Permission\".\"ID\")
|
||||
FROM \"Permission\"
|
||||
INNER JOIN \"Group\" ON \"Group\".\"ID\" = \"Permission\".\"GroupID\" AND \"Group\".\"AccessAllSubsites\" = 1
|
||||
INNER JOIN \"Group_Members\" ON \"Group_Members\".\"GroupID\" = \"Permission\".\"GroupID\"
|
||||
WHERE \"Permission\".\"Code\" IN ('$SQL_perms')
|
||||
AND \"MemberID\" = {$memberID}
|
||||
")->value();
|
||||
|
||||
// Count this user's groups which have a role that can access the main site
|
||||
$roleCount = DB::query("
|
||||
SELECT COUNT(\"PermissionRoleCode\".\"ID\")
|
||||
FROM \"Group\"
|
||||
INNER JOIN \"Group_Members\" ON \"Group_Members\".\"GroupID\" = \"Group\".\"ID\"
|
||||
INNER JOIN \"Group_Roles\" ON \"Group_Roles\".\"GroupID\"=\"Group\".\"ID\"
|
||||
INNER JOIN \"PermissionRole\" ON \"Group_Roles\".\"PermissionRoleID\"=\"PermissionRole\".\"ID\"
|
||||
INNER JOIN \"PermissionRoleCode\" ON \"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\"
|
||||
WHERE \"PermissionRoleCode\".\"Code\" IN ('$SQL_perms')
|
||||
AND \"Group\".\"AccessAllSubsites\" = 1
|
||||
AND \"MemberID\" = {$memberID}
|
||||
")->value();
|
||||
// Count this user's groups which have a role that can access the main site
|
||||
$roleCount = DB::query("
|
||||
SELECT COUNT(\"PermissionRoleCode\".\"ID\")
|
||||
FROM \"Group\"
|
||||
INNER JOIN \"Group_Members\" ON \"Group_Members\".\"GroupID\" = \"Group\".\"ID\"
|
||||
INNER JOIN \"Group_Roles\" ON \"Group_Roles\".\"GroupID\"=\"Group\".\"ID\"
|
||||
INNER JOIN \"PermissionRole\" ON \"Group_Roles\".\"PermissionRoleID\"=\"PermissionRole\".\"ID\"
|
||||
INNER JOIN \"PermissionRoleCode\" ON \"PermissionRole\".\"ID\"=\"PermissionRoleCode\".\"RoleID\"
|
||||
WHERE \"PermissionRoleCode\".\"Code\" IN ('$SQL_perms')
|
||||
AND \"Group\".\"AccessAllSubsites\" = 1
|
||||
AND \"MemberID\" = {$memberID}
|
||||
")->value();
|
||||
|
||||
// There has to be at least one that allows access.
|
||||
return ($groupCount + $roleCount > 0);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $db = [
|
||||
@ -547,16 +578,15 @@ class Subsite extends DataObject
|
||||
'Theme' => 'Varchar',
|
||||
'Language' => 'Varchar(6)',
|
||||
|
||||
// Used to hide unfinished/private subsites from public view.
|
||||
// If unset, will default to true
|
||||
'IsPublic' => 'Boolean',
|
||||
// Used to hide unfinished/private subsites from public view.
|
||||
// If unset, will default to true
|
||||
'IsPublic' => 'Boolean',
|
||||
|
||||
// Comma-separated list of disallowed page types
|
||||
'PageTypeBlacklist' => 'Text',
|
||||
];
|
||||
// Comma-separated list of disallowed page types
|
||||
'PageTypeBlacklist' => 'Text',
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $has_many = [
|
||||
@ -564,44 +594,41 @@ class Subsite extends DataObject
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $belongs_many_many = [
|
||||
"Groups" => Group::class,
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $defaults = [
|
||||
'IsPublic' => 1
|
||||
];
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $defaults = [
|
||||
'IsPublic' => 1
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $searchable_fields = [
|
||||
'Title',
|
||||
'Domains.Domain',
|
||||
'IsPublic',
|
||||
];
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private static $searchable_fields = [
|
||||
'Title',
|
||||
'Domains.Domain',
|
||||
'IsPublic',
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $default_sort = "\"Title\" ASC";
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private static $default_sort = "\"Title\" ASC";
|
||||
|
||||
/**
|
||||
* @todo Possible security issue, don't grant edit permissions to everybody.
|
||||
* @return boolean
|
||||
*/
|
||||
public function canEdit($member = false)
|
||||
{return true;
|
||||
}
|
||||
/**
|
||||
* @todo Possible security issue, don't grant edit permissions to everybody.
|
||||
* @return boolean
|
||||
*/
|
||||
public function canEdit($member = false)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the configuration fields for each subsite
|
||||
@ -610,7 +637,7 @@ class Subsite extends DataObject
|
||||
*/
|
||||
public function getCMSFields()
|
||||
{
|
||||
if ($this->ID!=0) {
|
||||
if ($this->ID != 0) {
|
||||
$domainTable = new GridField(
|
||||
"Domains",
|
||||
_t('Subsite.DomainsListTitle', "Domains"),
|
||||
@ -620,7 +647,8 @@ class Subsite extends DataObject
|
||||
} else {
|
||||
$domainTable = new LiteralField(
|
||||
'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()
|
||||
);
|
||||
|
||||
$pageTypeMap = array();
|
||||
$pageTypeMap = [];
|
||||
$pageTypes = SiteTree::page_type_classes();
|
||||
foreach ($pageTypes as $pageType) {
|
||||
$pageTypeMap[$pageType] = singleton($pageType)->i18n_singular_name();
|
||||
@ -655,98 +683,103 @@ class Subsite extends DataObject
|
||||
new CheckboxField('DefaultSite', $this->fieldLabel('DefaultSite'), $this->DefaultSite),
|
||||
new CheckboxField('IsPublic', $this->fieldLabel('IsPublic'), $this->IsPublic),
|
||||
|
||||
new DropdownField('Theme',$this->fieldLabel('Theme'), $this->allowedThemes(), $this->Theme),
|
||||
new DropdownField('Theme', $this->fieldLabel('Theme'), $this->allowedThemes(), $this->Theme),
|
||||
|
||||
|
||||
new LiteralField(
|
||||
'PageTypeBlacklistToggle',
|
||||
sprintf(
|
||||
'<div class="field"><a href="#" id="PageTypeBlacklistToggle">%s</a></div>',
|
||||
_t('Subsite.PageTypeBlacklistField', 'Disallow page types?')
|
||||
)
|
||||
),
|
||||
new CheckboxSetField(
|
||||
'PageTypeBlacklist',
|
||||
false,
|
||||
$pageTypeMap
|
||||
)
|
||||
)
|
||||
),
|
||||
new HiddenField('ID', '', $this->ID),
|
||||
new HiddenField('IsSubsite', '', 1)
|
||||
);
|
||||
new LiteralField(
|
||||
'PageTypeBlacklistToggle',
|
||||
sprintf(
|
||||
'<div class="field"><a href="#" id="PageTypeBlacklistToggle">%s</a></div>',
|
||||
_t('Subsite.PageTypeBlacklistField', 'Disallow page types?')
|
||||
)
|
||||
),
|
||||
new CheckboxSetField(
|
||||
'PageTypeBlacklist',
|
||||
false,
|
||||
$pageTypeMap
|
||||
)
|
||||
)
|
||||
),
|
||||
new HiddenField('ID', '', $this->ID),
|
||||
new HiddenField('IsSubsite', '', 1)
|
||||
);
|
||||
|
||||
$subsiteTabs->addExtraClass('subsite-model');
|
||||
$subsiteTabs->addExtraClass('subsite-model');
|
||||
|
||||
$this->extend('updateCMSFields', $fields);
|
||||
return $fields;
|
||||
}
|
||||
$this->extend('updateCMSFields', $fields);
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param boolean $includerelations
|
||||
* @return array
|
||||
*/
|
||||
public function fieldLabels($includerelations = true) {
|
||||
$labels = parent::fieldLabels($includerelations);
|
||||
$labels['Title'] = _t('Subsites.TitleFieldLabel', 'Subsite Name');
|
||||
$labels['RedirectURL'] = _t('Subsites.RedirectURLFieldLabel', 'Redirect URL');
|
||||
$labels['DefaultSite'] = _t('Subsites.DefaultSiteFieldLabel', 'Default site');
|
||||
$labels['Theme'] = _t('Subsites.ThemeFieldLabel', 'Theme');
|
||||
$labels['Language'] = _t('Subsites.LanguageFieldLabel', 'Language');
|
||||
$labels['IsPublic'] = _t('Subsites.IsPublicFieldLabel', 'Enable public access');
|
||||
$labels['PageTypeBlacklist'] = _t('Subsites.PageTypeBlacklistFieldLabel', 'Page Type Blacklist');
|
||||
$labels['Domains.Domain'] = _t('Subsites.DomainFieldLabel', 'Domain');
|
||||
$labels['PrimaryDomain'] = _t('Subsites.PrimaryDomainFieldLabel', 'Primary Domain');
|
||||
/**
|
||||
*
|
||||
* @param boolean $includerelations
|
||||
* @return array
|
||||
*/
|
||||
public function fieldLabels($includerelations = true)
|
||||
{
|
||||
$labels = parent::fieldLabels($includerelations);
|
||||
$labels['Title'] = _t('Subsites.TitleFieldLabel', 'Subsite Name');
|
||||
$labels['RedirectURL'] = _t('Subsites.RedirectURLFieldLabel', 'Redirect URL');
|
||||
$labels['DefaultSite'] = _t('Subsites.DefaultSiteFieldLabel', 'Default site');
|
||||
$labels['Theme'] = _t('Subsites.ThemeFieldLabel', 'Theme');
|
||||
$labels['Language'] = _t('Subsites.LanguageFieldLabel', 'Language');
|
||||
$labels['IsPublic'] = _t('Subsites.IsPublicFieldLabel', 'Enable public access');
|
||||
$labels['PageTypeBlacklist'] = _t('Subsites.PageTypeBlacklistFieldLabel', 'Page Type Blacklist');
|
||||
$labels['Domains.Domain'] = _t('Subsites.DomainFieldLabel', 'Domain');
|
||||
$labels['PrimaryDomain'] = _t('Subsites.PrimaryDomainFieldLabel', 'Primary Domain');
|
||||
|
||||
return $labels;
|
||||
}
|
||||
return $labels;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Return the themes that can be used with this subsite, as an array of themecode => description
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function allowedThemes()
|
||||
{
|
||||
if ($themes = $this->stat('allowed_themes')) {
|
||||
return ArrayLib::valuekey($themes);
|
||||
} else {
|
||||
$themes = [];
|
||||
if (is_dir(THEMES_PATH)) {
|
||||
foreach (scandir(THEMES_PATH) as $theme) {
|
||||
if ($theme[0] == '.') {
|
||||
continue;
|
||||
}
|
||||
$theme = strtok($theme, '_');
|
||||
$themes[$theme] = $theme;
|
||||
}
|
||||
ksort($themes);
|
||||
}
|
||||
return $themes;
|
||||
}
|
||||
}
|
||||
|
||||
* Return the themes that can be used with this subsite, as an array of themecode => description
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function allowedThemes()
|
||||
{if($themes = $this->stat('allowed_themes')) {
|
||||
return ArrayLib::valuekey($themes);
|
||||
} else {
|
||||
$themes = [];
|
||||
if(is_dir(THEMES_PATH)) {
|
||||
foreach(scandir(THEMES_PATH) as $theme) {
|
||||
if($theme[0] == '.') {continue;}
|
||||
$theme = strtok($theme,'_');
|
||||
$themes[$theme] = $theme;
|
||||
}
|
||||
ksort($themes);
|
||||
}
|
||||
return $themes;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @return string Current locale of the subsite
|
||||
*/
|
||||
public function getLanguage()
|
||||
{
|
||||
if ($this->getField('Language')) {
|
||||
return $this->getField('Language');
|
||||
} else {
|
||||
return i18n::get_locale();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string Current locale of the subsite
|
||||
*/
|
||||
public function getLanguage() {
|
||||
if($this->getField('Language')) {
|
||||
return $this->getField('Language');
|
||||
} else {
|
||||
return i18n::get_locale();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return ValidationResult
|
||||
*/
|
||||
public function validate() {
|
||||
$result = parent::validate();
|
||||
if(!$this->Title) {
|
||||
$result->error(_t('Subsite.ValidateTitle', 'Please add a "Title"'));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @return ValidationResult
|
||||
*/
|
||||
public function validate()
|
||||
{
|
||||
$result = parent::validate();
|
||||
if (!$this->Title) {
|
||||
$result->error(_t('Subsite.ValidateTitle', 'Please add a "Title"'));
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whenever a Subsite is written, rewrite the hostmap
|
||||
@ -815,38 +848,41 @@ class Subsite extends DataObject
|
||||
return Director::absoluteBaseURL();
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo getClassName is redundant, already stored as a database field?
|
||||
*/
|
||||
public function getClassName() {
|
||||
return $this->class;
|
||||
}
|
||||
/**
|
||||
* @todo getClassName is redundant, already stored as a database field?
|
||||
*/
|
||||
public function getClassName()
|
||||
{
|
||||
return $this->class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Javascript admin action to duplicate this subsite
|
||||
*
|
||||
* @return string - javascript
|
||||
*/
|
||||
public function adminDuplicate()
|
||||
{$newItem = $this->duplicate();
|
||||
$message = _t(
|
||||
'Subsite.CopyMessage',
|
||||
'Created a copy of {title}',
|
||||
['title' => Convert::raw2js($this->Title)]
|
||||
);
|
||||
/**
|
||||
* Javascript admin action to duplicate this subsite
|
||||
*
|
||||
* @return string - javascript
|
||||
*/
|
||||
public function adminDuplicate()
|
||||
{
|
||||
$newItem = $this->duplicate();
|
||||
$message = _t(
|
||||
'Subsite.CopyMessage',
|
||||
'Created a copy of {title}',
|
||||
['title' => Convert::raw2js($this->Title)]
|
||||
);
|
||||
|
||||
return <<<JS
|
||||
statusMessage($message, 'good');
|
||||
$('Form_EditForm').loadURLFromServer('admin/subsites/show/$newItem->ID');
|
||||
return <<<JS
|
||||
statusMessage($message, 'good');
|
||||
$('Form_EditForm').loadURLFromServer('admin/subsites/show/$newItem->ID');
|
||||
JS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make this subsite the current one
|
||||
*/
|
||||
public function activate() {
|
||||
Subsite::changeSubsite($this);
|
||||
}
|
||||
/**
|
||||
* Make this subsite the current one
|
||||
*/
|
||||
public function activate()
|
||||
{
|
||||
Subsite::changeSubsite($this);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@ -860,26 +896,27 @@ JS;
|
||||
}
|
||||
$SQL_permissionCodes = Convert::raw2sql($permissionCodes);
|
||||
|
||||
$SQL_permissionCodes = join("','", $SQL_permissionCodes);
|
||||
$SQL_permissionCodes = join("','", $SQL_permissionCodes);
|
||||
|
||||
return DataObject::get(
|
||||
Member::class,
|
||||
"\"Group\".\"SubsiteID\" = $this->ID AND \"Permission\".\"Code\" IN ('$SQL_permissionCodes')",
|
||||
'',
|
||||
"LEFT JOIN \"Group_Members\" ON \"Member\".\"ID\" = \"Group_Members\".\"MemberID\"
|
||||
LEFT JOIN \"Group\" ON \"Group\".\"ID\" = \"Group_Members\".\"GroupID\"
|
||||
LEFT JOIN \"Permission\" ON \"Permission\".\"GroupID\" = \"Group\".\"ID\""
|
||||
);
|
||||
}
|
||||
LEFT JOIN \"Group\" ON \"Group\".\"ID\" = \"Group_Members\".\"GroupID\"
|
||||
LEFT JOIN \"Permission\" ON \"Permission\".\"GroupID\" = \"Group\".\"ID\""
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Duplicate this subsite
|
||||
*/
|
||||
public function duplicate($doWrite = true) {
|
||||
$duplicate = parent::duplicate($doWrite);
|
||||
/**
|
||||
* Duplicate this subsite
|
||||
*/
|
||||
public function duplicate($doWrite = true)
|
||||
{
|
||||
$duplicate = parent::duplicate($doWrite);
|
||||
|
||||
$oldSubsiteID = Session::get('SubsiteID');
|
||||
self::changeSubsite($this->ID);
|
||||
$oldSubsiteID = Session::get('SubsiteID');
|
||||
self::changeSubsite($this->ID);
|
||||
|
||||
/*
|
||||
* Copy data from this object to the given subsite. Does this using an iterative depth-first search.
|
||||
@ -892,24 +929,24 @@ JS;
|
||||
list($sourceParentID, $destParentID) = array_pop($stack);
|
||||
$children = Versioned::get_by_stage('Page', 'Live', "\"ParentID\" = $sourceParentID", '');
|
||||
|
||||
if($children) {
|
||||
foreach($children as $child) {
|
||||
self::changeSubsite($duplicate->ID); //Change to destination subsite
|
||||
if ($children) {
|
||||
foreach ($children as $child) {
|
||||
self::changeSubsite($duplicate->ID); //Change to destination subsite
|
||||
|
||||
$childClone = $child->duplicateToSubsite($duplicate, false);
|
||||
$childClone->ParentID = $destParentID;
|
||||
$childClone->writeToStage('Stage');
|
||||
$childClone->publish('Stage', 'Live');
|
||||
$childClone = $child->duplicateToSubsite($duplicate, false);
|
||||
$childClone->ParentID = $destParentID;
|
||||
$childClone->writeToStage('Stage');
|
||||
$childClone->publish('Stage', 'Live');
|
||||
|
||||
self::changeSubsite($this->ID); //Change Back to this subsite
|
||||
self::changeSubsite($this->ID); //Change Back to this subsite
|
||||
|
||||
array_push($stack, [$child->ID, $childClone->ID]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
self::changeSubsite($oldSubsiteID);
|
||||
self::changeSubsite($oldSubsiteID);
|
||||
|
||||
return $duplicate;
|
||||
}
|
||||
return $duplicate;
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,13 @@
|
||||
|
||||
namespace SilverStripe\Subsites\Model;
|
||||
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Control\Controller;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Forms\CheckboxField;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Forms\OptionsetField;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Subsites\Forms\WildcardDomainField;
|
||||
|
||||
|
||||
/**
|
||||
@ -21,7 +22,7 @@ use SilverStripe\ORM\DataObject;
|
||||
class SubsiteDomain extends DataObject
|
||||
{
|
||||
|
||||
private static $table_name = 'SubsiteDomain';
|
||||
private static $table_name = 'SubsiteDomain';
|
||||
|
||||
/**
|
||||
*
|
||||
@ -30,15 +31,16 @@ class SubsiteDomain extends DataObject
|
||||
private static $default_sort = "\"IsPrimary\" DESC";
|
||||
|
||||
/** *
|
||||
* @var array
|
||||
*/
|
||||
private static $db = [
|
||||
"Domain" => "Varchar(255)",
|
||||
"Protocol" => "Enum('http,https,automatic','automatic')",
|
||||
* @var array
|
||||
*/
|
||||
private static $db = [
|
||||
"Domain" => "Varchar(255)",
|
||||
"Protocol" => "Enum('http,https,automatic','automatic')",
|
||||
"IsPrimary" => "Boolean",
|
||||
];
|
||||
];
|
||||
|
||||
/*** Specifies that this subsite is http only
|
||||
/**
|
||||
* Specifies that this subsite is http only
|
||||
*/
|
||||
const PROTOCOL_HTTP = 'http';
|
||||
|
||||
@ -63,53 +65,55 @@ class SubsiteDomain extends DataObject
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $has_one = [
|
||||
"Subsite" => Subsite::class,
|
||||
];
|
||||
|
||||
/**
|
||||
*@config
|
||||
* @var array
|
||||
*/
|
||||
private static $summary_fields=[
|
||||
'Domain',
|
||||
'IsPrimary',
|
||||
];
|
||||
|
||||
/*** @config
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private static $casting = array(
|
||||
private static $has_one = [
|
||||
"Subsite" => Subsite::class,
|
||||
];
|
||||
|
||||
/**
|
||||
* @config
|
||||
* @var array
|
||||
*/
|
||||
private static $summary_fields = [
|
||||
'Domain',
|
||||
'IsPrimary',
|
||||
];
|
||||
|
||||
/*** @config
|
||||
* @var array
|
||||
*/
|
||||
private static $casting = [
|
||||
'SubstitutedDomain' => 'Varchar',
|
||||
'FullProtocol' => 'Varchar',
|
||||
'AbsoluteLink' => 'Varchar',
|
||||
);
|
||||
];
|
||||
|
||||
/**
|
||||
* Whenever a Subsite Domain is written, rewrite the hostmap
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterWrite()
|
||||
{Subsite::writeHostMap();
|
||||
}
|
||||
* Whenever a Subsite Domain is written, rewrite the hostmap
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function onAfterWrite()
|
||||
{
|
||||
Subsite::writeHostMap();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return \FieldList
|
||||
*/
|
||||
public function getCMSFields()
|
||||
{
|
||||
$protocols = array(
|
||||
/**
|
||||
*
|
||||
* @return \FieldList
|
||||
*/
|
||||
public function getCMSFields()
|
||||
{
|
||||
$protocols = [
|
||||
self::PROTOCOL_HTTP => _t('SubsiteDomain.PROTOCOL_HTTP', 'http://'),
|
||||
self::PROTOCOL_HTTPS => _t('SubsiteDomain.PROTOCOL_HTTPS', 'https://'),
|
||||
self::PROTOCOL_AUTOMATIC => _t('SubsiteDomain.PROTOCOL_AUTOMATIC', 'Automatic')
|
||||
);$fields = new FieldList(
|
||||
WildcardDomainField::create('Domain', $this->fieldLabel('Domain'), null, 255)
|
||||
->setDescription(_t(
|
||||
];
|
||||
$fields = new FieldList(
|
||||
WildcardDomainField::create('Domain', $this->fieldLabel('Domain'), null, 255)
|
||||
->setDescription(_t(
|
||||
'SubsiteDomain.DOMAIN_DESCRIPTION',
|
||||
'Hostname of this subsite (exclude protocol). Allows wildcards (*).'
|
||||
)),
|
||||
@ -119,10 +123,10 @@ class SubsiteDomain extends DataObject
|
||||
'When generating links to this subsite, use the selected protocol. <br />' .
|
||||
'Selecting \'Automatic\' means subsite links will default to the current protocol.'
|
||||
)), CheckboxField::create('IsPrimary', $this->fieldLabel('IsPrimary'))
|
||||
->setDescription(_t(
|
||||
'SubsiteDomain.PROTOCOL_DESCRIPTION',
|
||||
'Mark this as the default domain for this subsite'
|
||||
)));
|
||||
->setDescription(_t(
|
||||
'SubsiteDomain.PROTOCOL_DESCRIPTION',
|
||||
'Mark this as the default domain for this subsite'
|
||||
)));
|
||||
|
||||
$this->extend('updateCMSFields', $fields);
|
||||
return $fields;
|
||||
@ -162,7 +166,7 @@ class SubsiteDomain extends DataObject
|
||||
return $this->getFullProtocol() . $this->Domain;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Gets the full protocol (including ://) for this domain
|
||||
*
|
||||
* @return string
|
||||
@ -170,16 +174,13 @@ class SubsiteDomain extends DataObject
|
||||
public function getFullProtocol()
|
||||
{
|
||||
switch ($this->Protocol) {
|
||||
case self::PROTOCOL_HTTPS:
|
||||
{
|
||||
case self::PROTOCOL_HTTPS: {
|
||||
return 'https://';
|
||||
}
|
||||
case self::PROTOCOL_HTTP:
|
||||
{
|
||||
case self::PROTOCOL_HTTP: {
|
||||
return 'http://';
|
||||
}
|
||||
default:
|
||||
{
|
||||
default: {
|
||||
return Director::protocol();
|
||||
}
|
||||
}
|
||||
@ -198,7 +199,7 @@ class SubsiteDomain extends DataObject
|
||||
|
||||
// If there are wildcards in the primary domain (not recommended), make some
|
||||
// educated guesses about what to replace them with:
|
||||
$domain = preg_replace('/\.\*$/', ".{$currentHost}", $this->Domain );
|
||||
$domain = preg_replace('/\.\*$/', ".{$currentHost}", $this->Domain);
|
||||
|
||||
// Default to "subsite." prefix for first wildcard
|
||||
// TODO Whats the significance of "subsite" inthiscontext?!
|
||||
@ -230,5 +231,5 @@ class SubsiteDomain extends DataObject
|
||||
return Controller::join_links(
|
||||
$this->getAbsoluteLink(),
|
||||
Director::baseURL());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ use SilverStripe\Subsites\Forms\SubsitesTreeDropdownField;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
use SilverStripe\View\ArrayData;
|
||||
|
||||
|
||||
class SubsitesVirtualPage extends VirtualPage
|
||||
{
|
||||
|
||||
|
@ -15,9 +15,10 @@ use SilverStripe\Subsites\Model\Subsite;
|
||||
*/
|
||||
class SubsiteReportWrapper extends ReportWrapper
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Filtering
|
||||
|
||||
/**
|
||||
* @return FieldList
|
||||
*/
|
||||
public function parameterFields()
|
||||
{
|
||||
$subsites = Subsite::accessible_sites('CMS_ACCESS_CMSMain', true);
|
||||
@ -44,9 +45,9 @@ class SubsiteReportWrapper extends ReportWrapper
|
||||
return $fields;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Columns
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function columns()
|
||||
{
|
||||
$columns = parent::columns();
|
||||
@ -57,6 +58,10 @@ class SubsiteReportWrapper extends ReportWrapper
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Querying
|
||||
|
||||
/**
|
||||
* @param arary $params
|
||||
* @return void
|
||||
*/
|
||||
public function beforeQuery($params)
|
||||
{
|
||||
// The user has select a few specific sites
|
||||
@ -70,6 +75,10 @@ class SubsiteReportWrapper extends ReportWrapper
|
||||
Subsite::$force_subsite = join(',', array_keys($options));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function afterQuery()
|
||||
{
|
||||
// Manually manage the subsite filtering
|
||||
|
7
phpunit.xml.dist
Normal file
7
phpunit.xml.dist
Normal file
@ -0,0 +1,7 @@
|
||||
<phpunit bootstrap="framework/tests/bootstrap.php" colors="true">
|
||||
|
||||
<testsuite name="Default">
|
||||
<directory>tests/php</directory>
|
||||
</testsuite>
|
||||
|
||||
</phpunit>
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace Subsites\Test\Behaviour;
|
||||
namespace SilverStripe\Subsites\Tests\Behaviour;
|
||||
|
||||
if (!class_exists('SilverStripe\BehatExtension\Context\SilverStripeContext')) {
|
||||
return;
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
|
||||
@ -10,8 +12,9 @@ class BaseSubsiteTest extends SapphireTest
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Subsite::$use_session_subsiteid = true;
|
||||
Subsite::$force_subsite = null;}
|
||||
Subsite::$use_session_subsiteid = true;
|
||||
Subsite::$force_subsite = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Avoid subsites filtering on fixture fetching.
|
@ -1,13 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\Assets\File;
|
||||
use SilverStripe\Assets\Folder;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Subsites\Tests\BaseSubsiteTest;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
|
||||
class FileSubsitesTest extends BaseSubsiteTest
|
||||
{
|
||||
|
||||
public static $fixture_file = 'subsites/tests/SubsiteTest.yml';
|
||||
|
||||
/**
|
||||
@ -15,15 +19,15 @@ class FileSubsitesTest extends BaseSubsiteTest
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $illegalExtensions = array(
|
||||
protected $illegalExtensions = array(
|
||||
'File' => array(
|
||||
'SecureFileExtension',
|
||||
'VersionedFileExtension'
|
||||
),
|
||||
'SiteTree' => array(
|
||||
'Translatable',
|
||||
)
|
||||
);
|
||||
'SiteTree' => array(
|
||||
'Translatable',
|
||||
)
|
||||
);
|
||||
|
||||
public function testTrivialFeatures()
|
||||
{
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\Security\Group;
|
||||
use SilverStripe\Forms\FieldList;
|
||||
use SilverStripe\Subsites\Extensions\GroupSubsites;
|
||||
@ -10,7 +12,6 @@ class GroupSubsitesTest extends BaseSubsiteTest
|
||||
public static $fixture_file = 'subsites/tests/SubsiteTest.yml';
|
||||
|
||||
protected $requireDefaultRecordsFrom = [GroupSubsites::class];
|
||||
|
||||
public function testTrivialFeatures()
|
||||
{
|
||||
$this->assertTrue(is_array(singleton('GroupSubsites')->extraStatics()));
|
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\AssetAdmin\Controller\AssetAdmin;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\CMS\Controllers\CMSMain;
|
||||
use SilverStripe\Admin\LeftAndMain;
|
||||
@ -56,7 +59,6 @@ class LeftAndMainSubsitesTest extends FunctionalTest
|
||||
$subsite1 = $this->objFromFixture(Subsite::class, 'domaintest1');
|
||||
$subsite2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
||||
$subsite3 = $this->objFromFixture(Subsite::class, 'domaintest3');
|
||||
|
||||
$ids[] = $subsite1->ID;
|
||||
$ids[] = $subsite2->ID;
|
||||
$ids[] = $subsite3->ID;
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\SiteConfig\SiteConfig;
|
||||
use SilverStripe\Subsites\Extensions\SiteConfigSubsites;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
@ -7,9 +9,9 @@ use SilverStripe\Subsites\Model\Subsite;
|
||||
|
||||
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');
|
||||
$subsite2 = $this->objFromFixture(Subsite::class, 'domaintest2');
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\SiteConfig\SiteConfig;
|
||||
use SilverStripe\Forms\FieldList;
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Core\Config\Config;
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Control\Director;
|
@ -1,9 +1,11 @@
|
||||
<?php
|
||||
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\CMS\Model\SiteTree;
|
||||
use SilverStripe\Control\Director;
|
||||
use SilverStripe\Core\Config\Config;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\Security\Member;
|
||||
use SilverStripe\Subsites\Model\Subsite;
|
||||
use SilverStripe\Subsites\Model\SubsiteDomain;
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\Control\Session;
|
||||
use SilverStripe\Dev\FunctionalTest;
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\Assets\Filesystem;
|
||||
use SilverStripe\Assets\Tests\Storage\AssetStoreTest\TestAssetStore;
|
||||
use SilverStripe\Control\Director;
|
@ -1,6 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace SilverStripe\Subsites\Tests;
|
||||
|
||||
use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Subsites\Forms\WildcardDomainField;
|
||||
|
||||
/**
|
||||
* Tests {@see WildcardDomainField}
|
||||
@ -61,7 +64,7 @@ class WildcardDomainFieldTest extends SapphireTest {
|
||||
array('*.mysite.')
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function validWildcards() {
|
||||
return array(
|
||||
array('*.mysite.com'),
|
Loading…
Reference in New Issue
Block a user