]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/EmailSummary/siteemailsummaryhandler.php
Merge commit 'refs/merge-requests/159' of git://gitorious.org/statusnet/mainline...
[quix0rs-gnu-social.git] / plugins / EmailSummary / siteemailsummaryhandler.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  *
5  * Handler for queue items of type 'sitesum', sends email summaries
6  * to all users on the site.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Affero General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Affero General Public License for more details.
17  *
18  * You should have received a copy of the GNU Affero General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  * @category  Sample
22  * @package   StatusNet
23  * @author    Evan Prodromou <evan@status.net>
24  * @copyright 2010 StatusNet, Inc.
25  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
26  * @link      http://status.net/
27  */
28
29 if (!defined('STATUSNET')) {
30     exit(1);
31 }
32
33 /**
34  *
35  * Handler for queue items of type 'sitesum', sends email summaries
36  * to all users on the site.
37  *
38  * @category  Email
39  * @package   StatusNet
40  * @author    Evan Prodromou <evan@status.net>
41  * @copyright 2010 StatusNet, Inc.
42  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
43  * @link      http://status.net/
44  */
45 class SiteEmailSummaryHandler extends QueueHandler
46 {
47     /**
48      * Return transport keyword which identifies items this queue handler
49      * services; must be defined for all subclasses.
50      *
51      * Must be 8 characters or less to fit in the queue_item database.
52      * ex "email", "jabber", "sms", "irc", ...
53      *
54      * @return string
55      */
56     function transport()
57     {
58         return 'sitesum';
59     }
60
61     /**
62      * Handle the site
63      *
64      * @param mixed $object
65      * @return boolean true on success, false on failure
66      */
67     function handle($object)
68     {
69         $qm = QueueManager::get();
70
71         try {
72             // Enqueue a summary for all users
73
74             $user = new User();
75             $user->find();
76
77             while ($user->fetch()) {
78                 try {
79                     $qm->enqueue($user->id, 'usersum');
80                 } catch (Exception $e) {
81                     common_log(LOG_WARNING, $e->getMessage());
82                     continue;
83                 }
84             }
85         } catch (Exception $e) {
86             common_log(LOG_WARNING, $e->getMessage());
87         }
88
89         return true;
90     }
91 }