mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
MINOR pass tests
This commit is contained in:
parent
3dd9b2a1e4
commit
fa21df693f
@ -48,27 +48,20 @@ class SiteTreeSubsites extends SiteTreeDecorator {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if we're currently looking at the main site.
|
|
||||||
* @return boolean TRUE main site | FALSE sub-site
|
|
||||||
*/
|
|
||||||
function isMainSite() {
|
|
||||||
if($this->owner->SubsiteID == 0) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update any requests to limit the results to the current site
|
* Update any requests to limit the results to the current site
|
||||||
*/
|
*/
|
||||||
function augmentSQL(SQLQuery &$query) {
|
function augmentSQL(SQLQuery &$query) {
|
||||||
if(Subsite::$disable_subsite_filter) return;
|
if(Subsite::$disable_subsite_filter) return;
|
||||||
|
|
||||||
$q = defined('DB::USE_ANSI_SQL') ? '"' : '`';
|
// Don't run on delete queries, since they are always tied to
|
||||||
|
// a specific ID.
|
||||||
if ($query->delete) return;
|
if ($query->delete) 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 || (!preg_match('/\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->where[0]))) {
|
if (!$query->where || (!preg_match('/\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->where[0]))) {
|
||||||
|
|
||||||
if (Subsite::$force_subsite) $subsiteID = Subsite::$force_subsite;
|
if (Subsite::$force_subsite) $subsiteID = Subsite::$force_subsite;
|
||||||
else {
|
else {
|
||||||
if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
|
if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
|
||||||
@ -77,11 +70,9 @@ class SiteTreeSubsites extends SiteTreeDecorator {
|
|||||||
|
|
||||||
// The foreach is an ugly way of getting the first key :-)
|
// The foreach is an ugly way of getting the first key :-)
|
||||||
foreach($query->from as $tableName => $info) {
|
foreach($query->from as $tableName => $info) {
|
||||||
$where = "{$q}$tableName{$q}.{$q}SubsiteID{$q} IN ($subsiteID)";
|
|
||||||
|
|
||||||
// The tableName should be SiteTree or SiteTree_Live...
|
// The tableName should be SiteTree or SiteTree_Live...
|
||||||
if(strpos($tableName,'SiteTree') === false) break;
|
if(strpos($tableName,'SiteTree') === false) break;
|
||||||
$query->where[] = $where;
|
$query->where[] = "\"$tableName\".\"SubsiteID\" IN ($subsiteID)";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -97,11 +88,8 @@ class SiteTreeSubsites extends SiteTreeDecorator {
|
|||||||
|
|
||||||
protected $nextWriteDoesntCustomise = false;
|
protected $nextWriteDoesntCustomise = false;
|
||||||
|
|
||||||
function augmentBeforeWrite() {
|
function onBeforeWrite() {
|
||||||
// if the page hasn't been written to a database table yet and no subsite has been set, then give it a subsite
|
if(!$this->owner->ID && !$this->owner->SubsiteID) $this->owner->SubsiteID = Subsite::currentSubsiteID();
|
||||||
if((!is_numeric($this->owner->ID) || $this->owner->ID == 0) && !$this->owner->SubsiteID) {
|
|
||||||
$this->owner->SubsiteID = Subsite::currentSubsiteID();
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the content has been changed, then the page should be marked as 'custom content'
|
// If the content has been changed, then the page should be marked as 'custom content'
|
||||||
if(!$this->nextWriteDoesntCustomise && $this->owner->ID && $this->owner->MasterPageID && !$this->owner->CustomContent) {
|
if(!$this->nextWriteDoesntCustomise && $this->owner->ID && $this->owner->MasterPageID && !$this->owner->CustomContent) {
|
||||||
@ -117,6 +105,8 @@ class SiteTreeSubsites extends SiteTreeDecorator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->nextWriteDoesntCustomise = false;
|
$this->nextWriteDoesntCustomise = false;
|
||||||
|
|
||||||
|
parent::onBeforeWrite();
|
||||||
}
|
}
|
||||||
|
|
||||||
function onAfterWrite(&$original) {
|
function onAfterWrite(&$original) {
|
||||||
|
@ -27,7 +27,7 @@ class SubsitesVirtualPageTest extends SapphireTest {
|
|||||||
$this->assertEquals($svp->SubsiteID, $subsite->ID);
|
$this->assertEquals($svp->SubsiteID, $subsite->ID);
|
||||||
$this->assertEquals($svp->Title, $linky->Title);
|
$this->assertEquals($svp->Title, $linky->Title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test custom metadata. Reloading Content should not
|
* Test custom metadata. Reloading Content should not
|
||||||
* obliterate our custom fields
|
* obliterate our custom fields
|
||||||
@ -62,7 +62,7 @@ class SubsitesVirtualPageTest extends SapphireTest {
|
|||||||
|
|
||||||
function testFileLinkRewritingOnVirtualPages() {
|
function testFileLinkRewritingOnVirtualPages() {
|
||||||
// File setup
|
// File setup
|
||||||
$this->logInWithPermssion('ADMIN');
|
$this->logInWithPermission('ADMIN');
|
||||||
touch(Director::baseFolder() . '/assets/testscript-test-file.pdf');
|
touch(Director::baseFolder() . '/assets/testscript-test-file.pdf');
|
||||||
|
|
||||||
// Publish the source page
|
// Publish the source page
|
||||||
@ -178,7 +178,6 @@ class SubsitesVirtualPageTest extends SapphireTest {
|
|||||||
$page->doUnpublish();
|
$page->doUnpublish();
|
||||||
|
|
||||||
Subsite::changeSubsite($vp1->SubsiteID);
|
Subsite::changeSubsite($vp1->SubsiteID);
|
||||||
$_REQUEST['showqueries']=1;
|
|
||||||
$onLive = Versioned::get_one_by_stage('SubsitesVirtualPage', 'Live', "SiteTree_Live.ID = ".$vp1->ID);
|
$onLive = Versioned::get_one_by_stage('SubsitesVirtualPage', 'Live', "SiteTree_Live.ID = ".$vp1->ID);
|
||||||
$this->assertFalse($onLive, 'SVP has been removed from live');
|
$this->assertFalse($onLive, 'SVP has been removed from live');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user