summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/controllers/albums.php2
-rw-r--r--modules/gallery/controllers/movies.php2
-rw-r--r--modules/gallery/controllers/photos.php2
-rw-r--r--modules/gallery/helpers/gallery_event.php4
-rw-r--r--modules/gallery/libraries/MY_ORM.php27
-rw-r--r--modules/gallery/models/item.php3
-rw-r--r--modules/gallery/tests/Item_Model_Test.php16
7 files changed, 50 insertions, 6 deletions
diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php
index e6d01b90..c378e3ce 100644
--- a/modules/gallery/controllers/albums.php
+++ b/modules/gallery/controllers/albums.php
@@ -192,7 +192,7 @@ class Albums_Controller extends Items_Controller {
}
$album->save();
- module::event("item_updated", $orig, $album);
+ module::event("item_updated", $album);
log::success("content", "Updated album", "<a href=\"albums/$album->id\">view</a>");
message::success(
diff --git a/modules/gallery/controllers/movies.php b/modules/gallery/controllers/movies.php
index 30a5d78c..fc511082 100644
--- a/modules/gallery/controllers/movies.php
+++ b/modules/gallery/controllers/movies.php
@@ -91,7 +91,7 @@ class Movies_Controller extends Items_Controller {
$photo->rename($form->edit_photo->filename->value);
$photo->save();
- module::event("item_updated", $orig, $photo);
+ module::event("item_updated", $photo);
log::success("content", "Updated photo", "<a href=\"photos/$photo->id\">view</a>");
message::success(
diff --git a/modules/gallery/controllers/photos.php b/modules/gallery/controllers/photos.php
index 6a62e859..77627009 100644
--- a/modules/gallery/controllers/photos.php
+++ b/modules/gallery/controllers/photos.php
@@ -84,7 +84,7 @@ class Photos_Controller extends Items_Controller {
$photo->rename($form->edit_photo->filename->value);
$photo->save();
- module::event("item_updated", $orig, $photo);
+ module::event("item_updated", $photo);
log::success("content", "Updated photo", "<a href=\"photos/$photo->id\">view</a>");
message::success(
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index aa11b7c0..2f3a64d3 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -23,7 +23,7 @@ class gallery_event_Core {
access::add_group($group);
}
- static function group_before_delete($group) {
+ static function group_deleted($group) {
access::delete_group($group);
}
@@ -31,7 +31,7 @@ class gallery_event_Core {
access::add_item($item);
}
- static function item_before_delete($item) {
+ static function item_deleted($item) {
access::delete_item($item);
}
diff --git a/modules/gallery/libraries/MY_ORM.php b/modules/gallery/libraries/MY_ORM.php
index 2bd9b4eb..319cbe09 100644
--- a/modules/gallery/libraries/MY_ORM.php
+++ b/modules/gallery/libraries/MY_ORM.php
@@ -18,6 +18,9 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class ORM extends ORM_Core {
+ // Track the original value of this ORM instance so that we can look it up in ORM::original()
+ protected $original = null;
+
public function open_paren() {
$this->db->open_paren();
return $this;
@@ -30,7 +33,29 @@ class ORM extends ORM_Core {
public function save() {
model_cache::clear($this->object_name, $this->{$this->primary_key}, $this->primary_key);
- return parent::save();
+ $result = parent::save();
+ $this->original = $this->object;
+ return $result;
+ }
+
+ public function __set($column, $value) {
+ if (!isset($this->original)) {
+ $this->original = $this->object;
+ }
+
+ return parent::__set($column, $value);
+ }
+
+ public function __unset($column) {
+ if (!isset($this->original)) {
+ $this->original = $this->object;
+ }
+
+ return parent::__unset($column);
+ }
+
+ public function original($column) {
+ return $this->original[$column];
}
}
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 51037073..80f19d26 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -93,6 +93,7 @@ class Item_Model extends ORM_MPTT {
}
public function delete() {
+ $old = clone $this;
module::event("item_before_delete", $this);
$parent = $this->parent();
@@ -114,6 +115,8 @@ class Item_Model extends ORM_MPTT {
@unlink($resize_path);
@unlink($thumb_path);
}
+
+ module::event("item_deleted", $old);
}
/**
diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php
index 615b8997..a21cdc13 100644
--- a/modules/gallery/tests/Item_Model_Test.php
+++ b/modules/gallery/tests/Item_Model_Test.php
@@ -140,4 +140,20 @@ class Item_Model_Test extends Unit_Test_Case {
}
$this->assert_false(true, "Item_Model::rename should not accept / characters");
}
+
+ public function save_original_values_test() {
+ print "START\n";
+ $item = $this->create_random_item();
+ $item->title = "ORIGINAL_VALUE";
+ $item->save();
+
+ print "CHANGE\n";
+ $item->title = "NEW_VALUE";
+
+ //printf("<pre>%s</pre>",print_r($item,1));flush();
+
+ print "COMPARE\n";
+ $this->assert_same("ORIGINAL_VALUE", $item->original("title"));
+ $this->assert_same("NEW_VALUE", $item->title);
+ }
}