Permalink
Browse files

API CHANGE Moved DataObject->writeWithoutVersion() to Versioned exten…

…sion

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)
  • Loading branch information...
1 parent 3eda9db commit 9451993d7475ffe9944585b37e9a397fb5381dbb @chillu chillu committed Jan 14, 2012
Showing with 26 additions and 15 deletions.
  1. +0 −14 model/DataObject.php
  2. +26 −1 model/Versioned.php
View
@@ -1174,20 +1174,6 @@ public function writeComponents($recursive = false) {
}
/**
- * 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.
* Note that in Versioned objects, both Stage and Live will be deleted.
View
@@ -40,6 +40,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()}
* and all Versioned calls extending or creating
@@ -511,7 +519,9 @@ function augmentWrite(&$manipulation) {
}
// 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']);
@@ -539,6 +549,21 @@ function augmentWrite(&$manipulation) {
}
/**
+ * 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.
*/

0 comments on commit 9451993

Please sign in to comment.