BUGFIX: Ensure that DataObject::get_one() cache knows which subsite you're on (from r93096)

This commit is contained in:
Tom Rix 2010-03-01 21:41:01 +00:00
parent e91ba528b6
commit 29dda5abdf
4 changed files with 51 additions and 1 deletions

View File

@ -102,5 +102,14 @@ class FileSubsites extends DataObjectDecorator {
return $access;
}
}
/**
* Return a piece of text to keep DataObject cache keys appropriately specific
*/
function cacheKeyComponent() {
return 'subsite-'.Subsite::currentSubsiteID();
}
}

View File

@ -38,4 +38,11 @@ class SiteConfigSubsites extends DataObjectDecorator {
$this->owner->SubsiteID = Subsite::currentSubsiteID();
}
}
/**
* Return a piece of text to keep DataObject cache keys appropriately specific
*/
function cacheKeyComponent() {
return 'subsite-'.Subsite::currentSubsiteID();
}
}

View File

@ -364,6 +364,13 @@ class SiteTreeSubsites extends SiteTreeDecorator {
$this->owner->CrossSubsiteLinkTracking()->setByIDList($linkedPages);
}
/**
* Return a piece of text to keep DataObject cache keys appropriately specific
*/
function cacheKeyComponent() {
return 'subsite-'.Subsite::currentSubsiteID();
}
}
?>

View File

@ -217,4 +217,31 @@ class SubsiteTest extends SapphireTest {
);
}
function testTwoPagesWithSameURLOnDifferentSubsites() {
// Set up a couple of pages with the same URL on different subsites
$s1 = $this->objFromFixture('Subsite','domaintest1');
$s2 = $this->objFromFixture('Subsite','domaintest2');
$p1 = new SiteTree();
$p1->Title = $p1->URLSegment = "test-page";
$p1->SubsiteID = $s1->ID;
$p1->write();
$p2 = new SiteTree();
$p2->Title = $p1->URLSegment = "test-page";
$p2->SubsiteID = $s2->ID;
$p2->write();
// Check that the URLs weren't modified in our set-up
$this->assertEquals($p1->URLSegment, 'test-page');
$this->assertEquals($p2->URLSegment, 'test-page');
// Check that if we switch between the different subsites, we receive the correct pages
Subsite::changeSubsite($s1);
$this->assertEquals($p1->ID, SiteTree::get_by_url('test-page')->ID);
Subsite::changeSubsite($s2);
$this->assertEquals($p2->ID, SiteTree::get_by_url('test-page')->ID);
}
}