Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

BUG Correct live state in SiteTree->getAbsoluteLiveLink()

Was fetching the record from live (and its direct URLSegment),
but all of its parents from the current stage, which might be draft,
leading to "mixed" draft/live nested URLs which might no longer
be reachable in live mode.
  • Loading branch information...
commit 8a514d8b64a3a16f5fcbd40e6cf46f00ac973f79 1 parent 24b0e5d
@chillu chillu authored
Showing with 25 additions and 8 deletions.
  1. +8 −8 code/model/SiteTree.php
  2. +17 −0 tests/model/SiteTreeTest.php
View
16 code/model/SiteTree.php
@@ -455,18 +455,18 @@ public function RelativeLink($action = null) {
* Get the absolute URL for this page on the Live site.
*/
public function getAbsoluteLiveLink($includeStageEqualsLive = true) {
+ $oldStage = Versioned::current_stage();
+ Versioned::reading_stage('Live');
$live = Versioned::get_one_by_stage('SiteTree', 'Live', '"SiteTree"."ID" = ' . $this->ID);
-
if($live) {
$link = $live->AbsoluteLink();
-
- if($includeStageEqualsLive) {
- $link .= '?stage=Live';
- }
-
- return $link;
-
+ if($includeStageEqualsLive) $link .= '?stage=Live';
+ } else {
+ $link = null;
}
+
+ Versioned::reading_stage($oldStage);
+ return $link;
}
/**
View
17 tests/model/SiteTreeTest.php
@@ -356,6 +356,23 @@ function testRelativeLink() {
$this->assertEquals('about-us/edit', $about->RelativeLink('edit'), 'Matches URLSegment plus parameter on top level');
$this->assertEquals('about-us/tom&jerry', $about->RelativeLink('tom&jerry'), 'Doesnt url encode parameter');
}
+
+ function testAbsoluteLiveLink() {
+ $parent = $this->objFromFixture('Page', 'about');
+ $child = $this->objFromFixture('Page', 'staff');
+
+ SiteTree::enable_nested_urls();
+
+ $child->publish('Stage', 'Live');
+ $parent->URLSegment = 'changed-on-live';
+ $parent->write();
+ $parent->publish('Stage', 'Live');
+ $parent->URLSegment = 'changed-on-draft';
+ $parent->write();
+
+ $this->assertStringEndsWith('changed-on-live/my-staff/', $child->getAbsoluteLiveLink(false));
+ $this->assertStringEndsWith('changed-on-live/my-staff/?stage=Live', $child->getAbsoluteLiveLink());
+ }
function testDeleteFromStageOperatesRecursively() {
SiteTree::set_enforce_strict_hierarchy(false);
Please sign in to comment.
Something went wrong with that request. Please try again.