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
This commit is contained in:
Sam Minnee 2010-03-16 22:43:51 +00:00
parent 682e7d0f1a
commit d825a6bb5c
2 changed files with 16 additions and 1 deletions

View File

@ -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 "<b>Debug:</b> no changes for DataObject<br />";
// 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

View File

@ -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)