From d825a6bb5c6984323ec070024b299eaaafc82227 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 16 Mar 2010 22:43:51 +0000 Subject: [PATCH] BUGFIX: Prevent failed migrateVersion writes from breaking versioning system in future writes. BUGFIX: MAke site tree pages go green when you save a new draft. API CHANGE: Add option for DataObjectDecorator::onAfterSkippedWrite() git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@101155 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/model/DataObject.php | 7 +++++++ core/model/Versioned.php | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/model/DataObject.php b/core/model/DataObject.php index ef587f4fe..ca798eb6e 100755 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -920,6 +920,8 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity if(self::get_validation_enabled()) { $valid = $this->validate(); if(!$valid->valid()) { + // Used by DODs to clean up after themselves, eg, Versioned + $this->extend('onAfterSkippedWrite'); throw new ValidationException($valid, "Validation error writing a $this->class object: " . $valid->message() . ". Object not written.", E_USER_WARNING); return false; } @@ -1050,6 +1052,8 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity $this->changed = null; } elseif ( $showDebug ) { echo "Debug: no changes for DataObject
"; + // Used by DODs to clean up after themselves, eg, Versioned + $this->extend('onAfterSkippedWrite'); } // Clears the cache for this object so get_one returns the correct object. @@ -1059,6 +1063,9 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity $this->record['Created'] = SS_Datetime::now()->Rfc2822(); } $this->record['LastEdited'] = SS_Datetime::now()->Rfc2822(); + } else { + // Used by DODs to clean up after themselves, eg, Versioned + $this->extend('onAfterSkippedWrite'); } // Write ComponentSets as necessary diff --git a/core/model/Versioned.php b/core/model/Versioned.php index 0f3faf341..c8e4ba7f0 100755 --- a/core/model/Versioned.php +++ b/core/model/Versioned.php @@ -335,7 +335,7 @@ class Versioned extends DataObjectDecorator { if($this->migratingVersion) { $manipulation[$table]['fields']['Version'] = $this->migratingVersion; } - + // If we haven't got a version #, then we're creating a new version. // Otherwise, we're just copying a version to another table if(!isset($manipulation[$table]['fields']['Version'])) { @@ -390,6 +390,14 @@ class Versioned extends DataObjectDecorator { // Add the new version # back into the data object, for accessing after this write if(isset($thisVersion)) $this->owner->Version = str_replace("'","",$thisVersion); } + + /** + * If a write was skipped, then we need to ensure that we don't leave a migrateVersion() + * value lying around for the next write. + */ + function onAfterSkippedWrite() { + $this->migrateVersion(null); + } /** * Determine if a table is supporting the Versioned extensions (e.g. $table_versions does exists)