From 4ad5d55ecf65fb1c9f58211b37f8f111e9ca0c7b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Fri, 13 Feb 2009 10:52:26 -0500 Subject: Add events for filtering and logging new notices --- classes/Notice.php | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'classes') diff --git a/classes/Notice.php b/classes/Notice.php index 329988368..6db59c96e 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -154,32 +154,37 @@ class Notice extends Memcached_DataObject $notice->source = $source; $notice->uri = $uri; - $id = $notice->insert(); + if (Event::handle('StartNoticeSave', array(&$notice))) { - if (!$id) { - common_log_db_error($notice, 'INSERT', __FILE__); - return _('Problem saving notice.'); - } - - # Update the URI after the notice is in the database - if (!$uri) { - $orig = clone($notice); - $notice->uri = common_notice_uri($notice); + $id = $notice->insert(); - if (!$notice->update($orig)) { - common_log_db_error($notice, 'UPDATE', __FILE__); + if (!$id) { + common_log_db_error($notice, 'INSERT', __FILE__); return _('Problem saving notice.'); } - } - # XXX: do we need to change this for remote users? + # Update the URI after the notice is in the database + if (!$uri) { + $orig = clone($notice); + $notice->uri = common_notice_uri($notice); + + if (!$notice->update($orig)) { + common_log_db_error($notice, 'UPDATE', __FILE__); + return _('Problem saving notice.'); + } + } + + # XXX: do we need to change this for remote users? - $notice->saveReplies(); - $notice->saveTags(); - $notice->saveGroups(); + $notice->saveReplies(); + $notice->saveTags(); + $notice->saveGroups(); - $notice->addToInboxes(); - $notice->query('COMMIT'); + $notice->addToInboxes(); + $notice->query('COMMIT'); + + Event::handle('EndNoticeSave', array($notice)); + } # Clear the cache for subscribed users, so they'll update at next request # XXX: someone clever could prepend instead of clearing the cache -- cgit v1.2.3-54-g00ecf