]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/distribqueuehandler.php
don't calculate replies for remote notices
[quix0rs-gnu-social.git] / lib / distribqueuehandler.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2008, 2009, StatusNet, Inc.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
21
22 /**
23  * Base class for queue handlers.
24  *
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.
28  *
29  * Subclasses must override at least the following methods:
30  * - transport
31  * - handle_notice
32  */
33
34 class DistribQueueHandler
35 {
36     /**
37      * Return transport keyword which identifies items this queue handler
38      * services; must be defined for all subclasses.
39      *
40      * Must be 8 characters or less to fit in the queue_item database.
41      * ex "email", "jabber", "sms", "irc", ...
42      *
43      * @return string
44      */
45
46     function transport()
47     {
48         return 'distrib';
49     }
50
51     /**
52      * Here's the meat of your queue handler -- you're handed a Notice
53      * object, which you may do as you will with.
54      *
55      * If this function indicates failure, a warning will be logged
56      * and the item is placed back in the queue to be re-run.
57      *
58      * @param Notice $notice
59      * @return boolean true on success, false on failure
60      */
61     function handle($notice)
62     {
63         // XXX: do we need to change this for remote users?
64
65         try {
66             $notice->saveTags();
67         } catch (Exception $e) {
68             $this->logit($notice, $e);
69         }
70
71         try {
72             $groups = $notice->saveGroups();
73         } catch (Exception $e) {
74             $this->logit($notice, $e);
75         }
76
77         try {
78             $recipients = $notice->getReplies();
79         } catch (Exception $e) {
80             $this->logit($notice, $e);
81         }
82
83         try {
84             $notice->addToInboxes($groups, $recipients);
85         } catch (Exception $e) {
86             $this->logit($notice, $e);
87         }
88
89         try {
90             $notice->saveUrls();
91         } catch (Exception $e) {
92             $this->logit($notice, $e);
93         }
94
95         try {
96             Event::handle('EndNoticeSave', array($notice));
97             // Enqueue for other handlers
98         } catch (Exception $e) {
99             $this->logit($notice, $e);
100         }
101
102         try {
103             common_enqueue_notice($notice);
104         } catch (Exception $e) {
105             $this->logit($notice, $e);
106         }
107
108         return true;
109     }
110
111     protected function logit($notice, $e)
112     {
113         common_log(LOG_ERR, "Distrib queue exception saving notice $notice->id: " .
114             $e->getMessage() . ' ' .
115             str_replace("\n", " ", $e->getTraceAsString()));
116
117         // We'll still return true so we don't get stuck in a loop
118         // trying to run a bad insert over and over...
119     }
120 }
121