mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
f880f4e2c7
commit
60958496fc
@ -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);
|
||||
}
|
||||
|
50
tests/model/VirtualPageTest.php
Normal file
50
tests/model/VirtualPageTest.php
Normal 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");
|
||||
}
|
||||
|
||||
}
|
15
tests/model/VirtualPageTest.yml
Normal file
15
tests/model/VirtualPageTest.yml
Normal 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
|
||||
|
Loading…
Reference in New Issue
Block a user