From 3bce0ea42fac3d7e3bf56e8711bcef340bdc97e2 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 12 Jan 2010 23:37:04 +0000 Subject: [PATCH] BUGFIX: Don't publish virtual pages on regular page publish unless the page has already been published. (from r93529) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@96760 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/SiteTree.php | 3 +- tests/model/VirtualPageTest.php | 75 +++++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 5 deletions(-) diff --git a/core/model/SiteTree.php b/core/model/SiteTree.php index 9f975741f..cb08a5d70 100755 --- a/core/model/SiteTree.php +++ b/core/model/SiteTree.php @@ -1884,7 +1884,8 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid $linkedPages = DataObject::get("VirtualPage", "\"CopyContentFromID\" = $this->ID"); if($linkedPages) foreach($linkedPages as $page) { $page->copyFrom($page->CopyContentFrom()); - $page->doPublish(); + $page->write(); + if($page->ExistsOnLive) $page->doPublish(); } // Fix links that are different on staging vs live diff --git a/tests/model/VirtualPageTest.php b/tests/model/VirtualPageTest.php index e3683352e..da33cb0fc 100644 --- a/tests/model/VirtualPageTest.php +++ b/tests/model/VirtualPageTest.php @@ -26,17 +26,25 @@ class VirtualPageTest extends SapphireTest { } /** - * Test that, after you publish the source page of a virtual page, all the virtual pages - * are published + * Test that, after you publish the source page of a virtual page, all the already published + * virtual pages are published */ - function testPublishingSourcePagePublishesVirtualPages() { + function testPublishingSourcePagePublishesAlreadyPublishedVirtualPages() { $this->logInWithPermssion('ADMIN'); $master = $this->objFromFixture('Page', 'master'); + $master->doPublish(); + $master->Title = "New title"; $master->MenuTitle = "New menutitle"; $master->Content = "

New content

"; $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(); Versioned::reading_stage("Live"); @@ -133,7 +141,6 @@ class VirtualPageTest extends SapphireTest { $p->write(); $p->doPublish(); - // With no source page, we can't publish $vp = new VirtualPage(); $vp->CopyContentFromID = $p->ID; $vp->write(); @@ -151,4 +158,64 @@ class VirtualPageTest extends SapphireTest { $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)); + } + } + } \ No newline at end of file