From 9101a751230a485faa554c19ec3eab701e130fb1 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 14 Jan 2012 11:24:40 +0100 Subject: [PATCH] MINOR Code formatting and docs in VirtualPage (no functional changes) --- code/model/VirtualPage.php | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/code/model/VirtualPage.php b/code/model/VirtualPage.php index 88e5228a..46fdfbe8 100644 --- a/code/model/VirtualPage.php +++ b/code/model/VirtualPage.php @@ -196,29 +196,30 @@ class VirtualPage extends Page { * We have to change it to copy all the content from the original page first. */ function onBeforeWrite() { - // On regular write, this will copy from published source. This happens on every publish - if($this->extension_instances['Versioned']->migratingVersion - && Versioned::current_stage() == 'Live') { - if($this->CopyContentFromID) { - $performCopyFrom = true; - + $performCopyFrom = null; + + // Determine if we need to copy values. + if( + $this->extension_instances['Versioned']->migratingVersion + && Versioned::current_stage() == 'Live' + && $this->CopyContentFromID + ) { + // On publication to live, copy from published source. + $performCopyFrom = true; + $stageSourceVersion = DB::query("SELECT \"Version\" FROM \"SiteTree\" WHERE \"ID\" = $this->CopyContentFromID")->value(); $liveSourceVersion = DB::query("SELECT \"Version\" FROM \"SiteTree_Live\" WHERE \"ID\" = $this->CopyContentFromID")->value(); - - // We're going to create a new VP record in SiteTree_versions because the published - // version might not exist, unless we're publishing the latest version - if($stageSourceVersion != $liveSourceVersion) { - $this->extension_instances['Versioned']->migratingVersion = null; - } + + // We're going to create a new VP record in SiteTree_versions because the published + // version might not exist, unless we're publishing the latest version + if($stageSourceVersion != $liveSourceVersion) { + $this->extension_instances['Versioned']->migratingVersion = null; } - - // On regular write, this will copy from draft source. This is only executed when the source - // page changeds } else { + // On regular write, copy from draft source. This is only executed when the source page changes. $performCopyFrom = $this->isChanged('CopyContentFromID', 2) && $this->CopyContentFromID != 0; } - // On publish, this will copy from published source if($performCopyFrom && $this instanceof VirtualPage) { // This flush is needed because the get_one cache doesn't respect site version :-( singleton('SiteTree')->flushCache();