Merge pull request #264 from kinglozzer/ss4-compat

SS4 namespaces compatibility
This commit is contained in:
Daniel Hensby 2016-09-23 15:20:57 +01:00 committed by GitHub
commit 84551163a6
37 changed files with 521 additions and 365 deletions

View File

@ -1,5 +1,21 @@
<?php <?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\CMS\Controllers\CMSPageAddController;
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Security\Group;
use SilverStripe\Assets\File;
use SilverStripe\CMS\Model\ErrorPage;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\SiteConfig\SiteConfigLeftAndMain;
use SilverStripe\Reports\Report;
use SilverStripe\Admin\SecurityAdmin;
use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\CMS\Controllers\CMSPagesController;
use SilverStripe\CMS\Controllers\CMSPageSettingsController;
use SilverStripe\AssetAdmin\Controller\AssetAdmin;
/** /**
* The subsites module modifies the behaviour of the CMS - in the SiteTree and Group databases - to store information * The subsites module modifies the behaviour of the CMS - in the SiteTree and Group databases - to store information
* about a number of sub-sites, rather than a single site. * about a number of sub-sites, rather than a single site.
@ -16,7 +32,7 @@ File::add_extension('FileSubsites');
ErrorPage::add_extension('ErrorPageSubsite'); ErrorPage::add_extension('ErrorPageSubsite');
SiteConfig::add_extension('SiteConfigSubsites'); SiteConfig::add_extension('SiteConfigSubsites');
SS_Report::add_excluded_reports('SubsiteReportWrapper'); Report::add_excluded_reports('SubsiteReportWrapper');
//Display in cms menu //Display in cms menu
AssetAdmin::add_extension('SubsiteMenuExtension'); AssetAdmin::add_extension('SubsiteMenuExtension');
@ -24,5 +40,5 @@ SecurityAdmin::add_extension('SubsiteMenuExtension');
CMSMain::add_extension('SubsiteMenuExtension'); CMSMain::add_extension('SubsiteMenuExtension');
CMSPagesController::add_extension('SubsiteMenuExtension'); CMSPagesController::add_extension('SubsiteMenuExtension');
SubsiteAdmin::add_extension('SubsiteMenuExtension'); SubsiteAdmin::add_extension('SubsiteMenuExtension');
CMSSettingsController::add_extension('SubsiteMenuExtension'); SiteConfigLeftAndMain::add_extension('SubsiteMenuExtension');

View File

@ -7,6 +7,6 @@ After:
AssetAdmin: AssetAdmin:
treats_subsite_0_as_global: true treats_subsite_0_as_global: true
Director: SilverStripe\Control\Director:
rules: rules:
'SubsiteXHRController': 'SubsiteXHRController' 'SubsiteXHRController': 'SubsiteXHRController'

View File

@ -1,4 +1,6 @@
<?php <?php
use SilverStripe\Admin\ModelAdmin;
/** /**
* Admin interface to manage and create {@link Subsite} instances. * Admin interface to manage and create {@link Subsite} instances.
* *
@ -23,7 +25,7 @@ class SubsiteAdmin extends ModelAdmin {
$grid=$form->Fields()->dataFieldByName('Subsite'); $grid=$form->Fields()->dataFieldByName('Subsite');
if($grid) { if($grid) {
$grid->getConfig()->removeComponentsByType('GridFieldDetailForm'); $grid->getConfig()->removeComponentsByType('SilverStripe\\Forms\\GridField\\GridFieldDetailForm');
$grid->getConfig()->addComponent(new GridFieldSubsiteDetailForm()); $grid->getConfig()->addComponent(new GridFieldSubsiteDetailForm());
} }

View File

@ -1,10 +1,14 @@
<?php <?php
use SilverStripe\Forms\TreeMultiselectField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Reports\ReportWrapper;
/** /**
* Creates a subsite-aware version of another report. * Creates a subsite-aware version of another report.
* Pass another report (or its classname) into the constructor. * Pass another report (or its classname) into the constructor.
*/ */
class SubsiteReportWrapper extends SS_ReportWrapper { class SubsiteReportWrapper extends ReportWrapper {
/////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////
// Filtering // Filtering

View File

@ -1,5 +1,7 @@
<?php <?php
use SilverStripe\Admin\LeftAndMain;
/** /**
* Section-agnostic PJAX controller. * Section-agnostic PJAX controller.
*/ */
@ -39,7 +41,7 @@ class SubsiteXHRController extends LeftAndMain {
* Provide the list of available subsites as a cms-section-agnostic PJAX handler. * Provide the list of available subsites as a cms-section-agnostic PJAX handler.
*/ */
public function SubsiteList() { public function SubsiteList() {
return $this->renderWith('SubsiteList'); return $this->renderWith('Includes/SubsiteList');
} }
} }

View File

@ -1,4 +1,17 @@
<?php <?php
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\ArrayList;
use SilverStripe\View\ArrayData;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Control\Controller;
use SilverStripe\Forms\LabelField;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Control\Session;
use SilverStripe\Core\Config\Config;
use SilverStripe\CMS\Model\VirtualPage;
use SilverStripe\CMS\Model\VirtualPage_Controller;
class SubsitesVirtualPage extends VirtualPage { class SubsitesVirtualPage extends VirtualPage {
private static $description = 'Displays the content of a page on another subsite'; private static $description = 'Displays the content of a page on another subsite';
@ -9,94 +22,94 @@ class SubsitesVirtualPage extends VirtualPage {
'CustomMetaDescription' => 'Text', 'CustomMetaDescription' => 'Text',
'CustomExtraMeta' => 'HTMLText' 'CustomExtraMeta' => 'HTMLText'
); );
public function getCMSFields() { public function getCMSFields() {
$fields = parent::getCMSFields(); $fields = parent::getCMSFields();
$subsites = DataObject::get('Subsite'); $subsites = DataObject::get('Subsite');
if(!$subsites) { if(!$subsites) {
$subsites = new ArrayList(); $subsites = new ArrayList();
}else { }else {
$subsites=ArrayList::create($subsites->toArray()); $subsites=ArrayList::create($subsites->toArray());
} }
$subsites->push(new ArrayData(array('Title' => 'Main site', 'ID' => 0))); $subsites->push(new ArrayData(array('Title' => 'Main site', 'ID' => 0)));
$fields->addFieldToTab( $fields->addFieldToTab(
'Root.Main', 'Root.Main',
DropdownField::create( DropdownField::create(
"CopyContentFromID_SubsiteID", "CopyContentFromID_SubsiteID",
_t('SubsitesVirtualPage.SubsiteField',"Subsite"), _t('SubsitesVirtualPage.SubsiteField',"Subsite"),
$subsites->map('ID', 'Title') $subsites->map('ID', 'Title')
)->addExtraClass('subsitestreedropdownfield-chooser no-change-track'), )->addExtraClass('subsitestreedropdownfield-chooser no-change-track'),
'CopyContentFromID' 'CopyContentFromID'
); );
// Setup the linking to the original page. // Setup the linking to the original page.
$pageSelectionField = new SubsitesTreeDropdownField( $pageSelectionField = new SubsitesTreeDropdownField(
"CopyContentFromID", "CopyContentFromID",
_t('VirtualPage.CHOOSE', "Choose a page to link to"), _t('VirtualPage.CHOOSE', "Choose a page to link to"),
"SiteTree", "SilverStripe\\CMS\\Model\\SiteTree",
"ID", "ID",
"MenuTitle" "MenuTitle"
); );
if(Controller::has_curr() && Controller::curr()->getRequest()) { if(Controller::has_curr() && Controller::curr()->getRequest()) {
$subsiteID = Controller::curr()->getRequest()->requestVar('CopyContentFromID_SubsiteID'); $subsiteID = Controller::curr()->getRequest()->requestVar('CopyContentFromID_SubsiteID');
$pageSelectionField->setSubsiteID($subsiteID); $pageSelectionField->setSubsiteID($subsiteID);
} }
$fields->replaceField('CopyContentFromID', $pageSelectionField); $fields->replaceField('CopyContentFromID', $pageSelectionField);
// Create links back to the original object in the CMS // Create links back to the original object in the CMS
if($this->CopyContentFromID) { if($this->CopyContentFromID) {
$editLink = "admin/pages/edit/show/$this->CopyContentFromID/?SubsiteID=" . $this->CopyContentFrom()->SubsiteID; $editLink = "admin/pages/edit/show/$this->CopyContentFromID/?SubsiteID=" . $this->CopyContentFrom()->SubsiteID;
$linkToContent = " $linkToContent = "
<a class=\"cmsEditlink\" href=\"$editLink\">" . <a class=\"cmsEditlink\" href=\"$editLink\">" .
_t('VirtualPage.EDITCONTENT', 'Click here to edit the content') . _t('VirtualPage.EDITCONTENT', 'Click here to edit the content') .
"</a>"; "</a>";
$fields->removeByName("VirtualPageContentLinkLabel"); $fields->removeByName("VirtualPageContentLinkLabel");
$fields->addFieldToTab( $fields->addFieldToTab(
"Root.Main", "Root.Main",
$linkToContentLabelField = new LabelField('VirtualPageContentLinkLabel', $linkToContent), $linkToContentLabelField = new LabelField('VirtualPageContentLinkLabel', $linkToContent),
'Title' 'Title'
); );
$linkToContentLabelField->setAllowHTML(true); $linkToContentLabelField->setAllowHTML(true);
} }
$fields->addFieldToTab( $fields->addFieldToTab(
'Root.Main', 'Root.Main',
TextField::create( TextField::create(
'CustomMetaTitle', 'CustomMetaTitle',
$this->fieldLabel('CustomMetaTitle') $this->fieldLabel('CustomMetaTitle')
)->setDescription(_t('SubsitesVirtualPage.OverrideNote', 'Overrides inherited value from the source')), )->setDescription(_t('SubsitesVirtualPage.OverrideNote', 'Overrides inherited value from the source')),
'MetaTitle' 'MetaTitle'
); );
$fields->addFieldToTab( $fields->addFieldToTab(
'Root.Main', 'Root.Main',
TextareaField::create( TextareaField::create(
'CustomMetaKeywords', 'CustomMetaKeywords',
$this->fieldLabel('CustomMetaTitle') $this->fieldLabel('CustomMetaTitle')
)->setDescription(_t('SubsitesVirtualPage.OverrideNote')), )->setDescription(_t('SubsitesVirtualPage.OverrideNote')),
'MetaKeywords' 'MetaKeywords'
); );
$fields->addFieldToTab( $fields->addFieldToTab(
'Root.Main', 'Root.Main',
TextareaField::create( TextareaField::create(
'CustomMetaDescription', 'CustomMetaDescription',
$this->fieldLabel('CustomMetaTitle') $this->fieldLabel('CustomMetaTitle')
)->setDescription(_t('SubsitesVirtualPage.OverrideNote')), )->setDescription(_t('SubsitesVirtualPage.OverrideNote')),
'MetaDescription' 'MetaDescription'
); );
$fields->addFieldToTab( $fields->addFieldToTab(
'Root.Main', 'Root.Main',
TextField::create( TextField::create(
'CustomExtraMeta', 'CustomExtraMeta',
$this->fieldLabel('CustomMetaTitle') $this->fieldLabel('CustomMetaTitle')
)->setDescription(_t('SubsitesVirtualPage.OverrideNote')), )->setDescription(_t('SubsitesVirtualPage.OverrideNote')),
'ExtraMeta' 'ExtraMeta'
); );
return $fields; return $fields;
} }
@ -113,73 +126,73 @@ class SubsitesVirtualPage extends VirtualPage {
public function getCopyContentFromID_SubsiteID() { public function getCopyContentFromID_SubsiteID() {
return ($this->CopyContentFromID) ? (int)$this->CopyContentFrom()->SubsiteID : (int)Session::get('SubsiteID'); return ($this->CopyContentFromID) ? (int)$this->CopyContentFrom()->SubsiteID : (int)Session::get('SubsiteID');
} }
public function getVirtualFields() { public function getVirtualFields() {
$fields = parent::getVirtualFields(); $fields = parent::getVirtualFields();
foreach($fields as $k => $v) { foreach($fields as $k => $v) {
if($v == 'SubsiteID') unset($fields[$k]); if($v == 'SubsiteID') unset($fields[$k]);
} }
foreach(self::$db as $field => $type) if (in_array($field, $fields)) unset($fields[array_search($field, $fields)]); foreach(self::$db as $field => $type) if (in_array($field, $fields)) unset($fields[array_search($field, $fields)]);
return $fields; return $fields;
} }
public function syncLinkTracking() { public function syncLinkTracking() {
$oldState = Subsite::$disable_subsite_filter; $oldState = Subsite::$disable_subsite_filter;
Subsite::$disable_subsite_filter = true; Subsite::$disable_subsite_filter = true;
if ($this->CopyContentFromID) $this->HasBrokenLink = DataObject::get_by_id('SiteTree', $this->CopyContentFromID) ? false : true; if ($this->CopyContentFromID) $this->HasBrokenLink = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $this->CopyContentFromID) ? false : true;
Subsite::$disable_subsite_filter = $oldState; Subsite::$disable_subsite_filter = $oldState;
} }
public function onBeforeWrite() { public function onBeforeWrite() {
parent::onBeforeWrite(); parent::onBeforeWrite();
if($this->CustomMetaTitle) $this->MetaTitle = $this->CustomMetaTitle; if($this->CustomMetaTitle) $this->MetaTitle = $this->CustomMetaTitle;
else { else {
$this->MetaTitle = $this->ContentSource()->MetaTitle ? $this->ContentSource()->MetaTitle : $this->MetaTitle; $this->MetaTitle = $this->ContentSource()->MetaTitle ? $this->ContentSource()->MetaTitle : $this->MetaTitle;
} }
if($this->CustomMetaKeywords) $this->MetaKeywords = $this->CustomMetaKeywords; if($this->CustomMetaKeywords) $this->MetaKeywords = $this->CustomMetaKeywords;
else { else {
$this->MetaKeywords = $this->ContentSource()->MetaKeywords ? $this->ContentSource()->MetaKeywords : $this->MetaKeywords; $this->MetaKeywords = $this->ContentSource()->MetaKeywords ? $this->ContentSource()->MetaKeywords : $this->MetaKeywords;
} }
if($this->CustomMetaDescription) $this->MetaDescription = $this->CustomMetaDescription; if($this->CustomMetaDescription) $this->MetaDescription = $this->CustomMetaDescription;
else { else {
$this->MetaDescription = $this->ContentSource()->MetaDescription ? $this->ContentSource()->MetaDescription : $this->MetaDescription; $this->MetaDescription = $this->ContentSource()->MetaDescription ? $this->ContentSource()->MetaDescription : $this->MetaDescription;
} }
if($this->CustomExtraMeta) $this->ExtraMeta = $this->CustomExtraMeta; if($this->CustomExtraMeta) $this->ExtraMeta = $this->CustomExtraMeta;
else { else {
$this->ExtraMeta = $this->ContentSource()->ExtraMeta ? $this->ContentSource()->ExtraMeta : $this->ExtraMeta; $this->ExtraMeta = $this->ContentSource()->ExtraMeta ? $this->ContentSource()->ExtraMeta : $this->ExtraMeta;
} }
} }
public function validURLSegment() { public function validURLSegment() {
$isValid = parent::validURLSegment(); $isValid = parent::validURLSegment();
// Veto the validation rules if its false. In this case, some logic // Veto the validation rules if its false. In this case, some logic
// needs to be duplicated from parent to find out the exact reason the validation failed. // needs to be duplicated from parent to find out the exact reason the validation failed.
if(!$isValid) { if(!$isValid) {
$IDFilter = ($this->ID) ? "AND \"SiteTree\".\"ID\" <> $this->ID" : null; $IDFilter = ($this->ID) ? "AND \"SiteTree\".\"ID\" <> $this->ID" : null;
$parentFilter = null; $parentFilter = null;
if(Config::inst()->get('SiteTree', 'nested_urls')) { if(Config::inst()->get('SilverStripe\\CMS\\Model\\SiteTree', 'nested_urls')) {
if($this->ParentID) { if($this->ParentID) {
$parentFilter = " AND \"SiteTree\".\"ParentID\" = $this->ParentID"; $parentFilter = " AND \"SiteTree\".\"ParentID\" = $this->ParentID";
} else { } else {
$parentFilter = ' AND "SiteTree"."ParentID" = 0'; $parentFilter = ' AND "SiteTree"."ParentID" = 0';
} }
} }
$origDisableSubsiteFilter = Subsite::$disable_subsite_filter; $origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
Subsite::$disable_subsite_filter = true; Subsite::$disable_subsite_filter = true;
$existingPage = DataObject::get_one( $existingPage = DataObject::get_one(
'SiteTree', 'SilverStripe\\CMS\\Model\\SiteTree',
"\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter", "\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter",
false // disable cache, it doesn't include subsite status in the key false // disable cache, it doesn't include subsite status in the key
); );
Subsite::$disable_subsite_filter = $origDisableSubsiteFilter; Subsite::$disable_subsite_filter = $origDisableSubsiteFilter;
$existingPageInSubsite = DataObject::get_one( $existingPageInSubsite = DataObject::get_one(
'SiteTree', 'SilverStripe\\CMS\\Model\\SiteTree',
"\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter", "\"URLSegment\" = '$this->URLSegment' $IDFilter $parentFilter",
false // disable cache, it doesn't include subsite status in the key false // disable cache, it doesn't include subsite status in the key
); );
@ -188,25 +201,7 @@ class SubsitesVirtualPage extends VirtualPage {
// be more specific and allow same URLSegments in different subsites // be more specific and allow same URLSegments in different subsites
$isValid = !($existingPage && $existingPageInSubsite); $isValid = !($existingPage && $existingPageInSubsite);
} }
return $isValid; return $isValid;
} }
} }
class SubsitesVirtualPage_Controller extends VirtualPage_Controller {
public function reloadContent() {
$this->failover->copyFrom($this->failover->CopyContentFrom());
$this->failover->write();
return;
}
public function init(){
$origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
Subsite::$disable_subsite_filter = true;
parent::init();
Subsite::$disable_subsite_filter = $origDisableSubsiteFilter;
}
}

View File

@ -1,4 +1,7 @@
<?php <?php
use SilverStripe\Forms\HiddenField;
use SilverStripe\Core\Extension;
class CMSPageAddControllerExtension extends Extension { class CMSPageAddControllerExtension extends Extension {
function updatePageOptions(&$fields) { function updatePageOptions(&$fields) {

View File

@ -1,4 +1,7 @@
<?php <?php
use SilverStripe\View\SSViewer;
use SilverStripe\Core\Extension;
/** /**
* @package subsites * @package subsites
*/ */

View File

@ -1,4 +1,7 @@
<?php <?php
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\DataExtension;
class ErrorPageSubsite extends DataExtension { class ErrorPageSubsite extends DataExtension {
/** /**

View File

@ -1,4 +1,14 @@
<?php <?php
use SilverStripe\Forms\FieldList;
use SilverStripe\Assets\Folder;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\ORM\DataQuery;
use SilverStripe\Control\Session;
use SilverStripe\Security\Permission;
use SilverStripe\ORM\DataExtension;
/** /**
* Extension for the File object to add subsites support * Extension for the File object to add subsites support
* *

View File

@ -1,4 +1,16 @@
<?php <?php
use SilverStripe\ORM\DB;
use SilverStripe\Forms\FieldList;
use SilverStripe\Core\Convert;
use SilverStripe\Forms\OptionsetField;
use SilverStripe\Forms\CheckboxSetField;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\ORM\DataQuery;
use SilverStripe\Control\Cookie;
use SilverStripe\ORM\DataExtension;
use SilverStripe\Security\PermissionProvider;
/** /**
* Extension for the Group object to add subsites support * Extension for the Group object to add subsites support
* *
@ -24,30 +36,30 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
function requireDefaultRecords() { function requireDefaultRecords() {
// Migration for Group.SubsiteID data from when Groups only had a single subsite // Migration for Group.SubsiteID data from when Groups only had a single subsite
$groupFields = DB::field_list('Group'); $groupFields = DB::field_list('Group');
// Detection of SubsiteID field is the trigger for old-style-subsiteID migration // Detection of SubsiteID field is the trigger for old-style-subsiteID migration
if(isset($groupFields['SubsiteID'])) { if(isset($groupFields['SubsiteID'])) {
// Migrate subsite-specific data // Migrate subsite-specific data
DB::query('INSERT INTO "Group_Subsites" ("GroupID", "SubsiteID") DB::query('INSERT INTO "Group_Subsites" ("GroupID", "SubsiteID")
SELECT "ID", "SubsiteID" FROM "Group" WHERE "SubsiteID" > 0'); SELECT "ID", "SubsiteID" FROM "Group" WHERE "SubsiteID" > 0');
// Migrate global-access data // Migrate global-access data
DB::query('UPDATE "Group" SET "AccessAllSubsites" = 1 WHERE "SubsiteID" = 0'); DB::query('UPDATE "Group" SET "AccessAllSubsites" = 1 WHERE "SubsiteID" = 0');
// Move the field out of the way so that this migration doesn't get executed again // Move the field out of the way so that this migration doesn't get executed again
DB::get_schema()->renameField('Group', 'SubsiteID', '_obsolete_SubsiteID'); DB::get_schema()->renameField('Group', 'SubsiteID', '_obsolete_SubsiteID');
// No subsite access on anything means that we've just installed the subsites module. // No subsite access on anything means that we've just installed the subsites module.
// Make all previous groups global-access groups // Make all previous groups global-access groups
} else if(!DB::query('SELECT "Group"."ID" FROM "Group" } else if(!DB::query('SELECT "Group"."ID" FROM "Group"
LEFT JOIN "Group_Subsites" ON "Group_Subsites"."GroupID" = "Group"."ID" AND "Group_Subsites"."SubsiteID" > 0 LEFT JOIN "Group_Subsites" ON "Group_Subsites"."GroupID" = "Group"."ID" AND "Group_Subsites"."SubsiteID" > 0
WHERE "AccessAllSubsites" = 1 WHERE "AccessAllSubsites" = 1
OR "Group_Subsites"."GroupID" IS NOT NULL ')->value()) { OR "Group_Subsites"."GroupID" IS NOT NULL ')->value()) {
DB::query('UPDATE "Group" SET "AccessAllSubsites" = 1'); DB::query('UPDATE "Group" SET "AccessAllSubsites" = 1');
} }
} }
function updateCMSFields(FieldList $fields) { function updateCMSFields(FieldList $fields) {
if($this->owner->canEdit() ){ if($this->owner->canEdit() ){
// i18n tab // i18n tab
@ -58,11 +70,11 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
// Prevent XSS injection // Prevent XSS injection
$subsiteMap = Convert::raw2xml($subsiteMap); $subsiteMap = Convert::raw2xml($subsiteMap);
// Interface is different if you have the rights to modify subsite group values on // Interface is different if you have the rights to modify subsite group values on
// all subsites // all subsites
if(isset($subsiteMap[0])) { if(isset($subsiteMap[0])) {
$fields->addFieldToTab("Root.Subsites", new OptionsetField("AccessAllSubsites", $fields->addFieldToTab("Root.Subsites", new OptionsetField("AccessAllSubsites",
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'), _t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
array( array(
1 => _t('GroupSubsites.ACCESSALL', "All subsites"), 1 => _t('GroupSubsites.ACCESSALL', "All subsites"),
@ -76,11 +88,11 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
} else { } else {
if (sizeof($subsiteMap) <= 1) { if (sizeof($subsiteMap) <= 1) {
$fields->addFieldToTab("Root.Subsites", new ReadonlyField("SubsitesHuman", $fields->addFieldToTab("Root.Subsites", new ReadonlyField("SubsitesHuman",
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'), _t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
reset($subsiteMap))); reset($subsiteMap)));
} else { } else {
$fields->addFieldToTab("Root.Subsites", new CheckboxSetField("Subsites", $fields->addFieldToTab("Root.Subsites", new CheckboxSetField("Subsites",
_t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'), _t('GroupSubsites.ACCESSRADIOTITLE', 'Give this group access to'),
$subsiteMap)); $subsiteMap));
} }
@ -116,7 +128,7 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
/*if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID; /*if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
else */$subsiteID = (int)Subsite::currentSubsiteID(); else */$subsiteID = (int)Subsite::currentSubsiteID();
// Don't filter by Group_Subsites if we've already done that // Don't filter by Group_Subsites if we've already done that
$hasGroupSubsites = false; $hasGroupSubsites = false;
foreach($query->getFrom() as $item) { foreach($query->getFrom() as $item) {
@ -125,10 +137,10 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
break; break;
} }
} }
if(!$hasGroupSubsites) { if(!$hasGroupSubsites) {
if($subsiteID) { if($subsiteID) {
$query->addLeftJoin("Group_Subsites", "\"Group_Subsites\".\"GroupID\" $query->addLeftJoin("Group_Subsites", "\"Group_Subsites\".\"GroupID\"
= \"Group\".\"ID\" AND \"Group_Subsites\".\"SubsiteID\" = $subsiteID"); = \"Group\".\"ID\" AND \"Group_Subsites\".\"SubsiteID\" = $subsiteID");
$query->addWhere("(\"Group_Subsites\".\"SubsiteID\" IS NOT NULL OR $query->addWhere("(\"Group_Subsites\".\"SubsiteID\" IS NOT NULL OR
\"Group\".\"AccessAllSubsites\" = 1)"); \"Group\".\"AccessAllSubsites\" = 1)");
@ -136,7 +148,7 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
$query->addWhere("\"Group\".\"AccessAllSubsites\" = 1"); $query->addWhere("\"Group\".\"AccessAllSubsites\" = 1");
} }
} }
// WORKAROUND for databases that complain about an ORDER BY when the column wasn't selected (e.g. SQL Server) // WORKAROUND for databases that complain about an ORDER BY when the column wasn't selected (e.g. SQL Server)
$select=$query->getSelect(); $select=$query->getSelect();
if(isset($select[0]) && !$select[0] == 'COUNT(*)') { if(isset($select[0]) && !$select[0] == 'COUNT(*)') {
@ -152,7 +164,7 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
$this->owner->AccessAllSubsites = 1; $this->owner->AccessAllSubsites = 1;
} }
} }
function onAfterWrite() { function onAfterWrite() {
// New record test approximated by checking whether the ID has changed. // New record test approximated by checking whether the ID has changed.
// Note also that the after write test is only used when we're on a subsite // Note also that the after write test is only used when we're on a subsite
@ -166,7 +178,7 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
// Find the sites that this group belongs to and the sites where we have appropriate perm. // Find the sites that this group belongs to and the sites where we have appropriate perm.
$accessibleSites = Subsite::accessible_sites('CMS_ACCESS_SecurityAdmin')->column('ID'); $accessibleSites = Subsite::accessible_sites('CMS_ACCESS_SecurityAdmin')->column('ID');
$linkedSites = $this->owner->Subsites()->column('ID'); $linkedSites = $this->owner->Subsites()->column('ID');
// We are allowed to access this site if at we have CMS_ACCESS_SecurityAdmin permission on // We are allowed to access this site if at we have CMS_ACCESS_SecurityAdmin permission on
// at least one of the sites // at least one of the sites
return (bool)array_intersect($accessibleSites, $linkedSites); return (bool)array_intersect($accessibleSites, $linkedSites);

View File

@ -1,4 +1,19 @@
<?php <?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;
use SilverStripe\Admin\CMSMenu;
use SilverStripe\Security\Security;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Extension;
/** /**
* Decorator designed to add subsites support to LeftAndMain * Decorator designed to add subsites support to LeftAndMain
* *
@ -46,7 +61,7 @@ class LeftAndMainSubsites extends Extension {
// Rationalise member arguments // Rationalise member arguments
if(!$member) $member = Member::currentUser(); if(!$member) $member = Member::currentUser();
if(!$member) return new ArrayList(); if(!$member) return new ArrayList();
if(!is_object($member)) $member = DataObject::get_by_id('Member', $member); if(!is_object($member)) $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
// Collect permissions - honour the LeftAndMain::required_permission_codes, current model requires // Collect permissions - honour the LeftAndMain::required_permission_codes, current model requires
// us to check if the user satisfies ALL permissions. Code partly copied from LeftAndMain::canView. // us to check if the user satisfies ALL permissions. Code partly copied from LeftAndMain::canView.
@ -295,7 +310,7 @@ class LeftAndMainSubsites extends Extension {
} }
function copytosubsite($data, $form) { function copytosubsite($data, $form) {
$page = DataObject::get_by_id('SiteTree', $data['ID']); $page = DataObject::get_by_id('SilverStripe\\CMS\\Model\\SiteTree', $data['ID']);
$subsite = DataObject::get_by_id('Subsite', $data['CopyToSubsiteID']); $subsite = DataObject::get_by_id('Subsite', $data['CopyToSubsiteID']);
$newPage = $page->duplicateToSubsite($subsite->ID, true); $newPage = $page->duplicateToSubsite($subsite->ID, true);
$response = $this->owner->getResponse(); $response = $this->owner->getResponse();

View File

@ -1,5 +1,11 @@
<?php <?php
use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\ORM\DataQuery;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\HiddenField;
use SilverStripe\ORM\DataExtension;
/** /**
* Extension for the SiteConfig object to add subsites support * Extension for the SiteConfig object to add subsites support
*/ */
@ -8,7 +14,7 @@ class SiteConfigSubsites extends DataExtension {
private static $has_one = array( private static $has_one = array(
'Subsite' => 'Subsite', // The subsite that this page belongs to 'Subsite' => 'Subsite', // The subsite that this page belongs to
); );
/** /**
* Update any requests to limit the results to the current site * Update any requests to limit the results to the current site
*/ */

View File

@ -1,5 +1,20 @@
<?php <?php
use SilverStripe\ORM\Queries\SQLSelect;
use SilverStripe\ORM\DataQuery;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\InlineFormAction;
use SilverStripe\Core\Config\Config;
use SilverStripe\Control\Director;
use SilverStripe\Control\Controller;
use SilverStripe\ORM\DataObject;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Security\Member;
use SilverStripe\Control\HTTP;
use SilverStripe\Core\Convert;
use SilverStripe\ORM\DataExtension;
/** /**
* Extension for the SiteTree object to add subsites support * Extension for the SiteTree object to add subsites support
*/ */
@ -10,7 +25,7 @@ class SiteTreeSubsites extends DataExtension {
); );
private static $many_many = array( private static $many_many = array(
'CrossSubsiteLinkTracking' => 'SiteTree' // Stored separately, as the logic for URL rewriting is different 'CrossSubsiteLinkTracking' => 'SilverStripe\\CMS\\Model\\SiteTree' // Stored separately, as the logic for URL rewriting is different
); );
private static $many_many_extraFields = array( private static $many_many_extraFields = array(
@ -21,14 +36,14 @@ class SiteTreeSubsites extends DataExtension {
if($this->owner->SubsiteID == 0) return true; if($this->owner->SubsiteID == 0) return true;
return false; return false;
} }
/** /**
* Update any requests to limit the results to the current site * Update any requests to limit the results to the current site
*/ */
public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) { public function augmentSQL(SQLSelect $query, DataQuery $dataQuery = null) {
if(Subsite::$disable_subsite_filter) return; if(Subsite::$disable_subsite_filter) return;
if($dataQuery->getQueryParam('Subsite.filter') === false) return; if($dataQuery->getQueryParam('Subsite.filter') === false) return;
// If you're querying by ID, ignore the sub-site - this is a bit ugly... // If you're querying by ID, ignore the sub-site - this is a bit ugly...
// if(!$query->where || (strpos($query->where[0], ".\"ID\" = ") === false && strpos($query->where[0], ".`ID` = ") === false && strpos($query->where[0], ".ID = ") === false && strpos($query->where[0], "ID = ") !== 0)) { // if(!$query->where || (strpos($query->where[0], ".\"ID\" = ") === false && strpos($query->where[0], ".`ID` = ") === false && strpos($query->where[0], ".ID = ") === false && strpos($query->where[0], "ID = ") !== 0)) {
if($query->filtersOnID()) return; if($query->filtersOnID()) return;
@ -47,10 +62,10 @@ class SiteTreeSubsites extends DataExtension {
break; break;
} }
} }
function onBeforeWrite() { function onBeforeWrite() {
if(!$this->owner->ID && !$this->owner->SubsiteID) $this->owner->SubsiteID = Subsite::currentSubsiteID(); if(!$this->owner->ID && !$this->owner->SubsiteID) $this->owner->SubsiteID = Subsite::currentSubsiteID();
parent::onBeforeWrite(); parent::onBeforeWrite();
} }
@ -58,7 +73,7 @@ class SiteTreeSubsites extends DataExtension {
$subsites = Subsite::accessible_sites("CMS_ACCESS_CMSMain"); $subsites = Subsite::accessible_sites("CMS_ACCESS_CMSMain");
$subsitesMap = array(); $subsitesMap = array();
if($subsites && $subsites->Count()) { if($subsites && $subsites->Count()) {
$subsitesMap = $subsites->map('ID', 'Title'); $subsitesMap = $subsites->map('ID', 'Title')->toArray();
unset($subsitesMap[$this->owner->SubsiteID]); unset($subsitesMap[$this->owner->SubsiteID]);
} }
@ -68,8 +83,8 @@ class SiteTreeSubsites extends DataExtension {
$fields->addFieldToTab( $fields->addFieldToTab(
'Root.Main', 'Root.Main',
new DropdownField( new DropdownField(
"CopyToSubsiteID", "CopyToSubsiteID",
_t('SiteTreeSubsites.CopyToSubsite', "Copy page to subsite"), _t('SiteTreeSubsites.CopyToSubsite', "Copy page to subsite"),
$subsitesMap, $subsitesMap,
'' ''
) )
@ -77,31 +92,30 @@ class SiteTreeSubsites extends DataExtension {
$fields->addFieldToTab( $fields->addFieldToTab(
'Root.Main', 'Root.Main',
$copyAction = new InlineFormAction( $copyAction = new InlineFormAction(
"copytosubsite", "copytosubsite",
_t('SiteTreeSubsites.CopyAction', "Copy") _t('SiteTreeSubsites.CopyAction', "Copy")
) )
); );
$copyAction->includeDefaultJS(false);
} }
// replace readonly link prefix // replace readonly link prefix
$subsite = $this->owner->Subsite(); $subsite = $this->owner->Subsite();
$nested_urls_enabled = Config::inst()->get('SiteTree', 'nested_urls'); $nested_urls_enabled = Config::inst()->get('SilverStripe\\CMS\\Model\\SiteTree', 'nested_urls');
if($subsite && $subsite->ID) { if($subsite && $subsite->ID) {
$baseUrl = Director::protocol() . $subsite->domain() . '/'; $baseUrl = Director::protocol() . $subsite->domain() . '/';
$baseLink = Controller::join_links ( $baseLink = Controller::join_links (
$baseUrl, $baseUrl,
($nested_urls_enabled && $this->owner->ParentID ? $this->owner->Parent()->RelativeLink(true) : null) ($nested_urls_enabled && $this->owner->ParentID ? $this->owner->Parent()->RelativeLink(true) : null)
); );
$urlsegment = $fields->dataFieldByName('URLSegment'); $urlsegment = $fields->dataFieldByName('URLSegment');
$urlsegment->setURLPrefix($baseLink); $urlsegment->setURLPrefix($baseLink);
} }
} }
function alternateSiteConfig() { function alternateSiteConfig() {
if(!$this->owner->SubsiteID) return false; if(!$this->owner->SubsiteID) return false;
$sc = DataObject::get_one('SiteConfig', '"SubsiteID" = ' . $this->owner->SubsiteID); $sc = DataObject::get_one('SilverStripe\\SiteConfig\\SiteConfig', '"SubsiteID" = ' . $this->owner->SubsiteID);
if(!$sc) { if(!$sc) {
$sc = new SiteConfig(); $sc = new SiteConfig();
$sc->SubsiteID = $this->owner->SubsiteID; $sc->SubsiteID = $this->owner->SubsiteID;
@ -111,18 +125,18 @@ class SiteTreeSubsites extends DataExtension {
} }
return $sc; return $sc;
} }
/** /**
* Only allow editing of a page if the member satisfies one of the following conditions: * Only allow editing of a page if the member satisfies one of the following conditions:
* - Is in a group which has access to the subsite this page belongs to * - Is in a group which has access to the subsite this page belongs to
* - Is in a group with edit permissions on the "main site" * - Is in a group with edit permissions on the "main site"
* *
* @return boolean * @return boolean
*/ */
function canEdit($member = null) { function canEdit($member = null) {
if(!$member) $member = Member::currentUser(); if(!$member) $member = Member::currentUser();
// Find the sites that this user has access to // Find the sites that this user has access to
$goodSites = Subsite::accessible_sites('CMS_ACCESS_CMSMain',true,'all',$member)->column('ID'); $goodSites = Subsite::accessible_sites('CMS_ACCESS_CMSMain',true,'all',$member)->column('ID');
@ -140,25 +154,25 @@ class SiteTreeSubsites extends DataExtension {
// Return true if they have access to this object's site // Return true if they have access to this object's site
if(!(in_array(0, $goodSites) || in_array($subsiteID, $goodSites))) return false; if(!(in_array(0, $goodSites) || in_array($subsiteID, $goodSites))) return false;
} }
/** /**
* @return boolean * @return boolean
*/ */
function canDelete($member = null) { function canDelete($member = null) {
if(!$member && $member !== FALSE) $member = Member::currentUser(); if(!$member && $member !== FALSE) $member = Member::currentUser();
return $this->canEdit($member); return $this->canEdit($member);
} }
/** /**
* @return boolean * @return boolean
*/ */
function canAddChildren($member = null) { function canAddChildren($member = null) {
if(!$member && $member !== FALSE) $member = Member::currentUser(); if(!$member && $member !== FALSE) $member = Member::currentUser();
return $this->canEdit($member); return $this->canEdit($member);
} }
/** /**
* @return boolean * @return boolean
*/ */
@ -252,7 +266,7 @@ class SiteTreeSubsites extends DataExtension {
$subsite = Subsite::currentSubsite(); $subsite = Subsite::currentSubsite();
if($subsite && $subsite->Theme){ if($subsite && $subsite->Theme){
Config::inst()->update('SSViewer', 'theme', Subsite::currentSubsite()->Theme); Config::inst()->update('SilverStripe\\View\\SSViewer', 'theme', Subsite::currentSubsite()->Theme);
} }
} }
@ -293,22 +307,22 @@ class SiteTreeSubsites extends DataExtension {
// Set LinkTracking appropriately // Set LinkTracking appropriately
$links = HTTP::getLinksIn($this->owner->Content); $links = HTTP::getLinksIn($this->owner->Content);
$linkedPages = array(); $linkedPages = array();
if($links) foreach($links as $link) { if($links) foreach($links as $link) {
if(substr($link, 0, strlen('http://')) == 'http://') { if(substr($link, 0, strlen('http://')) == 'http://') {
$withoutHttp = substr($link, strlen('http://')); $withoutHttp = substr($link, strlen('http://'));
if(strpos($withoutHttp, '/') && strpos($withoutHttp, '/') < strlen($withoutHttp)) { if(strpos($withoutHttp, '/') && strpos($withoutHttp, '/') < strlen($withoutHttp)) {
$domain = substr($withoutHttp, 0, strpos($withoutHttp, '/')); $domain = substr($withoutHttp, 0, strpos($withoutHttp, '/'));
$rest = substr($withoutHttp, strpos($withoutHttp, '/') + 1); $rest = substr($withoutHttp, strpos($withoutHttp, '/') + 1);
$subsiteID = Subsite::getSubsiteIDForDomain($domain); $subsiteID = Subsite::getSubsiteIDForDomain($domain);
if($subsiteID == 0) continue; // We have no idea what the domain for the main site is, so cant track links to it if($subsiteID == 0) continue; // We have no idea what the domain for the main site is, so cant track links to it
$origDisableSubsiteFilter = Subsite::$disable_subsite_filter; $origDisableSubsiteFilter = Subsite::$disable_subsite_filter;
Subsite::disable_subsite_filter(true); Subsite::disable_subsite_filter(true);
$candidatePage = DataObject::get_one("SiteTree", "\"URLSegment\" = '" . Convert::raw2sql(urldecode( $rest)) . "' AND \"SubsiteID\" = " . $subsiteID, false); $candidatePage = DataObject::get_one("SilverStripe\\CMS\\Model\\SiteTree", "\"URLSegment\" = '" . Convert::raw2sql(urldecode( $rest)) . "' AND \"SubsiteID\" = " . $subsiteID, false);
Subsite::disable_subsite_filter($origDisableSubsiteFilter); Subsite::disable_subsite_filter($origDisableSubsiteFilter);
if($candidatePage) { if($candidatePage) {
$linkedPages[] = $candidatePage->ID; $linkedPages[] = $candidatePage->ID;
} else { } else {
@ -317,17 +331,17 @@ class SiteTreeSubsites extends DataExtension {
} }
} }
} }
$this->owner->CrossSubsiteLinkTracking()->setByIDList($linkedPages); $this->owner->CrossSubsiteLinkTracking()->setByIDList($linkedPages);
} }
/** /**
* Return a piece of text to keep DataObject cache keys appropriately specific * Return a piece of text to keep DataObject cache keys appropriately specific
*/ */
function cacheKeyComponent() { function cacheKeyComponent() {
return 'subsite-'.Subsite::currentSubsiteID(); return 'subsite-'.Subsite::currentSubsiteID();
} }
/** /**
* @param Member * @param Member
* @return boolean|null * @return boolean|null

View File

@ -1,5 +1,7 @@
<?php <?php
use SilverStripe\Core\Extension;
/* /*
* Simple extension to show admins in the menu of subsites. * Simple extension to show admins in the menu of subsites.
* If an admin area should be available to a subsite, you can attach * If an admin area should be available to a subsite, you can attach

View File

@ -1,4 +1,8 @@
<?php <?php
use SilverStripe\Forms\GridField\GridFieldDetailForm;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\GridField\GridFieldDetailForm_ItemRequest;
class GridFieldSubsiteDetailForm extends GridFieldDetailForm { class GridFieldSubsiteDetailForm extends GridFieldDetailForm {
protected $itemRequestClass='GridFieldSubsiteDetailForm_ItemRequest'; protected $itemRequestClass='GridFieldSubsiteDetailForm_ItemRequest';
} }

View File

@ -1,4 +1,9 @@
<?php <?php
use SilverStripe\View\Requirements;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Session;
use SilverStripe\Forms\TreeDropdownField;
/** /**
* Wraps around a TreedropdownField to add ability for temporary * Wraps around a TreedropdownField to add ability for temporary
* switching of subsite sessions. * switching of subsite sessions.
@ -31,7 +36,7 @@ class SubsitesTreeDropdownField extends TreeDropdownField {
return $this->subsiteID; return $this->subsiteID;
} }
function tree(SS_HTTPRequest $request) { function tree(HTTPRequest $request) {
$oldSubsiteID = Session::get('SubsiteID'); $oldSubsiteID = Session::get('SubsiteID');
Session::set('SubsiteID', $this->subsiteID); Session::set('SubsiteID', $this->subsiteID);

View File

@ -1,4 +1,31 @@
<?php <?php
use SilverStripe\ORM\DataObject;
use SilverStripe\Control\Session;
use SilverStripe\i18n\i18n;
use SilverStripe\Security\Permission;
use SilverStripe\Security\Member;
use SilverStripe\Core\Convert;
use SilverStripe\ORM\ArrayList;
use SilverStripe\Admin\CMSMenu;
use SilverStripe\ORM\DataList;
use SilverStripe\Control\Director;
use SilverStripe\ORM\DB;
use SilverStripe\Forms\GridField\GridFieldConfig_RecordEditor;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\Forms\HeaderField;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\CheckboxSetField;
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\FieldList;
use SilverStripe\ORM\ArrayLib;
use SilverStripe\ORM\Versioning\Versioned;
/** /**
* A dynamically created subsite. SiteTree objects can now belong to a subsite. * A dynamically created subsite. SiteTree objects can now belong to a subsite.
* You can simulate subsite access without setting up virtual hosts by appending ?SubsiteID=<ID> to the request. * You can simulate subsite access without setting up virtual hosts by appending ?SubsiteID=<ID> to the request.
@ -9,8 +36,8 @@ class Subsite extends DataObject {
/** /**
* @var $use_session_subsiteid Boolean Set to TRUE when using the CMS and FALSE * @var $use_session_subsiteid Boolean Set to TRUE when using the CMS and FALSE
* when browsing the frontend of a website. * when browsing the frontend of a website.
* *
* @todo Remove flag once the Subsite CMS works without session state, * @todo Remove flag once the Subsite CMS works without session state,
* similarly to the Translatable module. * similarly to the Translatable module.
*/ */
@ -21,7 +48,7 @@ class Subsite extends DataObject {
* to limit DataObject::get*() calls to a specific subsite. Useful for debugging. * to limit DataObject::get*() calls to a specific subsite. Useful for debugging.
*/ */
public static $disable_subsite_filter = false; public static $disable_subsite_filter = false;
/** /**
* Allows you to force a specific subsite ID, or comma separated list of IDs. * Allows you to force a specific subsite ID, or comma separated list of IDs.
* Only works for reading. An object cannot be written to more than 1 subsite. * Only works for reading. An object cannot be written to more than 1 subsite.
@ -33,10 +60,10 @@ class Subsite extends DataObject {
* @var boolean * @var boolean
*/ */
public static $write_hostmap = true; public static $write_hostmap = true;
/** /**
* Memory cache of accessible sites * Memory cache of accessible sites
* *
* @array * @array
*/ */
private static $_cache_accessible_sites = array(); private static $_cache_accessible_sites = array();
@ -54,7 +81,7 @@ class Subsite extends DataObject {
* are listed. * are listed.
*/ */
private static $allowed_themes = array(); private static $allowed_themes = array();
/** /**
* @var Boolean If set to TRUE, don't assume 'www.example.com' and 'example.com' are the same. * @var Boolean If set to TRUE, don't assume 'www.example.com' and 'example.com' are the same.
* Doesn't affect wildcard matching, so '*.example.com' will match 'www.example.com' (but not 'example.com') * Doesn't affect wildcard matching, so '*.example.com' will match 'www.example.com' (but not 'example.com')
@ -78,13 +105,13 @@ class Subsite extends DataObject {
/** /**
* Set allowed themes * Set allowed themes
* *
* @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;
} }
/** /**
* Gets the subsite currently set in the session. * Gets the subsite currently set in the session.
* *
@ -124,7 +151,7 @@ class Subsite extends DataObject {
return (int)$id; return (int)$id;
} }
/** /**
* Switch to another subsite through storing the subsite identifier in the current PHP session. * 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. * Only takes effect when {@link Subsite::$use_session_subsiteid} is set to TRUE.
@ -151,13 +178,13 @@ class Subsite extends DataObject {
Permission::flush_permission_cache(); Permission::flush_permission_cache();
} }
/** /**
* Get a matching subsite for the given host, or for the current 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, * 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, * for example matching all subdomains on *.example.com with one subsite,
* and all subdomains on *.example.org on another. * 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. * @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
*/ */
@ -176,7 +203,7 @@ class Subsite extends DataObject {
$SQL_host = Convert::raw2sql($host); $SQL_host = Convert::raw2sql($host);
$matchingDomains = DataObject::get( $matchingDomains = DataObject::get(
"SubsiteDomain", "SubsiteDomain",
"'$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");
@ -210,7 +237,7 @@ class Subsite extends DataObject {
} }
/** /**
* *
* @param string $className * @param string $className
* @param string $filter * @param string $filter
* @param string $sort * @param string $sort
@ -230,7 +257,7 @@ class Subsite extends DataObject {
public static function disable_subsite_filter($disabled = true) { public static function disable_subsite_filter($disabled = true) {
self::$disable_subsite_filter = $disabled; self::$disable_subsite_filter = $disabled;
} }
/** /**
* Flush caches on database reset * Flush caches on database reset
*/ */
@ -238,7 +265,7 @@ class Subsite extends DataObject {
self::$_cache_accessible_sites = array(); self::$_cache_accessible_sites = array();
self::$_cache_subsite_for_domain = array(); self::$_cache_subsite_for_domain = array();
} }
/** /**
* Return all subsites, regardless of permissions (augmented with main site). * Return all subsites, regardless of permissions (augmented with main site).
* *
@ -270,7 +297,7 @@ class Subsite extends DataObject {
// Rationalise member arguments // Rationalise member arguments
if(!$member) $member = Member::currentUser(); if(!$member) $member = Member::currentUser();
if(!$member) return new ArrayList(); if(!$member) return new ArrayList();
if(!is_object($member)) $member = DataObject::get_by_id('Member', $member); if(!is_object($member)) $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
$subsites = new ArrayList(); $subsites = new ArrayList();
@ -308,12 +335,12 @@ class Subsite extends DataObject {
// Rationalise member arguments // Rationalise member arguments
if(!$member) $member = Member::currentUser(); if(!$member) $member = Member::currentUser();
if(!$member) return new ArrayList(); if(!$member) return new ArrayList();
if(!is_object($member)) $member = DataObject::get_by_id('Member', $member); if(!is_object($member)) $member = DataObject::get_by_id('SilverStripe\\Security\\Member', $member);
// Rationalise permCode argument // Rationalise permCode argument
if(is_array($permCode)) $SQL_codes = "'" . implode("', '", Convert::raw2sql($permCode)) . "'"; if(is_array($permCode)) $SQL_codes = "'" . implode("', '", Convert::raw2sql($permCode)) . "'";
else $SQL_codes = "'" . 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;
if(isset(self::$_cache_accessible_sites[$cacheKey])) { if(isset(self::$_cache_accessible_sites[$cacheKey])) {
@ -352,19 +379,19 @@ class Subsite extends DataObject {
if(!is_array($permCode)) $permCode = array($permCode); if(!is_array($permCode)) $permCode = array($permCode);
if(self::hasMainSitePermission($member, $permCode)) { if(self::hasMainSitePermission($member, $permCode)) {
$subsites=$subsites->toArray(); $subsites=$subsites->toArray();
$mainSite = new Subsite(); $mainSite = new Subsite();
$mainSite->Title = $mainSiteTitle; $mainSite->Title = $mainSiteTitle;
array_unshift($subsites, $mainSite); array_unshift($subsites, $mainSite);
$subsites=ArrayList::create($subsites); $subsites=ArrayList::create($subsites);
} }
} }
self::$_cache_accessible_sites[$cacheKey] = $subsites; self::$_cache_accessible_sites[$cacheKey] = $subsites;
return $subsites; return $subsites;
} }
/** /**
* Write a host->domain map to subsites/host-map.php * Write a host->domain map to subsites/host-map.php
* *
@ -375,22 +402,22 @@ class Subsite extends DataObject {
*/ */
public static function writeHostMap($file = null) { public static function writeHostMap($file = null) {
if (!self::$write_hostmap) return; if (!self::$write_hostmap) return;
if (!$file) $file = Director::baseFolder().'/subsites/host-map.php'; if (!$file) $file = Director::baseFolder().'/subsites/host-map.php';
$hostmap = array(); $hostmap = array();
$subsites = DataObject::get('Subsite'); $subsites = DataObject::get('Subsite');
if ($subsites) foreach($subsites as $subsite) { if ($subsites) foreach($subsites as $subsite) {
$domains = $subsite->Domains(); $domains = $subsite->Domains();
if ($domains) foreach($domains as $domain) { if ($domains) foreach($domains as $domain) {
$domainStr = $domain->Domain; $domainStr = $domain->Domain;
if(!self::$strict_subdomain_matching) $domainStr = preg_replace('/^www\./', '', $domainStr); if(!self::$strict_subdomain_matching) $domainStr = preg_replace('/^www\./', '', $domainStr);
$hostmap[$domainStr] = $subsite->domain(); $hostmap[$domainStr] = $subsite->domain();
} }
if ($subsite->DefaultSite) $hostmap['default'] = $subsite->domain(); if ($subsite->DefaultSite) $hostmap['default'] = $subsite->domain();
} }
$data = "<?php \n"; $data = "<?php \n";
$data .= "// Generated by Subsite::writeHostMap() on " . date('d/M/y') . "\n"; $data .= "// Generated by Subsite::writeHostMap() on " . date('d/M/y') . "\n";
$data .= '$subsiteHostmap = ' . var_export($hostmap, true) . ';'; $data .= '$subsiteHostmap = ' . var_export($hostmap, true) . ';';
@ -399,16 +426,16 @@ class Subsite extends DataObject {
file_put_contents($file, $data); file_put_contents($file, $data);
} }
} }
/** /**
* Checks if a member can be granted certain permissions, regardless of the subsite context. * Checks if a member can be granted certain permissions, regardless of the subsite context.
* Similar logic to {@link Permission::checkMember()}, but only returns TRUE * Similar logic to {@link Permission::checkMember()}, but only returns TRUE
* if the member is part of a group with the "AccessAllSubsites" flag set. * if the member is part of a group with the "AccessAllSubsites" flag set.
* If more than one permission is passed to the method, at least one of them must * If more than one permission is passed to the method, at least one of them must
* be granted for if to return TRUE. * be granted for if to return TRUE.
* *
* @todo Allow permission inheritance through group hierarchy. * @todo Allow permission inheritance through group hierarchy.
* *
* @param Member Member to check against. Defaults to currently logged in member * @param Member Member to check against. Defaults to currently logged in member
* @param Array Permission code strings. Defaults to "ADMIN". * @param Array Permission code strings. Defaults to "ADMIN".
* @return boolean * @return boolean
@ -420,13 +447,13 @@ class Subsite extends DataObject {
if(!$member && $member !== FALSE) $member = Member::currentUser(); if(!$member && $member !== FALSE) $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);
$memberID = (int)$member->ID; $memberID = (int)$member->ID;
// Count this user's groups which can access the main site // Count this user's groups which can access the main site
$groupCount = DB::query(" $groupCount = DB::query("
SELECT COUNT(\"Permission\".\"ID\") SELECT COUNT(\"Permission\".\"ID\")
@ -453,7 +480,7 @@ class Subsite extends DataObject {
// There has to be at least one that allows access. // There has to be at least one that allows access.
return ($groupCount + $roleCount > 0); return ($groupCount + $roleCount > 0);
} }
/** /**
* *
* @var array * @var array
@ -468,7 +495,7 @@ class Subsite extends DataObject {
// Used to hide unfinished/private subsites from public view. // Used to hide unfinished/private subsites from public view.
// If unset, will default to true // If unset, will default to true
'IsPublic' => 'Boolean', 'IsPublic' => 'Boolean',
// Comma-separated list of disallowed page types // Comma-separated list of disallowed page types
'PageTypeBlacklist' => 'Text', 'PageTypeBlacklist' => 'Text',
); );
@ -480,13 +507,13 @@ class Subsite extends DataObject {
private static $has_many = array( private static $has_many = array(
'Domains' => 'SubsiteDomain', 'Domains' => 'SubsiteDomain',
); );
/** /**
* *
* @var array * @var array
*/ */
private static $belongs_many_many = array( private static $belongs_many_many = array(
"Groups" => "Group", "Groups" => "SilverStripe\\Security\\Group",
); );
/** /**
@ -504,15 +531,15 @@ class Subsite extends DataObject {
private static $searchable_fields = array( private static $searchable_fields = array(
'Title', 'Title',
'Domains.Domain', 'Domains.Domain',
'IsPublic', 'IsPublic',
); );
/** /**
* *
* @var string * @var string
*/ */
private static $default_sort = "\"Title\" ASC"; private static $default_sort = "\"Title\" ASC";
/** /**
* @todo Possible security issue, don't grant edit permissions to everybody. * @todo Possible security issue, don't grant edit permissions to everybody.
* @return boolean * @return boolean
@ -523,30 +550,30 @@ class Subsite extends DataObject {
/** /**
* Show the configuration fields for each subsite * Show the configuration fields for each subsite
* *
* @return FieldList * @return FieldList
*/ */
public function getCMSFields() { public function getCMSFields() {
if($this->ID!=0) { if($this->ID!=0) {
$domainTable = new GridField( $domainTable = new GridField(
"Domains", "Domains",
_t('Subsite.DomainsListTitle',"Domains"), _t('Subsite.DomainsListTitle',"Domains"),
$this->Domains(), $this->Domains(),
GridFieldConfig_RecordEditor::create(10) GridFieldConfig_RecordEditor::create(10)
); );
}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>'
); );
} }
$languageSelector = new DropdownField( $languageSelector = new DropdownField(
'Language', 'Language',
$this->fieldLabel('Language'), $this->fieldLabel('Language'),
i18n::get_common_locales() i18n::get_common_locales()
); );
$pageTypeMap = array(); $pageTypeMap = array();
$pageTypes = SiteTree::page_type_classes(); $pageTypes = SiteTree::page_type_classes();
foreach($pageTypes as $pageType) { foreach($pageTypes as $pageType) {
@ -559,11 +586,12 @@ class Subsite extends DataObject {
new Tab( new Tab(
'Configuration', 'Configuration',
_t('Subsite.TabTitleConfig', 'Configuration'), _t('Subsite.TabTitleConfig', 'Configuration'),
new HeaderField($this->getClassName() . ' configuration', 2), new HeaderField('ConfigurationHeader', $this->getClassName() . ' configuration', 2),
new TextField('Title', $this->fieldLabel('Title'), $this->Title), new TextField('Title', $this->fieldLabel('Title'), $this->Title),
new HeaderField( new HeaderField(
_t('Subsite.DomainsHeadline',"Domains for this subsite") 'DomainsHeader',
_t('Subsite.DomainsHeadline', "Domains for this subsite")
), ),
$domainTable, $domainTable,
$languageSelector, $languageSelector,
@ -572,8 +600,8 @@ class Subsite extends DataObject {
new CheckboxField('IsPublic', $this->fieldLabel('IsPublic'), $this->IsPublic), 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( new LiteralField(
'PageTypeBlacklistToggle', 'PageTypeBlacklistToggle',
sprintf( sprintf(
@ -582,7 +610,7 @@ class Subsite extends DataObject {
) )
), ),
new CheckboxSetField( new CheckboxSetField(
'PageTypeBlacklist', 'PageTypeBlacklist',
false, false,
$pageTypeMap $pageTypeMap
) )
@ -597,9 +625,9 @@ class Subsite extends DataObject {
$this->extend('updateCMSFields', $fields); $this->extend('updateCMSFields', $fields);
return $fields; return $fields;
} }
/** /**
* *
* @param boolean $includerelations * @param boolean $includerelations
* @return array * @return array
*/ */
@ -617,10 +645,10 @@ class Subsite extends DataObject {
return $labels; return $labels;
} }
/** /**
* 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() {
@ -652,7 +680,7 @@ class Subsite extends DataObject {
} }
/** /**
* *
* @return ValidationResult * @return ValidationResult
*/ */
public function validate() { public function validate() {
@ -672,11 +700,11 @@ class Subsite extends DataObject {
Subsite::writeHostMap(); Subsite::writeHostMap();
parent::onAfterWrite(); parent::onAfterWrite();
} }
/** /**
* Return the primary domain of this site. Tries to "normalize" the domain name, * Return the primary domain of this site. Tries to "normalize" the domain name,
* by replacing potential wildcards. * by replacing potential wildcards.
* *
* @return string The full domain name of this subsite (without protocol prefix) * @return string The full domain name of this subsite (without protocol prefix)
*/ */
public function domain() { public function domain() {
@ -692,18 +720,18 @@ class Subsite extends DataObject {
$domain = preg_replace('/^\*\./',"subsite.", $domain); $domain = preg_replace('/^\*\./',"subsite.", $domain);
// *Only* removes "intermediate" subdomains, so 'subdomain.www.domain.com' becomes 'subdomain.domain.com' // *Only* removes "intermediate" subdomains, so 'subdomain.www.domain.com' becomes 'subdomain.domain.com'
$domain = str_replace('.www.','.', $domain); $domain = str_replace('.www.','.', $domain);
return $domain; return $domain;
} }
// SubsiteID = 0 is often used to refer to the main site, just return $_SERVER['HTTP_HOST'] // SubsiteID = 0 is often used to refer to the main site, just return $_SERVER['HTTP_HOST']
} else { } else {
return $_SERVER['HTTP_HOST']; return $_SERVER['HTTP_HOST'];
} }
} }
/** /**
* *
* @return string - The full domain name of this subsite (without protocol prefix) * @return string - The full domain name of this subsite (without protocol prefix)
*/ */
public function getPrimaryDomain() { public function getPrimaryDomain() {
@ -711,8 +739,8 @@ class Subsite extends DataObject {
} }
/** /**
* *
* @return string * @return string
*/ */
public function absoluteBaseURL() { public function absoluteBaseURL() {
return "http://" . $this->domain() . Director::baseURL(); return "http://" . $this->domain() . Director::baseURL();
@ -727,8 +755,8 @@ class Subsite extends DataObject {
/** /**
* Javascript admin action to duplicate this subsite * Javascript admin action to duplicate this subsite
* *
* @return string - javascript * @return string - javascript
*/ */
public function adminDuplicate() { public function adminDuplicate() {
$newItem = $this->duplicate(); $newItem = $this->duplicate();
@ -737,7 +765,7 @@ class Subsite extends DataObject {
'Created a copy of {title}', 'Created a copy of {title}',
array('title' => Convert::raw2js($this->Title)) array('title' => Convert::raw2js($this->Title))
); );
return <<<JS return <<<JS
statusMessage($message, 'good'); statusMessage($message, 'good');
$('Form_EditForm').loadURLFromServer('admin/subsites/show/$newItem->ID'); $('Form_EditForm').loadURLFromServer('admin/subsites/show/$newItem->ID');
@ -752,7 +780,7 @@ JS;
} }
/** /**
* *
* @param array $permissionCodes * @param array $permissionCodes
* @return DataList * @return DataList
*/ */
@ -764,14 +792,14 @@ JS;
$SQL_permissionCodes = join("','", $SQL_permissionCodes); $SQL_permissionCodes = join("','", $SQL_permissionCodes);
return DataObject::get( return DataObject::get(
'Member', 'SilverStripe\\Security\\Member',
"\"Group\".\"SubsiteID\" = $this->ID AND \"Permission\".\"Code\" IN ('$SQL_permissionCodes')", "\"Group\".\"SubsiteID\" = $this->ID AND \"Permission\".\"Code\" IN ('$SQL_permissionCodes')",
'', '',
"LEFT JOIN \"Group_Members\" ON \"Member\".\"ID\" = \"Group_Members\".\"MemberID\" "LEFT JOIN \"Group_Members\" ON \"Member\".\"ID\" = \"Group_Members\".\"MemberID\"
LEFT JOIN \"Group\" ON \"Group\".\"ID\" = \"Group_Members\".\"GroupID\" LEFT JOIN \"Group\" ON \"Group\".\"ID\" = \"Group_Members\".\"GroupID\"
LEFT JOIN \"Permission\" ON \"Permission\".\"GroupID\" = \"Group\".\"ID\"" LEFT JOIN \"Permission\" ON \"Permission\".\"GroupID\" = \"Group\".\"ID\""
); );
} }
/** /**
@ -797,7 +825,7 @@ JS;
if($children) { if($children) {
foreach($children as $child) { foreach($children as $child) {
self::changeSubsite($duplicate->ID); //Change to destination subsite self::changeSubsite($duplicate->ID); //Change to destination subsite
$childClone = $child->duplicateToSubsite($duplicate, false); $childClone = $child->duplicateToSubsite($duplicate, false);
$childClone->ParentID = $destParentID; $childClone->ParentID = $destParentID;
$childClone->writeToStage('Stage'); $childClone->writeToStage('Stage');

View File

@ -1,5 +1,11 @@
<?php <?php
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\FieldList;
use SilverStripe\Core\Convert;
use SilverStripe\ORM\DataObject;
/** /**
* @property text Domain domain name of this subsite. Do not include the URL scheme here * @property text Domain domain name of this subsite. Do not include the URL scheme here
* @property bool IsPrimary Is this the primary subdomain? * @property bool IsPrimary Is this the primary subdomain?

View File

@ -1,4 +1,8 @@
<?php <?php
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\Versioning\Versioned;
use SilverStripe\Dev\BuildTask;
/** /**
* Handy alternative to copying pages when creating a subsite through the UI. * Handy alternative to copying pages when creating a subsite through the UI.
* Can be used to batch-add new pages after subsite creation, * Can be used to batch-add new pages after subsite creation,
@ -35,7 +39,7 @@ class SubsiteCopyPagesTask extends BuildTask {
while(count($stack) > 0) { while(count($stack) > 0) {
list($sourceParentID, $destParentID) = array_pop($stack); list($sourceParentID, $destParentID) = array_pop($stack);
$children = Versioned::get_by_stage('SiteTree', 'Live', "\"ParentID\" = $sourceParentID", ''); $children = Versioned::get_by_stage('SilverStripe\\CMS\\Model\\SiteTree', 'Live', "\"ParentID\" = $sourceParentID", '');
if($children) { if($children) {
foreach($children as $child) { foreach($children as $child) {

View File

@ -12,7 +12,8 @@
"require": "require":
{ {
"silverstripe/framework": "~4.0", "silverstripe/framework": "~4.0",
"silverstripe/cms": "~4.0" "silverstripe/cms": "~4.0",
"silverstripe/asset-admin": "~1.0.0"
}, },
"require-dev": { "require-dev": {
"phpunit/PHPUnit": "~3.7@stable" "phpunit/PHPUnit": "~3.7@stable"

View File

@ -25,12 +25,17 @@
} }
.cms-menu .cms-subsites{ .cms-menu .cms-subsites{
padding:3px 0px 15px; padding: 0 8px 12px;
} }
.cms-menu .cms-subsites .field.dropdown{ .cms-menu .cms-subsites .field.dropdown{
padding-bottom:0; padding-bottom:0;
margin-bottom:0; margin-bottom:0;
} }
.cms-menu .cms-subsites .field.dropdown span {
color: #4f5861;
}
.cms-menu.collapsed .cms-subsites { .cms-menu.collapsed .cms-subsites {
display: none; display: none;
} }

View File

@ -1,45 +0,0 @@
<div class="cms-menu cms-panel cms-panel-layout west" id="cms-menu" data-layout-type="border">
<div class="cms-logo-header north">
<div class="cms-logo">
<a href="$ApplicationLink" target="_blank" title="$ApplicationName (Version - $CMSVersion)">
$ApplicationName <% if $CMSVersion %><abbr class="version">$CMSVersion</abbr><% end_if %>
</a>
<span><% if $SiteConfig %>$SiteConfig.Title<% else %>$ApplicationName<% end_if %></span>
</div>
<div class="cms-login-status">
<a href="$LogoutURL" class="logout-link font-icon-logout" title="<%t LeftAndMain_Menu_ss.LOGOUT 'Log out' %>"></a>
<% with $CurrentMember %>
<span>
<%t LeftAndMain_Menu_ss.Hello 'Hi' %>
<a href="{$AbsoluteBaseURL}admin/myprofile" class="profile-link">
<% if $FirstName && $Surname %>$FirstName $Surname<% else_if $FirstName %>$FirstName<% else %>$Email<% end_if %>
</a>
</span>
<% end_with %>
</div>
<% if $ListSubsites %>
<% include SubsiteList %>
<% end_if %>
</div>
<div class="cms-panel-content center">
<ul class="cms-menu-list">
<% loop $MainMenu %>
<li class="$LinkingMode $FirstLast <% if $LinkingMode == 'link' %><% else %>opened<% end_if %>" id="Menu-$Code" title="$Title.ATT">
<a href="$Link" <% if $Code == 'Help' %>target="_blank"<% end_if %>>
<span class="icon icon-16 icon-{$Code.LowerCase}">&nbsp;</span>
<span class="text">$Title</span>
</a>
</li>
<% end_loop %>
</ul>
</div>
<div class="cms-panel-toggle south">
<button class="sticky-toggle" type="button" title="Sticky nav">Sticky nav</button>
<span class="sticky-status-indicator">auto</span>
<a class="toggle-expand" href="#"><span>&raquo;</span></a>
<a class="toggle-collapse" href="#"><span>&laquo;</span></a>
</div>
</div>

View File

@ -0,0 +1,18 @@
<div class="cms-menu cms-panel cms-panel-layout west" id="cms-menu" data-layout-type="border">
<div class="cms-logo-header north">
<% include SilverStripe\\Admin\\LeftAndMain_MenuLogo %>
<% include SilverStripe\\Admin\\LeftAndMain_MenuStatus %>
<% if $ListSubsites %>
<% include SubsiteList %>
<% end_if %>
</div>
<div class="panel panel--scrollable panel--triple-toolbar cms-panel-content">
<% include SilverStripe\\Admin\\LeftAndMain_MenuList %>
</div>
<div class="toolbar toolbar--south cms-panel-toggle">
<% include SilverStripe\\Admin\\LeftAndMain_MenuToggle %>
</div>
</div>

View File

@ -1,4 +1,6 @@
<?php <?php
use SilverStripe\Dev\SapphireTest;
class BaseSubsiteTest extends SapphireTest { class BaseSubsiteTest extends SapphireTest {
function setUp() { function setUp() {

View File

@ -1,5 +1,9 @@
<?php <?php
use SilverStripe\Assets\File;
use SilverStripe\Forms\FieldList;
use SilverStripe\Assets\Folder;
class FileSubsitesTest extends BaseSubsiteTest { class FileSubsitesTest extends BaseSubsiteTest {
static $fixture_file = 'subsites/tests/SubsiteTest.yml'; static $fixture_file = 'subsites/tests/SubsiteTest.yml';
@ -11,13 +15,13 @@ class FileSubsitesTest extends BaseSubsiteTest {
$this->assertEquals(' * FileTitle', $file->alternateTreeTitle()); $this->assertEquals(' * FileTitle', $file->alternateTreeTitle());
$file->SubsiteID = $this->objFromFixture('Subsite', 'domaintest1')->ID; $file->SubsiteID = $this->objFromFixture('Subsite', 'domaintest1')->ID;
$this->assertEquals('FileTitle', $file->getTreeTitle()); $this->assertEquals('FileTitle', $file->getTreeTitle());
$this->assertTrue(singleton('Folder')->getCMSFields() instanceof FieldList); $this->assertTrue(singleton('SilverStripe\\Assets\\Folder')->getCMSFields() instanceof FieldList);
Subsite::changeSubsite(1); Subsite::changeSubsite(1);
$this->assertEquals($file->cacheKeyComponent(), 'subsite-1'); $this->assertEquals($file->cacheKeyComponent(), 'subsite-1');
} }
function testWritingSubsiteID() { function testWritingSubsiteID() {
$this->objFromFixture('Member', 'admin')->logIn(); $this->objFromFixture('SilverStripe\\Security\\Member', 'admin')->logIn();
$subsite = $this->objFromFixture('Subsite', 'domaintest1'); $subsite = $this->objFromFixture('Subsite', 'domaintest1');
FileSubsites::$default_root_folders_global = true; FileSubsites::$default_root_folders_global = true;
@ -55,7 +59,7 @@ class FileSubsitesTest extends BaseSubsiteTest {
} }
function testSubsitesFolderDropdown() { function testSubsitesFolderDropdown() {
$this->objFromFixture('Member', 'admin')->logIn(); $this->objFromFixture('SilverStripe\\Security\\Member', 'admin')->logIn();
$file = new Folder(); $file = new Folder();

View File

@ -1,5 +1,8 @@
<?php <?php
use SilverStripe\Forms\FieldList;
use SilverStripe\Security\Group;
class GroupSubsitesTest extends BaseSubsiteTest { class GroupSubsitesTest extends BaseSubsiteTest {
static $fixture_file = 'subsites/tests/SubsiteTest.yml'; static $fixture_file = 'subsites/tests/SubsiteTest.yml';
@ -8,7 +11,7 @@ class GroupSubsitesTest extends BaseSubsiteTest {
function testTrivialFeatures() { function testTrivialFeatures() {
$this->assertTrue(is_array(singleton('GroupSubsites')->extraStatics())); $this->assertTrue(is_array(singleton('GroupSubsites')->extraStatics()));
$this->assertTrue(is_array(singleton('GroupSubsites')->providePermissions())); $this->assertTrue(is_array(singleton('GroupSubsites')->providePermissions()));
$this->assertTrue(singleton('Group')->getCMSFields() instanceof FieldList); $this->assertTrue(singleton('SilverStripe\\Security\\Group')->getCMSFields() instanceof FieldList);
} }
function testAlternateTreeTitle() { function testAlternateTreeTitle() {

View File

@ -1,5 +1,9 @@
<?php <?php
use SilverStripe\Admin\LeftAndMain;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest;
class LeftAndMainSubsitesTest extends FunctionalTest { class LeftAndMainSubsitesTest extends FunctionalTest {
static $fixture_file = 'subsites/tests/SubsiteTest.yml'; static $fixture_file = 'subsites/tests/SubsiteTest.yml';
@ -16,9 +20,9 @@ class LeftAndMainSubsitesTest extends FunctionalTest {
} }
function testSectionSites() { function testSectionSites() {
$member = $this->objFromFixture('Member', 'subsite1member'); $member = $this->objFromFixture('SilverStripe\\Security\\Member', 'subsite1member');
$cmsmain = singleton('CMSMain'); $cmsmain = singleton('SilverStripe\\CMS\\Controllers\\CMSMain');
$subsites = $cmsmain->sectionSites(true, "Main site", $member); $subsites = $cmsmain->sectionSites(true, "Main site", $member);
$this->assertDOSEquals(array( $this->assertDOSEquals(array(
array('Title' =>'Subsite1 Template') array('Title' =>'Subsite1 Template')
@ -28,9 +32,9 @@ class LeftAndMainSubsitesTest extends FunctionalTest {
$subsites = $assetadmin->sectionSites(true, "Main site", $member); $subsites = $assetadmin->sectionSites(true, "Main site", $member);
$this->assertDOSEquals(array(), $subsites, 'Does not list any sites for forbidden controller.'); $this->assertDOSEquals(array(), $subsites, 'Does not list any sites for forbidden controller.');
$member = $this->objFromFixture('Member', 'editor'); $member = $this->objFromFixture('SilverStripe\\Security\\Member', 'editor');
$cmsmain = singleton('CMSMain'); $cmsmain = singleton('SilverStripe\\CMS\\Controllers\\CMSMain');
$subsites = $cmsmain->sectionSites(true, "Main site", $member); $subsites = $cmsmain->sectionSites(true, "Main site", $member);
$this->assertDOSContains(array( $this->assertDOSContains(array(
array('Title' =>'Main site') array('Title' =>'Main site')
@ -38,7 +42,7 @@ class LeftAndMainSubsitesTest extends FunctionalTest {
} }
function testAccessChecksDontChangeCurrentSubsite() { function testAccessChecksDontChangeCurrentSubsite() {
$admin = $this->objFromFixture("Member","admin"); $admin = $this->objFromFixture("SilverStripe\\Security\\Member","admin");
$this->loginAs($admin); $this->loginAs($admin);
$ids = array(); $ids = array();
@ -70,17 +74,17 @@ class LeftAndMainSubsitesTest extends FunctionalTest {
$l = new LeftAndMain(); $l = new LeftAndMain();
Config::inst()->nest(); Config::inst()->nest();
Config::inst()->update('CMSPageEditController', 'treats_subsite_0_as_global', false); Config::inst()->update('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 'treats_subsite_0_as_global', false);
$this->assertTrue($l->shouldChangeSubsite('CMSPageEditController', 0, 5)); $this->assertTrue($l->shouldChangeSubsite('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 0, 5));
$this->assertFalse($l->shouldChangeSubsite('CMSPageEditController', 0, 0)); $this->assertFalse($l->shouldChangeSubsite('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 0, 0));
$this->assertTrue($l->shouldChangeSubsite('CMSPageEditController', 1, 5)); $this->assertTrue($l->shouldChangeSubsite('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 1, 5));
$this->assertFalse($l->shouldChangeSubsite('CMSPageEditController', 1, 1)); $this->assertFalse($l->shouldChangeSubsite('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 1, 1));
Config::inst()->update('CMSPageEditController', 'treats_subsite_0_as_global', true); Config::inst()->update('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 'treats_subsite_0_as_global', true);
$this->assertFalse($l->shouldChangeSubsite('CMSPageEditController', 0, 5)); $this->assertFalse($l->shouldChangeSubsite('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 0, 5));
$this->assertFalse($l->shouldChangeSubsite('CMSPageEditController', 0, 0)); $this->assertFalse($l->shouldChangeSubsite('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 0, 0));
$this->assertTrue($l->shouldChangeSubsite('CMSPageEditController', 1, 5)); $this->assertTrue($l->shouldChangeSubsite('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 1, 5));
$this->assertFalse($l->shouldChangeSubsite('CMSPageEditController', 1, 1)); $this->assertFalse($l->shouldChangeSubsite('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 1, 1));
Config::inst()->unnest(); Config::inst()->unnest();
} }

View File

@ -1,5 +1,7 @@
<?php <?php
use SilverStripe\SiteConfig\SiteConfig;
class SiteConfigSubsitesTest extends BaseSubsiteTest { class SiteConfigSubsitesTest extends BaseSubsiteTest {
static $fixture_file = 'subsites/tests/SubsiteTest.yml'; static $fixture_file = 'subsites/tests/SubsiteTest.yml';

View File

@ -1,9 +1,18 @@
<?php <?php
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\Forms\FieldList;
use SilverStripe\Control\Session;
use SilverStripe\CMS\Controllers\CMSMain;
use SilverStripe\Core\Convert;
use SilverStripe\Dev\TestOnly;
use SilverStripe\CMS\Model\ErrorPage;
class SiteTreeSubsitesTest extends BaseSubsiteTest { class SiteTreeSubsitesTest extends BaseSubsiteTest {
static $fixture_file = 'subsites/tests/SubsiteTest.yml'; static $fixture_file = 'subsites/tests/SubsiteTest.yml';
protected $extraDataObjects = array( protected $extraDataObjects = array(
'SiteTreeSubsitesTest_ClassA', 'SiteTreeSubsitesTest_ClassA',
'SiteTreeSubsitesTest_ClassB', 'SiteTreeSubsitesTest_ClassB',
@ -11,89 +20,89 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest {
); );
protected $illegalExtensions = array( protected $illegalExtensions = array(
'SiteTree' => array('Translatable') 'SilverStripe\CMS\Model\SiteTree' => array('Translatable')
); );
function testPagesInDifferentSubsitesCanShareURLSegment() { function testPagesInDifferentSubsitesCanShareURLSegment() {
$subsiteMain = $this->objFromFixture('Subsite', 'main'); $subsiteMain = $this->objFromFixture('Subsite', 'main');
$subsite1 = $this->objFromFixture('Subsite', 'subsite1'); $subsite1 = $this->objFromFixture('Subsite', 'subsite1');
$pageMain = new SiteTree(); $pageMain = new SiteTree();
$pageMain->URLSegment = 'testpage'; $pageMain->URLSegment = 'testpage';
$pageMain->write(); $pageMain->write();
$pageMain->publish('Stage', 'Live'); $pageMain->publish('Stage', 'Live');
$pageMainOther = new SiteTree(); $pageMainOther = new SiteTree();
$pageMainOther->URLSegment = 'testpage'; $pageMainOther->URLSegment = 'testpage';
$pageMainOther->write(); $pageMainOther->write();
$pageMainOther->publish('Stage', 'Live'); $pageMainOther->publish('Stage', 'Live');
$this->assertNotEquals($pageMain->URLSegment, $pageMainOther->URLSegment, $this->assertNotEquals($pageMain->URLSegment, $pageMainOther->URLSegment,
'Pages in same subsite cant share the same URL' 'Pages in same subsite cant share the same URL'
); );
Subsite::changeSubsite($subsite1->ID); Subsite::changeSubsite($subsite1->ID);
$pageSubsite1 = new SiteTree(); $pageSubsite1 = new SiteTree();
$pageSubsite1->URLSegment = 'testpage'; $pageSubsite1->URLSegment = 'testpage';
$pageSubsite1->write(); $pageSubsite1->write();
$pageSubsite1->publish('Stage', 'Live'); $pageSubsite1->publish('Stage', 'Live');
$this->assertEquals($pageMain->URLSegment, $pageSubsite1->URLSegment, $this->assertEquals($pageMain->URLSegment, $pageSubsite1->URLSegment,
'Pages in different subsites can share the same URL' 'Pages in different subsites can share the same URL'
); );
} }
function testBasicSanity() { function testBasicSanity() {
$this->assertTrue(singleton('SiteTree')->getSiteConfig() instanceof SiteConfig); $this->assertTrue(singleton('SilverStripe\\CMS\\Model\\SiteTree')->getSiteConfig() instanceof SiteConfig);
// The following assert is breaking in Translatable. // The following assert is breaking in Translatable.
$this->assertTrue(singleton('SiteTree')->getCMSFields() instanceof FieldList); $this->assertTrue(singleton('SilverStripe\\CMS\\Model\\SiteTree')->getCMSFields() instanceof FieldList);
$this->assertTrue(singleton('SubsitesVirtualPage')->getCMSFields() instanceof FieldList); $this->assertTrue(singleton('SubsitesVirtualPage')->getCMSFields() instanceof FieldList);
$this->assertTrue(is_array(singleton('SiteTreeSubsites')->extraStatics())); $this->assertTrue(is_array(singleton('SiteTreeSubsites')->extraStatics()));
} }
function testErrorPageLocations() { function testErrorPageLocations() {
$subsite1 = $this->objFromFixture('Subsite', 'domaintest1'); $subsite1 = $this->objFromFixture('Subsite', 'domaintest1');
Subsite::changeSubsite($subsite1->ID); Subsite::changeSubsite($subsite1->ID);
$path = SiteTreeSubsitesTest_ErrorPage::get_error_filename_spy(500); $path = SiteTreeSubsitesTest_ErrorPage::get_error_filename_spy(500);
$expected_path = 'error-500-'.$subsite1->domain().'.html'; $expected_path = 'error-500-'.$subsite1->domain().'.html';
$this->assertEquals($expected_path, $path); $this->assertEquals($expected_path, $path);
} }
function testCanEditSiteTree() { function testCanEditSiteTree() {
$admin = $this->objFromFixture('Member', 'admin'); $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'admin');
$subsite1member = $this->objFromFixture('Member', 'subsite1member'); $subsite1member = $this->objFromFixture('SilverStripe\\Security\\Member', 'subsite1member');
$subsite2member = $this->objFromFixture('Member', 'subsite2member'); $subsite2member = $this->objFromFixture('SilverStripe\\Security\\Member', 'subsite2member');
$mainpage = $this->objFromFixture('Page', 'home'); $mainpage = $this->objFromFixture('Page', 'home');
$subsite1page = $this->objFromFixture('Page', 'subsite1_home'); $subsite1page = $this->objFromFixture('Page', 'subsite1_home');
$subsite2page = $this->objFromFixture('Page', 'subsite2_home'); $subsite2page = $this->objFromFixture('Page', 'subsite2_home');
$subsite1 = $this->objFromFixture('Subsite', 'subsite1'); $subsite1 = $this->objFromFixture('Subsite', 'subsite1');
$subsite2 = $this->objFromFixture('Subsite', 'subsite2'); $subsite2 = $this->objFromFixture('Subsite', 'subsite2');
// Cant pass member as arguments to canEdit() because of GroupSubsites // Cant pass member as arguments to canEdit() because of GroupSubsites
Session::set("loggedInAs", $admin->ID); Session::set("loggedInAs", $admin->ID);
$this->assertTrue( $this->assertTrue(
(bool)$subsite1page->canEdit(), (bool)$subsite1page->canEdit(),
'Administrators can edit all subsites' 'Administrators can edit all subsites'
); );
// @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state // @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state
Subsite::changeSubsite($subsite1); Subsite::changeSubsite($subsite1);
Session::set("loggedInAs", $subsite1member->ID); Session::set("loggedInAs", $subsite1member->ID);
$this->assertTrue( $this->assertTrue(
(bool)$subsite1page->canEdit(), (bool)$subsite1page->canEdit(),
'Members can edit pages on a subsite if they are in a group belonging to this subsite' 'Members can edit pages on a subsite if they are in a group belonging to this subsite'
); );
Session::set("loggedInAs", $subsite2member->ID); Session::set("loggedInAs", $subsite2member->ID);
$this->assertFalse( $this->assertFalse(
(bool)$subsite1page->canEdit(), (bool)$subsite1page->canEdit(),
'Members cant edit pages on a subsite if they are not in a group belonging to this subsite' 'Members cant edit pages on a subsite if they are not in a group belonging to this subsite'
); );
// @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state // @todo: Workaround because GroupSubsites->augmentSQL() is relying on session state
Subsite::changeSubsite(0); Subsite::changeSubsite(0);
$this->assertFalse( $this->assertFalse(
@ -101,7 +110,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest {
'Members cant edit pages on the main site if they are not in a group allowing this' 'Members cant edit pages on the main site if they are not in a group allowing this'
); );
} }
/** /**
* Similar to {@link SubsitesVirtualPageTest->testSubsiteVirtualPageCanHaveSameUrlsegmentAsOtherSubsite()}. * Similar to {@link SubsitesVirtualPageTest->testSubsiteVirtualPageCanHaveSameUrlsegmentAsOtherSubsite()}.
*/ */
@ -109,7 +118,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest {
// Set up a couple of pages with the same URL on different subsites // Set up a couple of pages with the same URL on different subsites
$s1 = $this->objFromFixture('Subsite','domaintest1'); $s1 = $this->objFromFixture('Subsite','domaintest1');
$s2 = $this->objFromFixture('Subsite','domaintest2'); $s2 = $this->objFromFixture('Subsite','domaintest2');
$p1 = new SiteTree(); $p1 = new SiteTree();
$p1->Title = $p1->URLSegment = "test-page"; $p1->Title = $p1->URLSegment = "test-page";
$p1->SubsiteID = $s1->ID; $p1->SubsiteID = $s1->ID;
@ -123,7 +132,7 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest {
// Check that the URLs weren't modified in our set-up // Check that the URLs weren't modified in our set-up
$this->assertEquals($p1->URLSegment, 'test-page'); $this->assertEquals($p1->URLSegment, 'test-page');
$this->assertEquals($p2->URLSegment, 'test-page'); $this->assertEquals($p2->URLSegment, 'test-page');
// Check that if we switch between the different subsites, we receive the correct pages // Check that if we switch between the different subsites, we receive the correct pages
Subsite::changeSubsite($s1); Subsite::changeSubsite($s1);
$this->assertEquals($p1->ID, SiteTree::get_by_link('test-page')->ID); $this->assertEquals($p1->ID, SiteTree::get_by_link('test-page')->ID);
@ -131,71 +140,71 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest {
Subsite::changeSubsite($s2); Subsite::changeSubsite($s2);
$this->assertEquals($p2->ID, SiteTree::get_by_link('test-page')->ID); $this->assertEquals($p2->ID, SiteTree::get_by_link('test-page')->ID);
} }
function testPageTypesBlacklistInClassDropdown() { function testPageTypesBlacklistInClassDropdown() {
$editor = $this->objFromFixture('Member', 'editor'); $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'editor');
Session::set("loggedInAs", $editor->ID); Session::set("loggedInAs", $editor->ID);
$s1 = $this->objFromFixture('Subsite','domaintest1'); $s1 = $this->objFromFixture('Subsite','domaintest1');
$s2 = $this->objFromFixture('Subsite','domaintest2'); $s2 = $this->objFromFixture('Subsite','domaintest2');
$page = singleton('SiteTree'); $page = singleton('SilverStripe\\CMS\\Model\\SiteTree');
$s1->PageTypeBlacklist = 'SiteTreeSubsitesTest_ClassA,ErrorPage'; $s1->PageTypeBlacklist = 'SiteTreeSubsitesTest_ClassA,ErrorPage';
$s1->write(); $s1->write();
Subsite::changeSubsite($s1); Subsite::changeSubsite($s1);
$settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource(); $settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource();
$this->assertArrayNotHasKey('ErrorPage', $this->assertArrayNotHasKey('SilverStripe\\CMS\\Model\\ErrorPage',
$settingsFields $settingsFields
); );
$this->assertArrayNotHasKey('SiteTreeSubsitesTest_ClassA', $this->assertArrayNotHasKey('SiteTreeSubsitesTest_ClassA',
$settingsFields $settingsFields
); );
$this->assertArrayHasKey('SiteTreeSubsitesTest_ClassB', $this->assertArrayHasKey('SiteTreeSubsitesTest_ClassB',
$settingsFields $settingsFields
); );
Subsite::changeSubsite($s2); Subsite::changeSubsite($s2);
$settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource(); $settingsFields = $page->getSettingsFields()->dataFieldByName('ClassName')->getSource();
$this->assertArrayHasKey('ErrorPage', $this->assertArrayHasKey('SilverStripe\\CMS\\Model\\ErrorPage',
$settingsFields $settingsFields
); );
$this->assertArrayHasKey('SiteTreeSubsitesTest_ClassA', $this->assertArrayHasKey('SiteTreeSubsitesTest_ClassA',
$settingsFields $settingsFields
); );
$this->assertArrayHasKey('SiteTreeSubsitesTest_ClassB', $this->assertArrayHasKey('SiteTreeSubsitesTest_ClassB',
$settingsFields $settingsFields
); );
} }
function testPageTypesBlacklistInCMSMain() { function testPageTypesBlacklistInCMSMain() {
$editor = $this->objFromFixture('Member', 'editor'); $editor = $this->objFromFixture('SilverStripe\\Security\\Member', 'editor');
Session::set("loggedInAs", $editor->ID); Session::set("loggedInAs", $editor->ID);
$cmsmain = new CMSMain(); $cmsmain = new CMSMain();
$s1 = $this->objFromFixture('Subsite','domaintest1'); $s1 = $this->objFromFixture('Subsite','domaintest1');
$s2 = $this->objFromFixture('Subsite','domaintest2'); $s2 = $this->objFromFixture('Subsite','domaintest2');
$s1->PageTypeBlacklist = 'SiteTreeSubsitesTest_ClassA,ErrorPage'; $s1->PageTypeBlacklist = 'SiteTreeSubsitesTest_ClassA,ErrorPage';
$s1->write(); $s1->write();
Subsite::changeSubsite($s1); Subsite::changeSubsite($s1);
$hints = Convert::json2array($cmsmain->SiteTreeHints()); $hints = Convert::json2array($cmsmain->SiteTreeHints());
$classes = $hints['Root']['disallowedChildren']; $classes = $hints['Root']['disallowedChildren'];
$this->assertContains('ErrorPage', $classes); $this->assertContains('SilverStripe\\CMS\\Model\\ErrorPage', $classes);
$this->assertContains('SiteTreeSubsitesTest_ClassA', $classes); $this->assertContains('SiteTreeSubsitesTest_ClassA', $classes);
$this->assertNotContains('SiteTreeSubsitesTest_ClassB', $classes); $this->assertNotContains('SiteTreeSubsitesTest_ClassB', $classes);
Subsite::changeSubsite($s2); Subsite::changeSubsite($s2);
$hints = Convert::json2array($cmsmain->SiteTreeHints()); $hints = Convert::json2array($cmsmain->SiteTreeHints());
$classes = $hints['Root']['disallowedChildren']; $classes = $hints['Root']['disallowedChildren'];
$this->assertNotContains('ErrorPage', $classes); $this->assertNotContains('SilverStripe\\CMS\\Model\\ErrorPage', $classes);
$this->assertNotContains('SiteTreeSubsitesTest_ClassA', $classes); $this->assertNotContains('SiteTreeSubsitesTest_ClassA', $classes);
$this->assertNotContains('SiteTreeSubsitesTest_ClassB', $classes); $this->assertNotContains('SiteTreeSubsitesTest_ClassB', $classes);
} }
} }
class SiteTreeSubsitesTest_ClassA extends SiteTree implements TestOnly {} class SiteTreeSubsitesTest_ClassA extends SiteTree implements TestOnly {}
@ -213,4 +222,4 @@ class SiteTreeSubsitesTest_ErrorPage extends ErrorPage implements TestOnly {
public static function get_error_filename_spy($statusCode) { public static function get_error_filename_spy($statusCode) {
return self::get_error_filename($statusCode); return self::get_error_filename($statusCode);
} }
} }

View File

@ -1,5 +1,9 @@
<?php <?php
use SilverStripe\Control\Session;
use SilverStripe\Core\Config\Config;
use SilverStripe\Dev\FunctionalTest;
class SubsiteAdminFunctionalTest extends FunctionalTest { class SubsiteAdminFunctionalTest extends FunctionalTest {
static $fixture_file = 'subsites/tests/SubsiteTest.yml'; static $fixture_file = 'subsites/tests/SubsiteTest.yml';
static $use_draft_site = true; static $use_draft_site = true;
@ -39,7 +43,7 @@ class SubsiteAdminFunctionalTest extends FunctionalTest {
* Admin should be able to access all subsites and the main site * Admin should be able to access all subsites and the main site
*/ */
function testAdminCanAccessAllSubsites() { function testAdminCanAccessAllSubsites() {
$member = $this->objFromFixture('Member', 'admin'); $member = $this->objFromFixture('SilverStripe\\Security\\Member', 'admin');
Session::set("loggedInAs", $member->ID); Session::set("loggedInAs", $member->ID);
$this->getAndFollowAll('admin/pages/?SubsiteID=0'); $this->getAndFollowAll('admin/pages/?SubsiteID=0');
@ -57,7 +61,7 @@ class SubsiteAdminFunctionalTest extends FunctionalTest {
} }
function testAdminIsRedirectedToObjectsSubsite() { function testAdminIsRedirectedToObjectsSubsite() {
$member = $this->objFromFixture('Member', 'admin'); $member = $this->objFromFixture('SilverStripe\\Security\\Member', 'admin');
Session::set("loggedInAs", $member->ID); Session::set("loggedInAs", $member->ID);
$mainSubsitePage = $this->objFromFixture('Page', 'mainSubsitePage'); $mainSubsitePage = $this->objFromFixture('Page', 'mainSubsitePage');
@ -65,13 +69,13 @@ class SubsiteAdminFunctionalTest extends FunctionalTest {
Config::inst()->nest(); Config::inst()->nest();
Config::inst()->update('CMSPageEditController', 'treats_subsite_0_as_global', false); Config::inst()->update('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 'treats_subsite_0_as_global', false);
Subsite::changeSubsite(0); Subsite::changeSubsite(0);
$this->getAndFollowAll("admin/pages/edit/show/$subsite1Home->ID"); $this->getAndFollowAll("admin/pages/edit/show/$subsite1Home->ID");
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID, 'Loading an object switches the subsite'); $this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID, 'Loading an object switches the subsite');
$this->assertRegExp("#^admin/pages.*#", $this->mainSession->lastUrl(), 'Lands on the correct section'); $this->assertRegExp("#^admin/pages.*#", $this->mainSession->lastUrl(), 'Lands on the correct section');
Config::inst()->update('CMSPageEditController', 'treats_subsite_0_as_global', true); Config::inst()->update('SilverStripe\\CMS\\Controllers\\CMSPageEditController', 'treats_subsite_0_as_global', true);
Subsite::changeSubsite(0); Subsite::changeSubsite(0);
$this->getAndFollowAll("admin/pages/edit/show/$subsite1Home->ID"); $this->getAndFollowAll("admin/pages/edit/show/$subsite1Home->ID");
$this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID, 'Loading a non-main-site object still switches the subsite if configured with treats_subsite_0_as_global'); $this->assertEquals(Subsite::currentSubsiteID(), $subsite1Home->SubsiteID, 'Loading a non-main-site object still switches the subsite if configured with treats_subsite_0_as_global');
@ -89,7 +93,7 @@ class SubsiteAdminFunctionalTest extends FunctionalTest {
* even though he does not have the ADMIN permission. * even though he does not have the ADMIN permission.
*/ */
function testEditorCanAccessAllSubsites() { function testEditorCanAccessAllSubsites() {
$member = $this->objFromFixture('Member', 'editor'); $member = $this->objFromFixture('SilverStripe\\Security\\Member', 'editor');
Session::set("loggedInAs", $member->ID); Session::set("loggedInAs", $member->ID);
$this->getAndFollowAll('admin/pages/?SubsiteID=0'); $this->getAndFollowAll('admin/pages/?SubsiteID=0');
@ -110,7 +114,7 @@ class SubsiteAdminFunctionalTest extends FunctionalTest {
* Test a member who only has access to one subsite (subsite1) and only some sections (pages and security). * Test a member who only has access to one subsite (subsite1) and only some sections (pages and security).
*/ */
function testSubsiteAdmin() { function testSubsiteAdmin() {
$member = $this->objFromFixture('Member', 'subsite1member'); $member = $this->objFromFixture('SilverStripe\\Security\\Member', 'subsite1member');
Session::set("loggedInAs", $member->ID); Session::set("loggedInAs", $member->ID);
$subsite1 = $this->objFromFixture('Subsite', 'subsite1'); $subsite1 = $this->objFromFixture('Subsite', 'subsite1');

View File

@ -1,11 +1,15 @@
<?php <?php
use SilverStripe\Control\Session;
use SilverStripe\Control\Director;
use SilverStripe\CMS\Controllers\CMSMain;
class SubsiteAdminTest extends BaseSubsiteTest { class SubsiteAdminTest extends BaseSubsiteTest {
static $fixture_file = 'subsites/tests/SubsiteTest.yml'; static $fixture_file = 'subsites/tests/SubsiteTest.yml';
function adminLoggedInSession() { function adminLoggedInSession() {
return new Session(array( return new Session(array(
'loggedInAs' => $this->idFromFixture('Member', 'admin') 'loggedInAs' => $this->idFromFixture('SilverStripe\\Security\\Member', 'admin')
)); ));
} }
@ -31,7 +35,7 @@ class SubsiteAdminTest extends BaseSubsiteTest {
* of whether he is in a subsite-specific group or not. * of whether he is in a subsite-specific group or not.
*/ */
function testMainsiteAdminCanAccessAllSubsites() { function testMainsiteAdminCanAccessAllSubsites() {
$member = $this->objFromFixture('Member', 'admin'); $member = $this->objFromFixture('SilverStripe\\Security\\Member', 'admin');
Session::set("loggedInAs", $member->ID); Session::set("loggedInAs", $member->ID);
$cmsMain = new CMSMain(); $cmsMain = new CMSMain();

View File

@ -1,5 +1,8 @@
<?php <?php
use SilverStripe\ORM\DataObject;
use SilverStripe\Control\Director;
class SubsiteTest extends BaseSubsiteTest { class SubsiteTest extends BaseSubsiteTest {
static $fixture_file = 'subsites/tests/SubsiteTest.yml'; static $fixture_file = 'subsites/tests/SubsiteTest.yml';
@ -32,7 +35,7 @@ class SubsiteTest extends BaseSubsiteTest {
$tmplHome = DataObject::get_one('Page', "\"URLSegment\" = 'home'"); $tmplHome = DataObject::get_one('Page', "\"URLSegment\" = 'home'");
// Publish all the pages in the template, testing that DataObject::get only returns pages from the chosen subsite // Publish all the pages in the template, testing that DataObject::get only returns pages from the chosen subsite
$pages = DataObject::get("SiteTree"); $pages = DataObject::get("SilverStripe\\CMS\\Model\\SiteTree");
$totalPages = $pages->Count(); $totalPages = $pages->Count();
foreach($pages as $page) { foreach($pages as $page) {
$this->assertEquals($template->ID, $page->SubsiteID); $this->assertEquals($template->ID, $page->SubsiteID);
@ -256,7 +259,7 @@ class SubsiteTest extends BaseSubsiteTest {
} }
function testAllAccessibleSites() { function testAllAccessibleSites() {
$member = $this->objFromFixture('Member', 'subsite1member'); $member = $this->objFromFixture('SilverStripe\\Security\\Member', 'subsite1member');
$subsites = Subsite::all_accessible_sites(true, 'Main site', $member); $subsites = Subsite::all_accessible_sites(true, 'Main site', $member);
$this->assertDOSEquals(array( $this->assertDOSEquals(array(
@ -269,13 +272,13 @@ class SubsiteTest extends BaseSubsiteTest {
*/ */
function testAccessibleSites() { function testAccessibleSites() {
$member1Sites = Subsite::accessible_sites("CMS_ACCESS_CMSMain", false, null, $member1Sites = Subsite::accessible_sites("CMS_ACCESS_CMSMain", false, null,
$this->objFromFixture('Member', 'subsite1member')); $this->objFromFixture('SilverStripe\\Security\\Member', 'subsite1member'));
$member1SiteTitles = $member1Sites->column("Title"); $member1SiteTitles = $member1Sites->column("Title");
sort($member1SiteTitles); sort($member1SiteTitles);
$this->assertEquals('Subsite1 Template', $member1SiteTitles[0], 'Member can get to a subsite via a group'); $this->assertEquals('Subsite1 Template', $member1SiteTitles[0], 'Member can get to a subsite via a group');
$adminSites = Subsite::accessible_sites("CMS_ACCESS_CMSMain", false, null, $adminSites = Subsite::accessible_sites("CMS_ACCESS_CMSMain", false, null,
$this->objFromFixture('Member', 'admin')); $this->objFromFixture('SilverStripe\\Security\\Member', 'admin'));
$adminSiteTitles = $adminSites->column("Title"); $adminSiteTitles = $adminSites->column("Title");
sort($adminSiteTitles); sort($adminSiteTitles);
$this->assertEquals(array( $this->assertEquals(array(
@ -288,17 +291,17 @@ class SubsiteTest extends BaseSubsiteTest {
), $adminSiteTitles); ), $adminSiteTitles);
$member2Sites = Subsite::accessible_sites("CMS_ACCESS_CMSMain", false, null, $member2Sites = Subsite::accessible_sites("CMS_ACCESS_CMSMain", false, null,
$this->objFromFixture('Member', 'subsite1member2')); $this->objFromFixture('SilverStripe\\Security\\Member', 'subsite1member2'));
$member2SiteTitles = $member2Sites->column("Title"); $member2SiteTitles = $member2Sites->column("Title");
sort($member2SiteTitles); sort($member2SiteTitles);
$this->assertEquals('Subsite1 Template', $member2SiteTitles[0], 'Member can get to subsite via a group role'); $this->assertEquals('Subsite1 Template', $member2SiteTitles[0], 'Member can get to subsite via a group role');
} }
function testhasMainSitePermission() { function testhasMainSitePermission() {
$admin = $this->objFromFixture('Member', 'admin'); $admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'admin');
$subsite1member = $this->objFromFixture('Member', 'subsite1member'); $subsite1member = $this->objFromFixture('SilverStripe\\Security\\Member', 'subsite1member');
$subsite1admin = $this->objFromFixture('Member', 'subsite1admin'); $subsite1admin = $this->objFromFixture('SilverStripe\\Security\\Member', 'subsite1admin');
$allsubsitesauthor = $this->objFromFixture('Member', 'allsubsitesauthor'); $allsubsitesauthor = $this->objFromFixture('SilverStripe\\Security\\Member', 'allsubsitesauthor');
$this->assertTrue( $this->assertTrue(
Subsite::hasMainSitePermission($admin), Subsite::hasMainSitePermission($admin),

View File

@ -75,14 +75,14 @@ Page:
Title: 'Contact Us (Subsite 2)' Title: 'Contact Us (Subsite 2)'
SubsiteID: =>Subsite.subsite2 SubsiteID: =>Subsite.subsite2
PermissionRoleCode: SilverStripe\Security\PermissionRoleCode:
roleCode1: roleCode1:
Code: CMS_ACCESS_CMSMain Code: CMS_ACCESS_CMSMain
PermissionRole: SilverStripe\Security\PermissionRole:
role1: role1:
Title: role1 Title: role1
Codes: =>PermissionRoleCode.roleCode1 Codes: =>SilverStripe\Security\PermissionRoleCode.roleCode1
Group: SilverStripe\Security\Group:
admin: admin:
Title: Admin Title: Admin
Code: admin Code: admin
@ -114,71 +114,71 @@ Group:
Title: subsite1_group_via_role Title: subsite1_group_via_role
Code: subsite1_group_via_role Code: subsite1_group_via_role
AccessAllSubsites: 1 AccessAllSubsites: 1
Roles: =>PermissionRole.role1 Roles: =>SilverStripe\Security\PermissionRole.role1
Permission: SilverStripe\Security\Permission:
admin: admin:
Code: ADMIN Code: ADMIN
GroupID: =>Group.admin GroupID: =>SilverStripe\Security\Group.admin
editor1: editor1:
Code: CMS_ACCESS_CMSMain Code: CMS_ACCESS_CMSMain
GroupID: =>Group.editor GroupID: =>SilverStripe\Security\Group.editor
editor2: editor2:
Code: SITETREE_VIEW_ALL Code: SITETREE_VIEW_ALL
GroupID: =>Group.editor GroupID: =>SilverStripe\Security\Group.editor
editor3: editor3:
Code: VIEW_DRAFT_CONTENT Code: VIEW_DRAFT_CONTENT
GroupID: =>Group.editor GroupID: =>SilverStripe\Security\Group.editor
accesscmsmain1: accesscmsmain1:
Code: CMS_ACCESS_CMSMain Code: CMS_ACCESS_CMSMain
GroupID: =>Group.subsite1_group GroupID: =>SilverStripe\Security\Group.subsite1_group
accesscmsmain2: accesscmsmain2:
Code: CMS_ACCESS_CMSMain Code: CMS_ACCESS_CMSMain
GroupID: =>Group.subsite2_group GroupID: =>SilverStripe\Security\Group.subsite2_group
accesscmsmain3: accesscmsmain3:
Code: CMS_ACCESS_CMSMain Code: CMS_ACCESS_CMSMain
GroupID: =>Group.subsite1admins GroupID: =>SilverStripe\Security\Group.subsite1admins
accesscmsmain4: accesscmsmain4:
Code: CMS_ACCESS_CMSMain Code: CMS_ACCESS_CMSMain
GroupID: =>Group.allsubsitesauthors GroupID: =>SilverStripe\Security\Group.allsubsitesauthors
securityaccess1: securityaccess1:
Code: CMS_ACCESS_SecurityAdmin Code: CMS_ACCESS_SecurityAdmin
GroupID: =>Group.subsite1_group GroupID: =>SilverStripe\Security\Group.subsite1_group
securityaccess2: securityaccess2:
Code: CMS_ACCESS_SecurityAdmin Code: CMS_ACCESS_SecurityAdmin
GroupID: =>Group.subsite2_group GroupID: =>SilverStripe\Security\Group.subsite2_group
adminsubsite1: adminsubsite1:
Code: ADMIN Code: ADMIN
GroupID: =>Group.subsite1admins GroupID: =>SilverStripe\Security\Group.subsite1admins
Member: SilverStripe\Security\Member:
admin: admin:
FirstName: Admin FirstName: Admin
Surname: User Surname: User
Email: admin@test.com Email: admin@test.com
Password: rangi Password: rangi
Groups: =>Group.admin Groups: =>SilverStripe\Security\Group.admin
editor: editor:
FirstName: Editor FirstName: Editor
Surname: User Surname: User
Email: editor@test.com Email: editor@test.com
Password: rangi Password: rangi
Groups: =>Group.editor Groups: =>SilverStripe\Security\Group.editor
subsite1member: subsite1member:
Email: subsite1member@test.com Email: subsite1member@test.com
Groups: =>Group.subsite1_group Groups: =>SilverStripe\Security\Group.subsite1_group
subsite2member: subsite2member:
Email: subsite2member@test.com Email: subsite2member@test.com
Groups: =>Group.subsite2_group Groups: =>SilverStripe\Security\Group.subsite2_group
subsite1admin: subsite1admin:
Email: subsite1admin@test.com Email: subsite1admin@test.com
Groups: =>Group.subsite1admins Groups: =>SilverStripe\Security\Group.subsite1admins
allsubsitesauthor: allsubsitesauthor:
Email: allsubsitesauthor@test.com Email: allsubsitesauthor@test.com
Groups: =>Group.allsubsitesauthors Groups: =>SilverStripe\Security\Group.allsubsitesauthors
subsite1member2: subsite1member2:
Email: subsite1member2@test.com Email: subsite1member2@test.com
Groups: =>Group.subsite1_group_via_role Groups: =>SilverStripe\Security\Group.subsite1_group_via_role
SiteConfig: SilverStripe\SiteConfig\SiteConfig:
config: config:
CanCreateTopLevelType: LoggedInUsers CanCreateTopLevelType: LoggedInUsers

View File

@ -1,5 +1,10 @@
<?php <?php
use SilverStripe\Assets\Filesystem;
use SilverStripe\ORM\DB;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\Versioning\Versioned;
class SubsitesVirtualPageTest extends BaseSubsiteTest { class SubsitesVirtualPageTest extends BaseSubsiteTest {
static $fixture_file = array( static $fixture_file = array(
'subsites/tests/SubsiteTest.yml', 'subsites/tests/SubsiteTest.yml',
@ -13,8 +18,8 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest {
AssetStoreTest_SpyStore::activate('SubsitesVirtualPageTest'); AssetStoreTest_SpyStore::activate('SubsitesVirtualPageTest');
// Create a test files for each of the fixture references // Create a test files for each of the fixture references
$file = $this->objFromFixture('File', 'file1'); $file = $this->objFromFixture('SilverStripe\\Assets\\File', 'file1');
$page = $this->objFromFixture('SiteTree', 'page1'); $page = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'page1');
$fromPath = __DIR__ . '/testscript-test-file.pdf'; $fromPath = __DIR__ . '/testscript-test-file.pdf';
$destPath = AssetStoreTest_SpyStore::getLocalPath($file); $destPath = AssetStoreTest_SpyStore::getLocalPath($file);
Filesystem::makeFolder(dirname($destPath)); Filesystem::makeFolder(dirname($destPath));
@ -57,7 +62,7 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest {
$this->logInWithPermission('ADMIN'); $this->logInWithPermission('ADMIN');
// Publish the source page // Publish the source page
$page = $this->objFromFixture('SiteTree', 'page1'); $page = $this->objFromFixture('SilverStripe\\CMS\\Model\\SiteTree', 'page1');
$this->assertTrue($page->doPublish()); $this->assertTrue($page->doPublish());
// Create a virtual page from it, and publish that // Create a virtual page from it, and publish that
@ -67,7 +72,7 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest {
$svp->doPublish(); $svp->doPublish();
// Rename the file // Rename the file
$file = $this->objFromFixture('File', 'file1'); $file = $this->objFromFixture('SilverStripe\\Assets\\File', 'file1');
$file->Name = 'renamed-test-file.pdf'; $file->Name = 'renamed-test-file.pdf';
$file->write(); $file->write();
@ -261,8 +266,8 @@ class SubsitesVirtualPageTest extends BaseSubsiteTest {
function fixVersionNumberCache($page) { function fixVersionNumberCache($page) {
$pages = func_get_args(); $pages = func_get_args();
foreach($pages as $p) { foreach($pages as $p) {
Versioned::prepopulate_versionnumber_cache('SiteTree', 'Stage', array($p->ID)); Versioned::prepopulate_versionnumber_cache('SilverStripe\\CMS\\Model\\SiteTree', 'Stage', array($p->ID));
Versioned::prepopulate_versionnumber_cache('SiteTree', 'Live', array($p->ID)); Versioned::prepopulate_versionnumber_cache('SilverStripe\\CMS\\Model\\SiteTree', 'Live', array($p->ID));
} }
} }

View File

@ -1,11 +1,11 @@
# These need to come first so that SiteTree has the link meta-data written. # These need to come first so that SiteTree has the link meta-data written.
File: SilverStripe\Assets\File:
file1: file1:
FileFilename: testscript-test-file.pdf FileFilename: testscript-test-file.pdf
FileHash: 464dedb70af0dc7f8f3360e7f3ae43cbbf1cdf4e FileHash: 464dedb70af0dc7f8f3360e7f3ae43cbbf1cdf4e
Name: testscript-test-file.pdf Name: testscript-test-file.pdf
SiteTree: SilverStripe\CMS\Model\SiteTree:
page1: page1:
Title: page1 Title: page1
URLSegment: page1 URLSegment: page1

View File

@ -11,6 +11,9 @@ use SilverStripe\BehatExtension\Context\SilverStripeContext,
SilverStripe\Framework\Test\Behaviour\CmsFormsContext, SilverStripe\Framework\Test\Behaviour\CmsFormsContext,
SilverStripe\Framework\Test\Behaviour\CmsUiContext, SilverStripe\Framework\Test\Behaviour\CmsUiContext,
SilverStripe\Cms\Test\Behaviour; SilverStripe\Cms\Test\Behaviour;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\Core\ClassInfo;
// PHPUnit // PHPUnit
require_once 'PHPUnit/Autoload.php'; require_once 'PHPUnit/Autoload.php';
@ -49,15 +52,15 @@ class FeatureContext extends SilverStripeContext {
// Use blueprints to set user name from identifier // Use blueprints to set user name from identifier
$factory = $fixtureContext->getFixtureFactory(); $factory = $fixtureContext->getFixtureFactory();
$blueprint = \Injector::inst()->create('FixtureBlueprint', 'Member'); $blueprint = Injector::inst()->create('SilverStripe\\Dev\\FixtureBlueprint', 'SilverStripe\\Security\\Member');
$blueprint->addCallback('beforeCreate', function($identifier, &$data, &$fixtures) { $blueprint->addCallback('beforeCreate', function($identifier, &$data, &$fixtures) {
if(!isset($data['FirstName'])) $data['FirstName'] = $identifier; if(!isset($data['FirstName'])) $data['FirstName'] = $identifier;
}); });
$factory->define('Member', $blueprint); $factory->define('SilverStripe\\Security\\Member', $blueprint);
// Auto-publish pages // Auto-publish pages
foreach(\ClassInfo::subclassesFor('SiteTree') as $id => $class) { foreach(ClassInfo::subclassesFor('SilverStripe\\CMS\\Model\\SiteTree') as $id => $class) {
$blueprint = \Injector::inst()->create('FixtureBlueprint', $class); $blueprint = Injector::inst()->create('SilverStripe\\Dev\\FixtureBlueprint', $class);
$blueprint->addCallback('afterCreate', function($obj, $identifier, &$data, &$fixtures) { $blueprint->addCallback('afterCreate', function($obj, $identifier, &$data, &$fixtures) {
$obj->publish('Stage', 'Live'); $obj->publish('Stage', 'Live');
}); });
@ -78,7 +81,7 @@ class FeatureContext extends SilverStripeContext {
*/ */
public function getFixtureFactory() { public function getFixtureFactory() {
if(!$this->fixtureFactory) { if(!$this->fixtureFactory) {
$this->fixtureFactory = \Injector::inst()->create('BehatFixtureFactory'); $this->fixtureFactory = Injector::inst()->create('SilverStripe\\Dev\\BehatFixtureFactory');
} }
return $this->fixtureFactory; return $this->fixtureFactory;