From daeaca110d16128040c86727c65df225e957f7c6 Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Wed, 13 Jan 2010 11:27:09 -0800 Subject: 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. --- modules/gallery/tests/Item_Model_Test.php | 1 + 1 file changed, 1 insertion(+) (limited to 'modules/gallery/tests/Item_Model_Test.php') 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); -- cgit v1.2.3 From 00c73a4b072d2ad4e45323234b847da4f69d99a3 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Fri, 15 Jan 2010 23:53:43 -0800 Subject: Revert "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." This reverts commit daeaca110d16128040c86727c65df225e957f7c6. --- modules/gallery/libraries/MY_ORM.php | 20 ++------------------ modules/gallery/tests/Item_Model_Test.php | 1 - 2 files changed, 2 insertions(+), 19 deletions(-) (limited to 'modules/gallery/tests/Item_Model_Test.php') diff --git a/modules/gallery/libraries/MY_ORM.php b/modules/gallery/libraries/MY_ORM.php index 95fa9006..56c776aa 100644 --- a/modules/gallery/libraries/MY_ORM.php +++ b/modules/gallery/libraries/MY_ORM.php @@ -19,11 +19,12 @@ */ class ORM extends ORM_Core { // Track the original value of this ORM so that we can look it up in ORM::original() - protected $original; + protected $original = null; public function save() { model_cache::clear(); $result = parent::save(); + $this->original = clone $this; return $result; } @@ -47,24 +48,7 @@ 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 c0ac4436..bf5fca1a 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -166,7 +166,6 @@ 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); -- cgit v1.2.3 From cf236a228a8ea3316506f6d855bcade92676674c Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 18 Jan 2010 12:37:20 -0800 Subject: Don't assert_same() now that typecasting is gone from ORM. --- modules/gallery/tests/Item_Model_Test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/gallery/tests/Item_Model_Test.php') diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php index bf5fca1a..d03a03f4 100644 --- a/modules/gallery/tests/Item_Model_Test.php +++ b/modules/gallery/tests/Item_Model_Test.php @@ -52,7 +52,7 @@ class Item_Model_Test extends Unit_Test_Case { public function updating_view_count_only_doesnt_change_updated_date_test() { $item = self::_create_random_item(); $item->reload(); - $this->assert_same(0, $item->view_count); + $this->assert_equal(0, $item->view_count); // Force the updated date to something well known db::build() -- cgit v1.2.3