From d79dc8344b529281dfb8a8383c529720a429472b Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 29 Jul 2008 22:28:56 -0400 Subject: refactor notice-adding code to one static method on Notice darcs-hash:20080730022856-84dde-f19e4ff5d5ae2603b63b8aebd8f878ec90b3ce22.gz --- maildaemon.php | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) (limited to 'maildaemon.php') diff --git a/maildaemon.php b/maildaemon.php index f8fd7c11a..5be62efb8 100755 --- a/maildaemon.php +++ b/maildaemon.php @@ -115,35 +115,11 @@ class MailerDaemon { } function add_notice($user, $msg) { - $notice = new Notice(); - $notice->is_local = 1; - $notice->profile_id = $user->id; - $notice->content = trim(substr($msg, 0, 140)); - $notice->rendered = common_render_content($notice->content, $notice); - $notice->created = DB_DataObject_Cast::dateTime(); - $notice->query('BEGIN'); - $id = $notice->insert(); - if (!$id) { - $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError'); - $this->log(LOG_ERR, - 'Could not insert ' . common_log_objstring($notice) . - ' for user ' . common_log_objstring($user) . - ': ' . $last_error->message); + $notice = Notice::saveNew($user->id, $msg, 'mail'); + if (is_string($notice)) { + $this->log(LOG_ERR, $notice); return; } - $orig = clone($notice); - $notice->uri = common_notice_uri($notice); - $result = $notice->update($orig); - if (!$result) { - $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError'); - $this->log(LOG_ERR, - 'Could not add URI to ' . common_log_objstring($notice) . - ' for user ' . common_log_objstring($user) . - ': ' . $last_error->message); - return; - } - $notice->query('COMMIT'); - common_save_replies($notice); common_broadcast_notice($notice); $this->log(LOG_INFO, 'Added notice ' . $notice->id . ' from user ' . $user->nickname); -- cgit v1.2.3-54-g00ecf