3 * StatusNet - the distributed open-source microblogging tool
4 * Copyright (C) 2008, 2009, StatusNet, Inc.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
16 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 if (!defined('GNUSOCIAL') && !defined('STATUSNET')) { exit(1); }
23 * Base class for queue handlers.
25 * As extensions of the Daemon class, each queue handler has the ability
26 * to launch itself in the background, at which point it'll pass control
27 * to the configured QueueManager class to poll for updates.
29 * Subclasses must override at least the following methods:
34 class DistribQueueHandler
37 * Return transport keyword which identifies items this queue handler
38 * services; must be defined for all subclasses.
40 * Must be 8 characters or less to fit in the queue_item database.
41 * ex "email", "jabber", "sms", "irc", ...
46 public function transport()
52 * Handle distribution of a notice after we've saved it:
53 * @li add to local recipient inboxes
54 * @li send email notifications to local @-reply targets
55 * @li run final EndNoticeSave plugin events
56 * @li put any remaining post-processing into the queues
58 * If this function indicates failure, a warning will be logged
59 * and the item is placed back in the queue to be re-run.
61 * @param Notice $notice
62 * @return boolean true on success, false on failure
64 public function handle(Notice $notice)
66 // We have to manually add attentions to non-profile subs and non-mentions
67 $ptAtts = $notice->getAttentionsFromProfileTags();
68 foreach (array_keys($ptAtts) as $profile_id) {
69 $profile = Profile::getKV('id', $profile_id);
70 if ($profile instanceof Profile) {
72 common_debug('Adding Attention for '.$notice->getID().' profile '.$profile->getID());
73 Attention::saveNew($notice, $profile);
74 } catch (Exception $e) {
75 $this->logit($notice, $e);
81 $notice->sendReplyNotifications();
82 } catch (Exception $e) {
83 $this->logit($notice, $e);
87 Event::handle('EndNoticeDistribute', array($notice));
88 } catch (Exception $e) {
89 $this->logit($notice, $e);
93 Event::handle('EndNoticeSave', array($notice));
94 } catch (Exception $e) {
95 $this->logit($notice, $e);
99 // Enqueue for other handlers
100 common_enqueue_notice($notice);
101 } catch (Exception $e) {
102 $this->logit($notice, $e);
108 protected function logit($notice, $e)
110 common_log(LOG_ERR, "Distrib queue exception saving notice $notice->id: " .
111 $e->getMessage() . ' ' .
112 str_replace("\n", " ", $e->getTraceAsString()));
114 // We'll still return true so we don't get stuck in a loop
115 // trying to run a bad insert over and over...