diff --git a/model/DataObject.php b/model/DataObject.php index 30e2d51d2..8b8cb300a 100644 --- a/model/DataObject.php +++ b/model/DataObject.php @@ -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. diff --git a/model/Versioned.php b/model/Versioned.php index 54bd927e2..501b988f0 100644 --- a/model/Versioned.php +++ b/model/Versioned.php @@ -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.