mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API CHANGE Moved DataObject->writeWithoutVersion() to Versioned extension
BUGFIX Don't create new version on related VirtualPage records in SiteTree->onAfterWrite() when the write was triggered through writeWithoutVersion(). Use a new $_nextWriteWithoutVersion flag replacing the -1 Version number for this purpose (AIR-97)
This commit is contained in:
parent
3eda9dbf12
commit
9451993d74
@ -1173,20 +1173,6 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a write without affecting the version table.
|
||||
* On objects without versioning.
|
||||
*
|
||||
* @return int The ID of the record
|
||||
*/
|
||||
public function writeWithoutVersion() {
|
||||
$this->changed['Version'] = 1;
|
||||
if(!isset($this->record['Version'])) {
|
||||
$this->record['Version'] = -1;
|
||||
}
|
||||
return $this->write();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete this data object.
|
||||
* $this->onBeforeDelete() gets called.
|
||||
|
@ -39,6 +39,14 @@ class Versioned extends DataExtension {
|
||||
*/
|
||||
protected static $cache_versionnumber;
|
||||
|
||||
/**
|
||||
* @var Boolean Flag which is temporarily changed during the write() process
|
||||
* to influence augmentWrite() behaviour. If set to TRUE, no new version will be created
|
||||
* for the following write. Needs to be public as other classes introspect this state
|
||||
* during the write process in order to adapt to this versioning behaviour.
|
||||
*/
|
||||
public $_nextWriteWithoutVersion = false;
|
||||
|
||||
/**
|
||||
* Additional database columns for the new
|
||||
* "_versions" table. Used in {@link augmentDatabase()}
|
||||
@ -511,7 +519,9 @@ class Versioned extends DataExtension {
|
||||
}
|
||||
|
||||
// Putting a Version of -1 is a signal to leave the version table alone, despite their being no version
|
||||
if($manipulation[$table]['fields']['Version'] < 0) unset($manipulation[$table]['fields']['Version']);
|
||||
if($manipulation[$table]['fields']['Version'] < 0 || $this->_nextWriteWithoutVersion) {
|
||||
unset($manipulation[$table]['fields']['Version']);
|
||||
}
|
||||
|
||||
if(!$this->hasVersionField($table)) unset($manipulation[$table]['fields']['Version']);
|
||||
|
||||
@ -538,6 +548,21 @@ class Versioned extends DataExtension {
|
||||
if(isset($thisVersion)) $this->owner->Version = str_replace("'","",$thisVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a write without affecting the version table.
|
||||
* On objects without versioning.
|
||||
*
|
||||
* @return int The ID of the record
|
||||
*/
|
||||
public function writeWithoutVersion() {
|
||||
$this->_nextWriteWithoutVersion = true;
|
||||
return $this->owner->write();
|
||||
}
|
||||
|
||||
function onAfterWrite() {
|
||||
$this->_nextWriteWithoutVersion = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* If a write was skipped, then we need to ensure that we don't leave a migrateVersion()
|
||||
* value lying around for the next write.
|
||||
|
Loading…
Reference in New Issue
Block a user