BUGFIX: Automatically publish virtual pages when their source pages are published

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.3@75873 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-05-01 05:03:35 +00:00
parent f880f4e2c7
commit 60958496fc
3 changed files with 72 additions and 0 deletions

View File

@ -1434,6 +1434,13 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
SET SiteTree_Live.Sort = SiteTree.Sort
WHERE SiteTree_Live.ParentID = " . sprintf('%d', $this->ParentID));
// Publish any virtual pages that might need publishing
$linkedPages = DataObject::get("VirtualPage", "CopyContentFromID = $this->ID");
if($linkedPages) foreach($linkedPages as $page) {
$page->copyFrom($page->CopyContentFrom());
$page->doPublish();
}
// Handle activities undertaken by decorators
$this->extend('onAfterPublish', $original);
}

View File

@ -0,0 +1,50 @@
<?php
class VirtualPageTest extends SapphireTest {
static $fixture_file = 'sapphire/tests/model/VirtualPageTest.yml';
/**
* Test that, after you update the source page of a virtual page, all the virtual pages
* are updated
*/
function testEditingSourcePageUpdatesVirtualPages() {
$master = $this->objFromFixture('Page', 'master');
$master->Title = "New title";
$master->Content = "<p>New content</p>";
$master->write();
$vp1 = $this->objFromFixture('VirtualPage', 'vp1');
$vp2 = $this->objFromFixture('VirtualPage', 'vp2');
$this->assertEquals("New title", $vp1->Title);
$this->assertEquals("New title", $vp2->Title);
$this->assertEquals("<p>New content</p>", $vp1->Content);
$this->assertEquals("<p>New content</p>", $vp2->Content);
}
/**
* Test that, after you publish the source page of a virtual page, all the virtual pages
* are published
*/
function testPublishingSourcePagePublishesVirtualPages() {
$master = $this->objFromFixture('Page', 'master');
$master->Title = "New title";
$master->Content = "<p>New content</p>";
$master->write();
$master->doPublish();
Versioned::reading_stage("Live");
$vp1 = DataObject::get_by_id("VirtualPage", $this->idFromFixture('VirtualPage', 'vp1'));
$vp2 = DataObject::get_by_id("VirtualPage", $this->idFromFixture('VirtualPage', 'vp2'));
$this->assertNotNull($vp1);
$this->assertNotNull($vp2);
$this->assertEquals("New title", $vp1->Title);
$this->assertEquals("New title", $vp2->Title);
$this->assertEquals("<p>New content</p>", $vp1->Content);
$this->assertEquals("<p>New content</p>", $vp2->Content);
Versioned::reading_stage("Stage");
}
}

View File

@ -0,0 +1,15 @@
Page:
master:
Title: My Page
master2:
Title: My Other Page
holder:
Title: Sub-pages
VirtualPage:
vp1:
CopyContentFrom: =>Page.master
Parent: =>Page.holder
vp2:
CopyContentFrom: =>Page.master
Parent: =>Page.holder