From c6b814805277b04e211e127a94b6e8293f59a04b Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 12 Oct 2010 21:48:07 +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() (from r101155) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@111963 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 f7acb58f9..31297309a 100755 --- a/core/model/DataObject.php +++ b/core/model/DataObject.php @@ -971,6 +971,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; } @@ -1101,6 +1103,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. @@ -1110,6 +1114,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)