From 29dda5abdfde0a38b057a36e3ad9034c298f636b Mon Sep 17 00:00:00 2001 From: Tom Rix Date: Mon, 1 Mar 2010 21:41:01 +0000 Subject: [PATCH] BUGFIX: Ensure that DataObject::get_one() cache knows which subsite you're on (from r93096) --- code/FileSubsites.php | 9 +++++++++ code/SiteConfigSubsites.php | 7 +++++++ code/SiteTreeSubsites.php | 7 +++++++ tests/SubsiteTest.php | 29 ++++++++++++++++++++++++++++- 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/code/FileSubsites.php b/code/FileSubsites.php index f82a571..2adcf05 100755 --- a/code/FileSubsites.php +++ b/code/FileSubsites.php @@ -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(); + } + } + diff --git a/code/SiteConfigSubsites.php b/code/SiteConfigSubsites.php index 90584d2..304ab50 100644 --- a/code/SiteConfigSubsites.php +++ b/code/SiteConfigSubsites.php @@ -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(); + } } diff --git a/code/SiteTreeSubsites.php b/code/SiteTreeSubsites.php index aa8c7cb..d0bf81f 100644 --- a/code/SiteTreeSubsites.php +++ b/code/SiteTreeSubsites.php @@ -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(); + } } ?> diff --git a/tests/SubsiteTest.php b/tests/SubsiteTest.php index 07fc5dc..7185ef5 100644 --- a/tests/SubsiteTest.php +++ b/tests/SubsiteTest.php @@ -215,6 +215,33 @@ class SubsiteTest extends SapphireTest { $mainpage->canEdit(), 'Members cant edit pages on the main site if they are not in a group allowing this' ); - } + } + + 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); + } } \ No newline at end of file