mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
BUGFIX: Don't publish virtual pages on regular page publish unless the page has already been published. (from r93529) (from r96760)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@102391 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
ca29cc367c
commit
d9bd1af9ec
@ -1911,7 +1911,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
$linkedPages = DataObject::get("VirtualPage", "\"CopyContentFromID\" = $this->ID");
|
$linkedPages = DataObject::get("VirtualPage", "\"CopyContentFromID\" = $this->ID");
|
||||||
if($linkedPages) foreach($linkedPages as $page) {
|
if($linkedPages) foreach($linkedPages as $page) {
|
||||||
$page->copyFrom($page->CopyContentFrom());
|
$page->copyFrom($page->CopyContentFrom());
|
||||||
$page->doPublish();
|
$page->write();
|
||||||
|
if($page->ExistsOnLive) $page->doPublish();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fix links that are different on staging vs live
|
// Fix links that are different on staging vs live
|
||||||
|
@ -26,17 +26,25 @@ class VirtualPageTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that, after you publish the source page of a virtual page, all the virtual pages
|
* Test that, after you publish the source page of a virtual page, all the already published
|
||||||
* are published
|
* virtual pages are published
|
||||||
*/
|
*/
|
||||||
function testPublishingSourcePagePublishesVirtualPages() {
|
function testPublishingSourcePagePublishesAlreadyPublishedVirtualPages() {
|
||||||
$this->logInWithPermssion('ADMIN');
|
$this->logInWithPermssion('ADMIN');
|
||||||
|
|
||||||
$master = $this->objFromFixture('Page', 'master');
|
$master = $this->objFromFixture('Page', 'master');
|
||||||
|
$master->doPublish();
|
||||||
|
|
||||||
$master->Title = "New title";
|
$master->Title = "New title";
|
||||||
$master->MenuTitle = "New menutitle";
|
$master->MenuTitle = "New menutitle";
|
||||||
$master->Content = "<p>New content</p>";
|
$master->Content = "<p>New content</p>";
|
||||||
$master->write();
|
$master->write();
|
||||||
|
|
||||||
|
$vp1 = DataObject::get_by_id("VirtualPage", $this->idFromFixture('VirtualPage', 'vp1'));
|
||||||
|
$vp2 = DataObject::get_by_id("VirtualPage", $this->idFromFixture('VirtualPage', 'vp2'));
|
||||||
|
$this->assertTrue($vp1->doPublish());
|
||||||
|
$this->assertTrue($vp2->doPublish());
|
||||||
|
|
||||||
$master->doPublish();
|
$master->doPublish();
|
||||||
|
|
||||||
Versioned::reading_stage("Live");
|
Versioned::reading_stage("Live");
|
||||||
@ -133,7 +141,6 @@ class VirtualPageTest extends SapphireTest {
|
|||||||
$p->write();
|
$p->write();
|
||||||
$p->doPublish();
|
$p->doPublish();
|
||||||
|
|
||||||
// With no source page, we can't publish
|
|
||||||
$vp = new VirtualPage();
|
$vp = new VirtualPage();
|
||||||
$vp->CopyContentFromID = $p->ID;
|
$vp->CopyContentFromID = $p->ID;
|
||||||
$vp->write();
|
$vp->write();
|
||||||
@ -151,4 +158,64 @@ class VirtualPageTest extends SapphireTest {
|
|||||||
$this->assertNull(DB::query("SELECT \"ID\" FROM \"SiteTree_Live\" WHERE \"ID\" = $vp->ID")->value());
|
$this->assertNull(DB::query("SELECT \"ID\" FROM \"SiteTree_Live\" WHERE \"ID\" = $vp->ID")->value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testVirtualPagesArentInappropriatelyPublished() {
|
||||||
|
// Fixture
|
||||||
|
$p = new Page();
|
||||||
|
$p->Content = "test content";
|
||||||
|
$p->write();
|
||||||
|
$vp = new VirtualPage();
|
||||||
|
$vp->CopyContentFromID = $p->ID;
|
||||||
|
$vp->write();
|
||||||
|
|
||||||
|
// VP is oragne
|
||||||
|
$this->assertTrue($vp->IsAddedToStage);
|
||||||
|
|
||||||
|
// VP is still orange after we publish
|
||||||
|
$p->doPublish();
|
||||||
|
$this->fixVersionNumberCache($vp);
|
||||||
|
$this->assertTrue($vp->IsAddedToStage);
|
||||||
|
|
||||||
|
// A new VP created after P's initial construction
|
||||||
|
$vp2 = new VirtualPage();
|
||||||
|
$vp2->CopyContentFromID = $p->ID;
|
||||||
|
$vp2->write();
|
||||||
|
$this->assertTrue($vp2->IsAddedToStage);
|
||||||
|
|
||||||
|
// Also remains orange after a republish
|
||||||
|
$p->Content = "new content";
|
||||||
|
$p->write();
|
||||||
|
$p->doPublish();
|
||||||
|
$this->fixVersionNumberCache($vp2);
|
||||||
|
$this->assertTrue($vp2->IsAddedToStage);
|
||||||
|
|
||||||
|
// VP is now published
|
||||||
|
$vp->doPublish();
|
||||||
|
|
||||||
|
$this->fixVersionNumberCache($vp);
|
||||||
|
$this->assertTrue($vp->ExistsOnLive);
|
||||||
|
$this->assertFalse($vp->IsModifiedOnStage);
|
||||||
|
|
||||||
|
// P edited, VP and P both go green
|
||||||
|
$p->Content = "third content";
|
||||||
|
$p->write();
|
||||||
|
|
||||||
|
$this->fixVersionNumberCache($vp, $p);
|
||||||
|
$this->assertTrue($p->IsModifiedOnStage);
|
||||||
|
$this->assertTrue($vp->IsModifiedOnStage);
|
||||||
|
|
||||||
|
// Publish, VP goes black
|
||||||
|
$p->doPublish();
|
||||||
|
$this->fixVersionNumberCache($vp);
|
||||||
|
$this->assertTrue($vp->ExistsOnLive);
|
||||||
|
$this->assertFalse($vp->IsModifiedOnStage);
|
||||||
|
}
|
||||||
|
|
||||||
|
function fixVersionNumberCache($page) {
|
||||||
|
$pages = func_get_args();
|
||||||
|
foreach($pages as $p) {
|
||||||
|
Versioned::prepopulate_versionnumber_cache('SiteTree', 'Stage', array($p->ID));
|
||||||
|
Versioned::prepopulate_versionnumber_cache('SiteTree', 'Live', array($p->ID));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user