mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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
This commit is contained in:
parent
7d248e6835
commit
c6b8148052
@ -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 "<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.
|
||||
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user