mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
API CHANGE: column names quoted properly
This commit is contained in:
parent
beffd4e526
commit
1b7408dfb1
@ -58,7 +58,7 @@ class FileSubsites extends DataObjectDecorator {
|
||||
}
|
||||
|
||||
if(sizeof($query->select) > 1 && $query->select[0] != 'COUNT(*)'){
|
||||
$query->orderby = 'SubsiteID' . ($query->orderby ? ', ' : '') . $query->orderby;
|
||||
$query->orderby = "{$q}SubsiteID{$q}" . ($query->orderby ? ', ' : '') . $query->orderby;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -315,15 +315,19 @@ JS;
|
||||
$SQL_subdomain = Convert::raw2sql(array_shift($domainNameParts));
|
||||
$SQL_domain = join('.', Convert::raw2sql($domainNameParts));
|
||||
|
||||
if(defined('DB::USE_ANSI_SQL'))
|
||||
$q="\"";
|
||||
else $q='`';
|
||||
|
||||
$subsite = null;
|
||||
if(self::$use_domain) {
|
||||
$subsite = DataObject::get_one('Subsite', "Subdomain = '$SQL_subdomain' AND Domain = '$SQL_domain' AND IsPublic = 1");
|
||||
$subsite = DataObject::get_one('Subsite', "{$q}Subdomain{$q} = '$SQL_subdomain' AND {$q}Domain{$q} = '$SQL_domain' AND {$q}IsPublic{$q} = 1");
|
||||
}
|
||||
if(!$subsite) {
|
||||
$subsite = DataObject::get_one('Subsite', "Subdomain = '$SQL_subdomain' AND IsPublic = 1");
|
||||
$subsite = DataObject::get_one('Subsite', "{$q}Subdomain{$q} = '$SQL_subdomain' AND {$q}IsPublic{$q} = 1");
|
||||
}
|
||||
if(!$subsite) {
|
||||
$subsite = DataObject::get_one('Subsite', "DefaultSite = 1 AND IsPublic = 1");
|
||||
$subsite = DataObject::get_one('Subsite', "{$q}DefaultSite{$q} = 1 AND {$q}IsPublic{$q} = 1");
|
||||
}
|
||||
|
||||
if($subsite) {
|
||||
@ -398,25 +402,17 @@ JS;
|
||||
$SQL_perms = join("','", $SQLa_perm);
|
||||
$memberID = (int)$member->ID;
|
||||
|
||||
if(defined('DB::USE_ANSI_SQL')) {
|
||||
if(defined('DB::USE_ANSI_SQL'))
|
||||
$q="\"";
|
||||
else $q='`';
|
||||
|
||||
$groupCount = DB::query("
|
||||
SELECT COUNT(\"Permission\".\"ID\")
|
||||
FROM \"Permission\"
|
||||
INNER JOIN \"Group\" ON \"Group\".\"ID\" = \"Permission\".\"GroupID\" AND \"Group\".\"SubsiteID\" = 0
|
||||
INNER JOIN \"Group_Members\" USING(\"GroupID\")
|
||||
WHERE \"Permission\".\"Code\" IN ('$SQL_perms') AND \"MemberID\" = {$memberID}
|
||||
SELECT COUNT({$q}Permission{$q}.{$q}ID{$q})
|
||||
FROM {$q}Permission{$q}
|
||||
INNER JOIN {$q}Group{$q} ON {$q}Group{$q}.{$q}ID{$q} = {$q}Permission{$q}.{$q}GroupID{$q} AND {$q}Group{$q}.{$q}SubsiteID{$q} = 0
|
||||
INNER JOIN {$q}Group_Members{$q} USING({$q}GroupID{$q})
|
||||
WHERE {$q}Permission{$q}.{$q}Code{$q} IN ('$SQL_perms') AND {$q}MemberID{$q} = {$memberID}
|
||||
")->value();
|
||||
} else {
|
||||
$groupCount = DB::query("
|
||||
SELECT COUNT(`Permission`.`ID`)
|
||||
FROM `Permission`
|
||||
INNER JOIN `Group` ON `Group`.`ID` = `Permission`.`GroupID` AND `Group`.`SubsiteID` = 0
|
||||
INNER JOIN `Group_Members` USING(`GroupID`)
|
||||
WHERE
|
||||
`Permission`.`Code` IN ('$SQL_perms')
|
||||
AND `MemberID` = {$memberID}
|
||||
")->value();
|
||||
}
|
||||
|
||||
return ($groupCount > 0);
|
||||
}
|
||||
@ -434,6 +430,10 @@ JS;
|
||||
$oldSubsiteID = Session::get('SubsiteID');
|
||||
self::changeSubsite($this->ID);
|
||||
|
||||
if(defined('DB::USE_ANSI_SQL'))
|
||||
$q="\"";
|
||||
else $q='`';
|
||||
|
||||
/*
|
||||
* Copy data from this template to the given subsite. Does this using an iterative depth-first search.
|
||||
* This will make sure that the new parents on the new subsite are correct, and there are no funny
|
||||
@ -444,7 +444,7 @@ JS;
|
||||
while(count($stack) > 0) {
|
||||
list($sourceParentID, $destParentID) = array_pop($stack);
|
||||
|
||||
$children = Versioned::get_by_stage('Page', 'Live', "ParentID = $sourceParentID", '');
|
||||
$children = Versioned::get_by_stage('Page', 'Live', "{$q}ParentID{$q} = $sourceParentID", '');
|
||||
|
||||
if($children) {
|
||||
foreach($children as $child) {
|
||||
@ -555,6 +555,10 @@ class Subsite_Template extends Subsite {
|
||||
$oldSubsiteID = Session::get('SubsiteID');
|
||||
self::changeSubsite($this->ID);
|
||||
|
||||
if(defined('DB::USE_ANSI_SQL'))
|
||||
$q="\"";
|
||||
else $q='`';
|
||||
|
||||
/*
|
||||
* Copy site content from this template to the given subsite. Does this using an iterative depth-first search.
|
||||
* This will make sure that the new parents on the new subsite are correct, and there are no funny
|
||||
@ -565,7 +569,7 @@ class Subsite_Template extends Subsite {
|
||||
while(count($stack) > 0) {
|
||||
list($sourceParentID, $destParentID) = array_pop($stack);
|
||||
|
||||
$children = Versioned::get_by_stage('SiteTree', 'Live', "ParentID = $sourceParentID", '');
|
||||
$children = Versioned::get_by_stage('SiteTree', 'Live', "{$q}ParentID{$q} = $sourceParentID", '');
|
||||
|
||||
if($children) {
|
||||
foreach($children as $child) {
|
||||
@ -582,7 +586,7 @@ class Subsite_Template extends Subsite {
|
||||
* Copy groups from the template to the given subsites. Each of the groups will be created and left
|
||||
* empty.
|
||||
*/
|
||||
$groups = DataObject::get("Group", "SubsiteID = '$this->ID'");
|
||||
$groups = DataObject::get("Group", "{$q}SubsiteID{$q} = '$this->ID'");
|
||||
if($groups) foreach($groups as $group) {
|
||||
$group->duplicateToSubsite($intranet);
|
||||
}
|
||||
|
@ -43,7 +43,11 @@ class SubsiteTest extends SapphireTest {
|
||||
// Test that changeSubsite is working
|
||||
Subsite::changeSubsite($template->ID);
|
||||
|
||||
$tmplHome = DataObject::get_one('SiteTree', "URLSegment = 'home'");
|
||||
if(defined('DB::USE_ANSI_SQL'))
|
||||
$q="\"";
|
||||
else $q='`';
|
||||
|
||||
$tmplHome = DataObject::get_one('SiteTree', "{$q}URLSegment{$q} = 'home'");
|
||||
|
||||
// Publish all the pages in the template, testing that DataObject::get only returns pages from the chosen subsite
|
||||
$pages = DataObject::get("SiteTree");
|
||||
@ -65,7 +69,7 @@ class SubsiteTest extends SapphireTest {
|
||||
// Another test that changeSubsite is working
|
||||
Subsite::changeSubsite($subsite->ID);
|
||||
|
||||
$siteHome = DataObject::get_one('SiteTree', "URLSegment = 'home'");
|
||||
$siteHome = DataObject::get_one('SiteTree', "{$q}URLSegment{$q} = 'home'");
|
||||
$this->assertNotNull($siteHome);
|
||||
$this->assertEquals($subsite->ID, $siteHome->SubsiteID,
|
||||
'createInstance() copies existing pages retaining the same URLSegment'
|
||||
@ -74,7 +78,7 @@ class SubsiteTest extends SapphireTest {
|
||||
|
||||
// Check linking of child pages
|
||||
$tmplStaff = $this->objFromFixture('SiteTree','staff');
|
||||
$siteStaff = DataObject::get_one('SiteTree', "URLSegment = '" . Convert::raw2sql($tmplStaff->URLSegment) . "'");
|
||||
$siteStaff = DataObject::get_one('SiteTree', "{$q}URLSegment{$q} = '" . Convert::raw2sql($tmplStaff->URLSegment) . "'");
|
||||
$this->assertEquals($siteStaff->MasterPageID, $tmplStaff->ID);
|
||||
|
||||
Subsite::changeSubsite(0);
|
||||
|
Loading…
Reference in New Issue
Block a user