From 2ca20e8ab17de6d53200c8ace0595f7a6e27bd27 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 8 Sep 2009 21:19:00 -0700 Subject: Check for subscribers *before* going through the process of creating and rendering the email message. Fixes ticket #724. --- modules/notification/helpers/notification.php | 39 ++++++++++++++++++++------- 1 file changed, 29 insertions(+), 10 deletions(-) (limited to 'modules/notification') diff --git a/modules/notification/helpers/notification.php b/modules/notification/helpers/notification.php index d95b3060..88d92b16 100644 --- a/modules/notification/helpers/notification.php +++ b/modules/notification/helpers/notification.php @@ -87,6 +87,11 @@ class notification { } static function send_item_updated($item) { + $subscribers = self::get_subscribers($item); + if (!$subscribers) { + return; + } + $v = new View("item_updated.html"); $v->item = $item; $v->subject = $item->is_album() ? @@ -95,10 +100,15 @@ class notification { t("Photo %title updated", array("title" => $item->original("title"))) : t("Movie %title updated", array("title" => $item->original("title")))); - self::_notify_subscribers($item, $v->render(), $v->subject); + self::_notify($subscribers, $item, $v->render(), $v->subject); } static function send_item_add($item) { + $subscribers = self::get_subscribers($item); + if (!$subscribers) { + return; + } + $parent = $item->parent(); $v = new View("item_added.html"); $v->item = $item; @@ -111,10 +121,15 @@ class notification { t("Movie %title added to %parent_title", array("title" => $item->title, "parent_title" => $parent->title))); - self::_notify_subscribers($item, $v->render(), $v->subject); + self::_notify($subscribers, $item, $v->render(), $v->subject); } static function send_item_deleted($item) { + $subscribers = self::get_subscribers($item); + if (!$subscribers) { + return; + } + $parent = $item->parent(); $v = new View("item_deleted.html"); $v->item = $item; @@ -127,11 +142,16 @@ class notification { : t("Movie %title removed from %parent_title", array("title" => $item->title, "parent_title" => $parent->title))); - self::_notify_subscribers($item, $v->render(), $v->subject); + self::_notify($subscribers, $item, $v->render(), $v->subject); } static function send_comment_published($comment) { $item = $comment->item(); + $subscribers = self::get_subscribers($item); + if (!$subscribers) { + return; + } + $v = new View("comment_published.html"); $v->comment = $comment; $v->subject = $item->is_album() ? @@ -140,7 +160,7 @@ class notification { t("A new comment was published for photo %title", array("title" => $item->title)) : t("A new comment was published for movie %title", array("title" => $item->title))); - self::_notify_subscribers($item, $v->render(), $v->subject); + self::_notify($subscribers, $item, $v->render(), $v->subject); } static function send_pending_notifications() { @@ -179,23 +199,22 @@ class notification { } } - private static function _notify_subscribers($item, $text, $subject) { - $users = self::get_subscribers($item); - if (!empty($users)) { + private static function _notify($subscribers, $item, $text, $subject) { + if (!empty($subscribers)) { if (!batch::in_progress()) { Sendmail::factory() - ->to($users) + ->to($subscribers) ->subject($subject) ->header("Mime-Version", "1.0") ->header("Content-type", "text/html; charset=utf-8") ->message($text) ->send(); } else { - foreach ($users as $user) { + foreach ($subscribers as $subscriber) { $pending = ORM::factory("pending_notification"); $pending->subject = $subject; $pending->text = $text; - $pending->email = $user; + $pending->email = $subscriber; $pending->save(); } } -- cgit v1.2.3