summaryrefslogtreecommitdiff
path: root/modules/comment
diff options
context:
space:
mode:
authorBharat Mediratta <bharat@menalto.com>2009-07-16 12:29:16 -0700
committerBharat Mediratta <bharat@menalto.com>2009-07-16 12:31:40 -0700
commit0f766b149d0cee7af664f2321fddc6f04cda70ac (patch)
tree51d8cd4e26df82955d57eefaa46349568d054126 /modules/comment
parent43324fd12a23b35707300ff110f207552c3811f1 (diff)
Second non-trivial change to the event code. We now publish model
related events from within the model handling code. The only exception to this currently is item_created which is challenging because we have to save the item using ORM_MPTT::add_to_parent() before the object itself is fully set up. When we get that down to one call to save() we can publish that event from within the model also.
Diffstat (limited to 'modules/comment')
-rw-r--r--modules/comment/controllers/admin_comments.php4
-rw-r--r--modules/comment/controllers/comments.php1
-rw-r--r--modules/comment/helpers/comment.php5
-rw-r--r--modules/comment/models/comment.php17
4 files changed, 16 insertions, 11 deletions
diff --git a/modules/comment/controllers/admin_comments.php b/modules/comment/controllers/admin_comments.php
index ea76b188..a164f79f 100644
--- a/modules/comment/controllers/admin_comments.php
+++ b/modules/comment/controllers/admin_comments.php
@@ -113,10 +113,6 @@ class Admin_Comments_Controller extends Admin_Controller {
if ($comment->loaded) {
$comment->state = $state;
$comment->save();
- module::event("comment_updated", $comment);
- if ($comment->original("state") == "published" || $comment->state == "published") {
- module::event("item_related_update", $comment->item());
- }
}
}
diff --git a/modules/comment/controllers/comments.php b/modules/comment/controllers/comments.php
index 02c38491..9fb4796e 100644
--- a/modules/comment/controllers/comments.php
+++ b/modules/comment/controllers/comments.php
@@ -152,7 +152,6 @@ class Comments_Controller extends REST_Controller {
$comment->url = $form->edit_comment->url->value;
$comment->text = $form->edit_comment->text->value;
$comment->save();
- module::event("comment_updated", $comment);
print json_encode(
array("result" => "success",
diff --git a/modules/comment/helpers/comment.php b/modules/comment/helpers/comment.php
index 08cba096..3d743325 100644
--- a/modules/comment/helpers/comment.php
+++ b/modules/comment/helpers/comment.php
@@ -61,11 +61,6 @@ class comment_Core {
$comment->server_remote_port = substr($input->server("REMOTE_PORT"), 0, 16);
$comment->save();
- module::event("comment_created", $comment);
- if ($comment->state == "published") {
- module::event("item_related_update", $comment->item());
- }
-
return $comment;
}
diff --git a/modules/comment/models/comment.php b/modules/comment/models/comment.php
index 22c465df..551fb245 100644
--- a/modules/comment/models/comment.php
+++ b/modules/comment/models/comment.php
@@ -61,8 +61,23 @@ class Comment_Model extends ORM {
$this->updated = time();
if (!$this->loaded && empty($this->created)) {
$this->created = $this->updated;
+ $created = true;
}
}
- return parent::save();
+ parent::save();
+
+ if (isset($created)) {
+ module::event("comment_created", $this);
+ } else {
+ module::event("comment_updated", $this);
+ }
+
+ // We only notify on the related items if we're making a visible change, which means moving in
+ // or out of a published state
+ if ($this->original("state") == "published" || $this->state == "published") {
+ module::event("item_related_update", $this->item());
+ }
+
+ return $this;
}
}