mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
BUGFIX Respect writeWithoutVersion() when updating VirtualPage relationships in SiteTree->onAfterWrite() (AIR-97)
This commit is contained in:
parent
21d10ad32f
commit
f98bc8480c
@ -1453,11 +1453,17 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
||||
// Need to flush cache to avoid outdated versionnumber references
|
||||
$this->flushCache();
|
||||
|
||||
// Update any virtual pages that might need updating
|
||||
$linkedPages = $this->VirtualPages();
|
||||
if($linkedPages) foreach($linkedPages as $page) {
|
||||
$page->copyFrom($page->CopyContentFrom());
|
||||
$page->write();
|
||||
if($linkedPages) {
|
||||
// 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);
|
||||
foreach($linkedPages as $page) {
|
||||
$page->copyFrom($page->CopyContentFrom());
|
||||
if($withoutVersion) $page->writeWithoutVersion();
|
||||
else $page->write();
|
||||
}
|
||||
}
|
||||
|
||||
parent::onAfterWrite();
|
||||
|
@ -419,6 +419,33 @@ class VirtualPageTest extends SapphireTest {
|
||||
VirtualPage::$initially_copied_fields = $origInitiallyCopiedFields;
|
||||
VirtualPage::$non_virtual_fields = $origNonVirtualField;
|
||||
}
|
||||
|
||||
function testWriteWithoutVersion() {
|
||||
$original = new SiteTree();
|
||||
$original->write();
|
||||
$originalVersion = $original->Version;
|
||||
|
||||
$virtual = new VirtualPage();
|
||||
$virtual->CopyContentFromID = $original->ID;
|
||||
$virtual->write();
|
||||
$virtualVersion = $virtual->Version;
|
||||
|
||||
$virtual->Title = 'changed 1';
|
||||
$virtual->writeWithoutVersion();
|
||||
$this->assertEquals($virtual->Version, $virtualVersion, 'Explicit write');
|
||||
|
||||
$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');
|
||||
|
||||
$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');
|
||||
}
|
||||
}
|
||||
|
||||
class VirtualPageTest_ClassA extends Page implements TestOnly {
|
||||
|
Loading…
Reference in New Issue
Block a user