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:
Ingo Schommer 2012-01-14 11:03:45 +01:00
parent 3eda9dbf12
commit 9451993d74
2 changed files with 26 additions and 15 deletions

View File

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

View File

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