diff --git a/code/model/SiteTree.php b/code/model/SiteTree.php index 645fe07a..2e495079 100644 --- a/code/model/SiteTree.php +++ b/code/model/SiteTree.php @@ -1448,7 +1448,7 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid // The only way after a write() call to determine if it was triggered by a writeWithoutVersion(), // which we have to pass on to the virtual page writes as well. $previous = ($this->Version > 1) ? Versioned::get_version($this->class, $this->ID, $this->Version-1) : null; - $withoutVersion = (!$previous || $previous->Version == $this->Version); + $withoutVersion = $this->getExtensionInstance('Versioned')->_nextWriteWithoutVersion; foreach($linkedPages as $page) { $page->copyFrom($page->CopyContentFrom()); if($withoutVersion) $page->writeWithoutVersion(); diff --git a/tests/model/VirtualPageTest.php b/tests/model/VirtualPageTest.php index 3072744c..a1c850f2 100644 --- a/tests/model/VirtualPageTest.php +++ b/tests/model/VirtualPageTest.php @@ -423,28 +423,48 @@ class VirtualPageTest extends SapphireTest { function testWriteWithoutVersion() { $original = new SiteTree(); $original->write(); + // Create a second version (different behaviour), + // as SiteTree->onAfterWrite() checks for Version == 1 + $original->Title = 'prepare'; + $original->write(); $originalVersion = $original->Version; $virtual = new VirtualPage(); $virtual->CopyContentFromID = $original->ID; $virtual->write(); + // Create a second version, see above. + $virtual->Title = 'prepare'; + $virtual->write(); $virtualVersion = $virtual->Version; $virtual->Title = 'changed 1'; $virtual->writeWithoutVersion(); - $this->assertEquals($virtual->Version, $virtualVersion, 'Explicit write'); + $this->assertEquals( + $virtual->Version, + $virtualVersion, + 'writeWithoutVersion() on VirtualPage doesnt increment version' + ); $original->Title = 'changed 2'; $original->writeWithoutVersion(); + DataObject::flush_and_destroy_cache(); $virtual = DataObject::get_by_id('VirtualPage', $virtual->ID, false); - $this->assertEquals($virtual->Version, $virtualVersion, 'Implicit write through original'); + $this->assertEquals( + $virtual->Version, + $virtualVersion, + 'writeWithoutVersion() on original page doesnt increment version on related VirtualPage' + ); $original->Title = 'changed 3'; $original->write(); DataObject::flush_and_destroy_cache(); $virtual = DataObject::get_by_id('VirtualPage', $virtual->ID, false); - $this->assertGreaterThan($virtualVersion, $virtual->Version, 'Implicit write through original'); + $this->assertGreaterThan( + $virtualVersion, + $virtual->Version, + 'write() on original page does increment version on related VirtualPage' + ); } }