BUG: More SS 3.0 modifications

Fixes for SS 3.0 beta 3

Fixed compatibility issues with ss3.0 rc1

fixed potential issue caused by the from array format changing in 3.0

Fixed strict standards warnings

Fixed strict notice "Only variables should be passed by reference"

Fixed strict notice "Only variables should be passed by reference"

Fixed strict notice caused by SubsiteAdmin not declaring all of the properties for getCMSFields()

Made Subsite::accessible_sites() static

Fixed issue caused when trying to add a domain before saving for the first time

Fixed undefined property ParentID
This commit is contained in:
Ed 2012-04-25 09:29:32 -03:00 committed by Kirk Mayo
parent a2b612570b
commit c9d3a1f854
10 changed files with 45 additions and 35 deletions

View File

@ -6,7 +6,7 @@ The subsites module allows multiple websites to run from a single installation o
## Requirements
* SilverStripe 2.3
* SilverStripe 3.0
## Installation

View File

@ -13,8 +13,8 @@ class SubsiteAdmin extends ModelAdmin {
public $showImportForm=false;
public function getEditForm($id = null) {
$form = parent::getEditForm($id);
public function getEditForm($id = null, $fields = null) {
$form = parent::getEditForm($id, $fields);
if($this->modelClass=='Subsite') {
$grid=$form->Fields()->dataFieldByName('Subsite');

View File

@ -30,7 +30,7 @@ class FileSubsites extends DataExtension {
function updateCMSFields(FieldList $fields) {
if($this->owner instanceof Folder) {
$sites = Subsite::accessible_sites('CMS_ACCESS_AssetAdmin');
$dropdownValues = ($sites) ? $sites->map()->toArray() : array();
$dropdownValues = ($sites) ? $sites->map() : array();
$dropdownValues[0] = 'All sites';
ksort($dropdownValues);
if($sites)$fields->push(new DropdownField("SubsiteID", "Subsite", $dropdownValues));
@ -43,22 +43,23 @@ class FileSubsites extends DataExtension {
function augmentSQL(SQLQuery &$query) {
// If you're querying by ID, ignore the sub-site - this is a bit ugly... (but it was WAYYYYYYYYY worse)
//@TODO I don't think excluding if SiteTree_ImageTracking is a good idea however because of the SS 3.0 api and ManyManyList::removeAll() changing the from table after this function is called there isn't much of a choice
if(!array_key_exists('SiteTree_ImageTracking', $query->from) && (!$query->where || !preg_match('/\.(\'|"|`|)ID(\'|"|`|)/', $query->where[0]))) {
if(!array_search('SiteTree_ImageTracking', $query->getFrom())===false && (!$query->where || !preg_match('/\.(\'|"|`|)ID(\'|"|`|)/', $query->where[0]))) {
/*if($context = DataObject::context_obj()) $subsiteID = (int) $context->SubsiteID;
else */$subsiteID = (int) Subsite::currentSubsiteID();
// The foreach is an ugly way of getting the first key :-)
foreach($query->from as $tableName => $info) {
foreach($query->getFrom() as $tableName => $info) {
$where = "\"$tableName\".\"SubsiteID\" IN (0, $subsiteID)";
$query->where[] = $where;
$query->addWhere($where);
break;
}
$isCounting = strpos($query->select[0], 'COUNT') !== false;
$sect=array_values($query->getSelect());
$isCounting = strpos($sect[0], 'COUNT') !== false;
// Ordering when deleting or counting doesn't apply
if(!$query->delete && !$isCounting) {
$query->orderby = "\"SubsiteID\"" . ($query->orderby ? ', ' : '') . $query->orderby;
if(!$query->getDelete() && !$isCounting) {
$query->addOrderBy("\"SubsiteID\"");
}
}
}
@ -83,7 +84,7 @@ class FileSubsites extends DataExtension {
$this->owner->write();
}
function canEdit() {
function canEdit($member = null) {
// Check the CMS_ACCESS_SecurityAdmin privileges on the subsite that owns this group
$subsiteID = Session::get('SubsiteID');
if($subsiteID&&$subsiteID == $this->owner->SubsiteID) {

View File

@ -49,7 +49,7 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
}
}
function updateCMSFields(&$fields) {
function updateCMSFields(FieldList $fields) {
if($this->owner->canEdit() ){
// i18n tab
$fields->findOrMakeTab('Root.Subsites',_t('GroupSubsites.SECURITYTABTITLE','Subsites'));
@ -116,7 +116,7 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
// Don't filter by Group_Subsites if we've already done that
$hasGroupSubsites = false;
foreach($query->from as $item) {
foreach($query->getFrom() as $item) {
if((is_array($item) && strpos($item['table'], 'Group_Subsites')!==false) || (!is_array($item) && strpos($item, 'Group_Subsites')!==false)) {
$hasGroupSubsites = true;
break;
@ -125,17 +125,18 @@ class GroupSubsites extends DataExtension implements PermissionProvider {
if(!$hasGroupSubsites) {
if($subsiteID) {
$query->leftJoin("Group_Subsites", "\"Group_Subsites\".\"GroupID\"
$query->addLeftJoin("Group_Subsites", "\"Group_Subsites\".\"GroupID\"
= \"Group\".\"ID\" AND \"Group_Subsites\".\"SubsiteID\" = $subsiteID");
$query->where[] = "(\"Group_Subsites\".\"SubsiteID\" IS NOT NULL OR
\"Group\".\"AccessAllSubsites\" = 1)";
$query->addWhere("(\"Group_Subsites\".\"SubsiteID\" IS NOT NULL OR
\"Group\".\"AccessAllSubsites\" = 1)");
} else {
$query->where[] = "\"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)
if(!$query->select[0] == 'COUNT(*)') {
$select=$query->getSelect();
if(isset($select[0]) && !$select[0] == 'COUNT(*)') {
$query->orderby = "\"AccessAllSubsites\" DESC" . ($query->orderby ? ', ' : '') . $query->orderby;
}
}

View File

@ -20,9 +20,11 @@ class SiteConfigSubsites extends DataExtension {
/*if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
else */$subsiteID = (int)Subsite::currentSubsiteID();
$tableName = array_shift(array_keys($query->from));
$froms=$query->getFrom();
$froms=array_keys($froms);
$tableName = array_shift($froms);
if($tableName != 'SiteConfig') return;
$query->where[] = "\"$tableName\".\"SubsiteID\" IN ($subsiteID)";
$query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)");
}
}

View File

@ -61,7 +61,7 @@ class SiteTreeSubsites extends DataExtension {
// Don't run on delete queries, since they are always tied to
// a specific ID.
if ($query->delete) return;
if ($query->getDelete()) return;
// 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)) {
@ -74,10 +74,10 @@ class SiteTreeSubsites extends DataExtension {
}
// The foreach is an ugly way of getting the first key :-)
foreach($query->from as $tableName => $info) {
foreach($query->getFrom() as $tableName => $info) {
// The tableName should be SiteTree or SiteTree_Live...
if(strpos($tableName,'SiteTree') === false) break;
$query->where[] = "\"$tableName\".\"SubsiteID\" IN ($subsiteID)";
$query->addWhere("\"$tableName\".\"SubsiteID\" IN ($subsiteID)");
break;
}
}
@ -89,7 +89,7 @@ class SiteTreeSubsites extends DataExtension {
parent::onBeforeWrite();
}
function updateCMSFields(&$fields) {
function updateCMSFields(FieldList $fields) {
if($this->owner->MasterPageID) $fields->insertFirst(new HeaderField('This page\'s content is copied from a master page: ' . $this->owner->MasterPage()->Title, 2));
// replace readonly link prefix
@ -100,7 +100,7 @@ class SiteTreeSubsites extends DataExtension {
$baseLink = Controller::join_links (
$baseUrl,
(SiteTree::nested_urls() && $this->ParentID ? $this->owner->Parent()->RelativeLink(true) : null)
(SiteTree::nested_urls() && $this->owner->ParentID ? $this->owner->Parent()->RelativeLink(true) : null)
);
$url = (strlen($baseLink) > 36) ? "..." .substr($baseLink, -32) : $baseLink;

View File

@ -178,7 +178,11 @@ class Subsite extends DataObject implements PermissionProvider {
* Show the configuration fields for each subsite
*/
function getCMSFields() {
if($this->ID!=0) {
$domainTable = new GridField("Domains", "Domains", $this->Domains(), GridFieldConfig_RecordEditor::create(10));
}else {
$domainTable = new LiteralField('Domains', '<p>'._t('Subsite.DOMAINSAVEFIRST', '_You can only add domains after saving for the first time').'</p>');
}
$languageSelector = new DropdownField('Language', 'Language', i18n::get_common_locales());
@ -472,7 +476,7 @@ JS;
* @param $member
* @return DataList of {@link Subsite} instances
*/
function accessible_sites($permCode, $includeMainSite = false, $mainSiteTitle = "Main site", $member = null) {
function accessible_sites($permCode, $includeMainSite = true, $mainSiteTitle = "Main site", $member = null) {
// Rationalise member arguments
if(!$member) $member = Member::currentUser();
if(!$member) return new ArrayList();
@ -490,20 +494,18 @@ JS;
$templateClassList = "'" . implode("', '", ClassInfo::subclassesFor("Subsite_Template")) . "'";
$subsites = DataObject::get(
'Subsite',
"\"Subsite\".\"Title\" != ''",
'')->leftJoin('Group_Subsites', "\"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"")
$subsites = DataList::create('Subsite')
->where("\"Subsite\".\"Title\" != ''")
->leftJoin('Group_Subsites', "\"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"")
->innerJoin('Group', "\"Group\".\"ID\" = \"Group_Subsites\".\"GroupID\" OR \"Group\".\"AccessAllSubsites\" = 1")
->innerJoin('Group_Members', "\"Group_Members\".\"GroupID\"=\"Group\".\"ID\" AND \"Group_Members\".\"MemberID\" = $member->ID")
->innerJoin('Permission', "\"Group\".\"ID\"=\"Permission\".\"GroupID\" AND \"Permission\".\"Code\" IN ($SQL_codes, 'ADMIN')");
if(!$subsites) $subsites = new ArrayList();
$rolesSubsites = DataObject::get(
'Subsite',
"\"Subsite\".\"Title\" != ''",
'')->leftJoin('Group_Subsites', "\"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"")
$rolesSubsites = DataList::create('Subsite')
->where("\"Subsite\".\"Title\" != ''")
->leftJoin('Group_Subsites', "\"Group_Subsites\".\"SubsiteID\" = \"Subsite\".\"ID\"")
->innerJoin('Group', "\"Group\".\"ID\" = \"Group_Subsites\".\"GroupID\" OR \"Group\".\"AccessAllSubsites\" = 1")
->innerJoin('Group_Members', "\"Group_Members\".\"GroupID\"=\"Group\".\"ID\" AND \"Group_Members\".\"MemberID\" = $member->ID")
->innerJoin('Group_Roles', "\"Group_Roles\".\"GroupID\"=\"Group\".\"ID\"")
@ -534,6 +536,7 @@ JS;
self::$_cache_accessible_sites[$cacheKey] = $subsites;
return $subsites;
}

View File

@ -14,6 +14,7 @@ en_US:
Subsite:
PLURALNAME: "Subsits"
SINGULARNAME: "Subsite"
DOMAINSAVEFIRST: "You can only add domains after saving for the first time"
SubsiteDomain:
PLURALNAME: "Subsite Domains"
SINGULARNAME: "Subsite Domain"

View File

@ -15,6 +15,7 @@ nb_NO:
Subsite:
PLURALNAME: "Subdomener"
SINGULARNAME: "Subdomene"
DOMAINSAVEFIRST: "You can only add domains after saving for the first time"
SubsiteDomain:
PLURALNAME: "Subsite Domains"
SINGULARNAME: "Subsite Domain"

View File

@ -15,6 +15,7 @@ tr_TR:
Subsite:
PLURALNAME: "Alt Siteler"
SINGULARNAME: "Alt Site"
DOMAINSAVEFIRST: "You can only add domains after saving for the first time"
SubsiteDomain:
PLURALNAME: "Subsite Domains"
SINGULARNAME: "Subsite Domain"