summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Almdal <tnalmdal@shaw.ca>2010-01-13 11:27:09 -0800
committerTim Almdal <tnalmdal@shaw.ca>2010-01-13 11:27:09 -0800
commitdaeaca110d16128040c86727c65df225e957f7c6 (patch)
treea9a497b51eb6df8b65d12ca64f40fb47a60f86c9
parent639f1e741a5c9c96db1ab894cea7aa90cad82dbc (diff)
Fix for ticket #978. Don't reset the original property as part of the save processing, because that will overwrite the original values with all the new values. The problem with the original approach is that when changed event handlers used ->original(), it had already been reset as part of the save processing. Went back and forth on either leaving this alone and forcing callers to save the original prior to calling the save function, but there were a few event handlers that used ->original(). This seemed the easier change. So to reset the original you need to call reload() or clear(). There is now an optional parameter on the reload to only reload the original.
-rw-r--r--modules/gallery/libraries/MY_ORM.php20
-rw-r--r--modules/gallery/tests/Item_Model_Test.php1
2 files changed, 19 insertions, 2 deletions
diff --git a/modules/gallery/libraries/MY_ORM.php b/modules/gallery/libraries/MY_ORM.php
index 56c776aa..95fa9006 100644
--- a/modules/gallery/libraries/MY_ORM.php
+++ b/modules/gallery/libraries/MY_ORM.php
@@ -19,12 +19,11 @@
*/
class ORM extends ORM_Core {
// Track the original value of this ORM so that we can look it up in ORM::original()
- protected $original = null;
+ protected $original;
public function save() {
model_cache::clear();
$result = parent::save();
- $this->original = clone $this;
return $result;
}
@@ -48,7 +47,24 @@ class ORM extends ORM_Core {
return parent::__unset($column);
}
+ public function reload($original_only=false) {
+ if (!$original_only) {
+ parent::reload();
+ }
+ $this->original = clone $this;
+ return $this;
+ }
+
+ public function clear() {
+ parent::clear();
+ $this->original = clone $this;
+ return $this;
+ }
+
public function original() {
+ if (!isset($this->original)) {
+ $this->original = clone $this;
+ }
return $this->original;
}
}
diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php
index bf5fca1a..c0ac4436 100644
--- a/modules/gallery/tests/Item_Model_Test.php
+++ b/modules/gallery/tests/Item_Model_Test.php
@@ -166,6 +166,7 @@ class Item_Model_Test extends Unit_Test_Case {
$item = self::_create_random_item();
$item->title = "ORIGINAL_VALUE";
$item->save();
+ $item->reload(false);
$item->title = "NEW_VALUE";
$this->assert_same("ORIGINAL_VALUE", $item->original()->title);