Permalink
Browse files

No commit message

  • Loading branch information...
1 parent a9ce309 commit 1b4c314304735cafdc5da0535807cffca05d4d6b @rixth rixth committed Mar 21, 2010
View
@@ -13,7 +13,6 @@
Object::add_extension('LeftAndMain', 'ControllerSubsites');
Object::add_extension('Group', 'GroupSubsites');
-Object::add_extension('Member', 'MemberSubsites');
Object::add_extension('File', 'FileSubsites');
Object::add_extension('ErrorPage', 'ErrorPageSubsite');
if (class_exists('SiteConfig')) Object::add_extension('SiteConfig', 'SiteConfigSubsites');
@@ -14,9 +14,7 @@ function alternateFilepathForErrorcode($statusCode, $locale = null) {
$subdomainPart = "";
// when there's a controller get it subsite from session
- if (Controller::curr()) {
- $subsite = Subsite::currentSubsite(false);
- }
+ if (Controller::curr()) $subsite = Subsite::currentSubsite(false);
// since this function is called from Page class before the controller is created, we have to get subsite from domain instead
else {
$subsiteID = Subsite::getSubsiteIDForDomain();
@@ -11,9 +11,7 @@ class FileSubsites extends DataObjectDecorator {
static $default_root_folders_global = false;
function extraStatics() {
- if(!method_exists('DataObjectDecorator', 'load_extra_statics')) {
- if($this->owner->class != 'File') return null;
- }
+ if(!method_exists('DataObjectDecorator', 'load_extra_statics') && $this->owner->class != 'File') return null;
return array(
'has_one' => array(
'Subsite' => 'Subsite',
@@ -171,36 +171,6 @@ function alternateCanEdit() {
return (bool)array_intersect($accessibleSites, $linkedSites);
}
- /**
- * Create a duplicate of this group and save it to another subsite.
- * The group and permissions will be duplicated, but not the members.
- * @param $subsiteID int|Subsite The Subsite to copy to, or its ID
- */
- public function duplicateToSubsite($subsiteID = null) {
- if(is_object($subsiteID)) {
- $subsite = $subsiteID;
- $subsiteID = $subsite->ID;
- } else {
- $subsite = DataObject::get_by_id('Subsite', $subsiteID);
- }
-
- $group = $this->owner->duplicate(false);
-
- $group->write();
-
- $subsite->Groups()->add($group->ID);
-
- // Duplicate permissions
- $permissions = $this->owner->Permissions();
- foreach($permissions as $permission) {
- $newPerm = $permission->duplicate(false);
- $newPerm->GroupID = $group->ID;
- $newPerm->write();
- }
-
- return $group;
- }
-
function providePermissions() {
return array(
'SECURITY_SUBSITE_GROUP' => array(
@@ -1,20 +0,0 @@
-<?php
-/**
- * Extension for the Group object to add subsites support
- *
- * @package subsites
- */
-class MemberSubsites extends DataObjectDecorator {
-
- /* Only allow adding to groups we can edit */
- public function saveGroups( $groups ) {
- $groups = explode( ',', $groups ) ;
- $filtered = array() ;
- foreach( $groups as $groupID ) {
- $group = DataObject::get_by_id('Group', $groupID) ;
- if ( $group && $group->canEdit() ) $filtered[] = $groupID ;
- }
- $this->owner->Groups()->setByIDList( $filtered ) ;
- }
-
-}
@@ -64,10 +64,8 @@ function getCMSFields() {
}
function RelatedPageAdminLink($master = false) {
- $page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID)
- : Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
- $otherPage = $master ? Dataobject::get_by_id("SiteTree", $this->RelatedPageID)
- : Dataobject::get_by_id("SiteTree", $this->MasterPageID);
+ $page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID) : Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
+ $otherPage = $master ? Dataobject::get_by_id("SiteTree", $this->RelatedPageID) : Dataobject::get_by_id("SiteTree", $this->MasterPageID);
if(!$page) return;
// Use cmsEditlink only when moving between different pages in the same subsite.
@@ -76,8 +74,7 @@ function RelatedPageAdminLink($master = false) {
}
function AbsoluteLink($master = false) {
- $page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID)
- : Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
+ $page = $master ? Dataobject::get_by_id("SiteTree", $this->MasterPageID) : Dataobject::get_by_id("SiteTree", $this->RelatedPageID);
if(!$page) return;
@@ -19,11 +19,7 @@ function augmentSQL(SQLQuery &$query) {
if(Subsite::$disable_subsite_filter) return;
// If you're querying by ID, ignore the sub-site - this is a bit ugly...
- if (!$query->where || (
- !preg_match('/\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->where[0]) &&
- !preg_match('/\.?(\'|"|`|)SubsiteID(\'|"|`|)( ?)=/', $query->where[0])
- )) {
-
+ if (!$query->where || (!preg_match('/\.(\'|"|`|)ID(\'|"|`|)( ?)=/', $query->where[0]) && !preg_match('/\.?(\'|"|`|)SubsiteID(\'|"|`|)( ?)=/', $query->where[0]))) {
if($context = DataObject::context_obj()) $subsiteID = (int)$context->SubsiteID;
else $subsiteID = (int)Subsite::currentSubsiteID();
@@ -33,10 +29,8 @@ function augmentSQL(SQLQuery &$query) {
}
}
- function augmentBeforeWrite() {
- if((!is_numeric($this->owner->ID) || !$this->owner->ID) && !$this->owner->SubsiteID) {
- $this->owner->SubsiteID = Subsite::currentSubsiteID();
- }
+ function onBeforeWrite() {
+ if((!is_numeric($this->owner->ID) || !$this->owner->ID) && !$this->owner->SubsiteID) $this->owner->SubsiteID = Subsite::currentSubsiteID();
}
/**
@@ -0,0 +1,57 @@
+<?php
+
+class FileSubsitesTest extends SapphireTest {
+ static $fixture_file = 'subsites/tests/SubsiteTest.yml';
+
+ function testTrivialFeatures() {
+ $this->assertTrue(is_array(singleton('FileSubsites')->extraStatics()));
+ $file = new File();
+ $file->Title = 'FileTitle';
+ $this->assertEquals(' * FileTitle', $file->alternateTreeTitle());
+ $file->SubsiteID = $this->objFromFixture('Subsite', 'domaintest1')->ID;
+ $this->assertEquals('FileTitle', $file->TreeTitle());
+ $this->assertTrue(singleton('Folder')->getCMSFields() instanceof FieldSet);
+ Subsite::changeSubsite(1);
+ $this->assertEquals($file->cacheKeyComponent(), 'subsite-1');
+ }
+
+ function testWritingSubsiteID() {
+ $this->objFromFixture('Member', 'admin')->logIn();
+
+ $subsite = $this->objFromFixture('Subsite', 'domaintest1');
+ FileSubsites::$default_root_folders_global = true;
+
+ Subsite::changeSubsite(0);
+ $file = new File();
+ $file->write();
+ $file->onAfterUpload();
+ $this->assertEquals((int)$file->SubsiteID, 0);
+
+ Subsite::changeSubsite($subsite->ID);
+ $this->assertTrue($file->canEdit());
+
+ $file = new File();
+ $file->write();
+ $this->assertEquals((int)$file->SubsiteID, 0);
+ $this->assertTrue($file->canEdit());
+
+ FileSubsites::$default_root_folders_global = false;
+
+ Subsite::changeSubsite($subsite->ID);
+ $file = new File();
+ $file->write();
+ $this->assertEquals($file->SubsiteID, $subsite->ID);
+
+ // Test inheriting from parent folder
+ $folder = new Folder();
+ $folder->write();
+ $this->assertEquals($folder->SubsiteID, $subsite->ID);
+ FileSubsites::$default_root_folders_global = true;
+ $file = new File();
+ $file->ParentID = $folder->ID;
+ $file->onAfterUpload();
+ $this->assertEquals($folder->SubsiteID, $file->SubsiteID);
+ }
+
+
+}
@@ -0,0 +1,25 @@
+<?php
+
+class GroupSubsitesTest extends SapphireTest {
+ static $fixture_file = 'subsites/tests/SubsiteTest.yml';
+
+ protected $requireDefaultRecordsFrom = array('GroupSubsites');
+
+ function testTrivialFeatures() {
+ $this->assertTrue(is_array(singleton('GroupSubsites')->extraStatics()));
+ $this->assertTrue(is_array(singleton('GroupSubsites')->providePermissions()));
+ $this->assertTrue(singleton('Group')->getCMSFields() instanceof FieldSet);
+ }
+
+ function testAlternateTreeTitle() {
+ $group = new Group();
+ $group->Title = 'The A Team';
+ $group->AccessAllSubsites = true;
+ $this->assertEquals($group->TreeTitle(), 'The A Team <i>(global group)</i>');
+ $group->AccessAllSubsites = false;
+ $group->write();
+ $group->Subsites()->add($this->objFromFixture('Subsite', 'domaintest1'));
+ $group->Subsites()->add($this->objFromFixture('Subsite', 'domaintest2'));
+ $this->assertEquals($group->TreeTitle(), 'The A Team <i>(Test 1, Test 2)</i>');
+ }
+}
@@ -0,0 +1,36 @@
+<?php
+
+class SiteConfigSubsitesTest extends SapphireTest {
+ static $fixture_file = 'subsites/tests/SubsiteTest.yml';
+
+ function testEachSubsiteHasAUniqueSiteConfig() {
+ $subsite1 = $this->objFromFixture('Subsite', 'domaintest1');
+ $subsite2 = $this->objFromFixture('Subsite', 'domaintest2');
+
+ $this->assertTrue(is_array(singleton('SiteConfigSubsites')->extraStatics()));
+
+ Subsite::changeSubsite(0);
+ $sc = SiteConfig::current_site_config();
+ $sc->Title = 'RootSite';
+ $sc->write();
+
+ Subsite::changeSubsite($subsite1->ID);
+ $sc = SiteConfig::current_site_config();
+ $sc->Title = 'Subsite1';
+ $sc->write();
+
+ Subsite::changeSubsite($subsite2->ID);
+ $sc = SiteConfig::current_site_config();
+ $sc->Title = 'Subsite2';
+ $sc->write();
+
+ Subsite::changeSubsite(0);
+ $this->assertEquals(SiteConfig::current_site_config()->Title, 'RootSite');
+ Subsite::changeSubsite($subsite1->ID);
+ $this->assertEquals(SiteConfig::current_site_config()->Title, 'Subsite1');
+ Subsite::changeSubsite($subsite2->ID);
+ $this->assertEquals(SiteConfig::current_site_config()->Title, 'Subsite2');
+ $this->assertEquals(SiteConfig::current_site_config()->cacheKeyComponent(), 'subsite-'.$subsite2->ID);
+ }
+
+}
Oops, something went wrong.

0 comments on commit 1b4c314

Please sign in to comment.