Skip to content

Commit b9e2325

Browse files
committed
Add method for resetting persistent entities to their initial values
1 parent aa42016 commit b9e2325

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/wcmf/lib/persistence/PersistentObject.php

+5
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ public function mergeValues(PersistentObject $object);
9393
*/
9494
public function clearValues();
9595

96+
/**
97+
* Reset all values to their original values
98+
*/
99+
public function reset();
100+
96101
/**
97102
* <!--
98103
* Persistence hook methods.

src/wcmf/lib/persistence/PersistentObjectProxy.php

+7
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ public function clearValues() {
175175
return $this->__call(__FUNCTION__, []);
176176
}
177177

178+
/**
179+
* @see PersistentObject::reset()
180+
*/
181+
public function reset() {
182+
return $this->__call(__FUNCTION__, []);
183+
}
184+
178185
/**
179186
* @see PersistentObject::afterCreate()
180187
*/

src/wcmf/lib/persistence/impl/DefaultPersistentObject.php

+10
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ public function __clone() {
222222
$copy->properties = $this->properties;
223223
$copy->valueProperties = $this->valueProperties;
224224
$copy->state = $this->state;
225+
$copy->changedAttributes = $this->changedAttributes;
226+
$copy->originalData = $this->originalData;
225227

226228
return $copy;
227229
}
@@ -266,6 +268,14 @@ public function clearValues() {
266268
}
267269
}
268270

271+
/**
272+
* @see PersistentObject::reset()
273+
*/
274+
public function reset() {
275+
$this->data = $this->originalData;
276+
$this->changedAttributes = [];
277+
}
278+
269279
/**
270280
* Recalculate the object id
271281
*/

0 commit comments

Comments
 (0)