]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/EmailReminder/lib/siteconfirmreminderhandler.php
Add ability to send special one-time reminders
[quix0rs-gnu-social.git] / plugins / EmailReminder / lib / siteconfirmreminderhandler.php
1 <?php
2 /*
3  * StatusNet - the distributed open-source microblogging tool
4  *
5  * Handler for reminder queue items which send reminder emails to all users
6  * we would like to complete a given process (e.g.: registration).
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  Email
22  * @package   StatusNet
23  * @author    Zach Copley <zach@status.net>
24  * @copyright 2011 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  * Handler for reminder queue items which send reminder emails to all users
35  * we would like to complete a given process (e.g.: registration)
36  *
37  * @category  Email
38  * @package   StatusNet
39  * @author    Zach Copley <zach@status.net>
40  * @copyright 2011 StatusNet, Inc.
41  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
42  * @link      http://status.net/
43  */
44 class SiteConfirmReminderHandler extends QueueHandler
45 {
46     /**
47      * Return transport keyword which identifies items this queue handler
48      * services; must be defined for all subclasses.
49      *
50      * Must be 8 characters or less to fit in the queue_item database.
51      * ex "email", "jabber", "sms", "irc", ...
52      *
53      * @return string
54      */
55     function transport()
56     {
57         return 'siterem';
58     }
59
60     /**
61      * Handle the site
62      *
63      * @param array $remitem type of reminder to send and any special options
64      * @return boolean true on success, false on failure
65      */
66     function handle($remitem)
67     {
68         list($type, $opts) = $remitem;
69
70         $qm = QueueManager::get();
71
72         try {
73             switch($type) {
74             case UserConfirmRegReminderHandler::REGISTER_REMINDER:
75                 $confirm               = new Confirm_address();
76                 $confirm->address_type = $type;
77                 $confirm->find();
78                 while ($confirm->fetch()) {
79                     try {
80                         $qm->enqueue(array($confirm, $opts), 'uregrem');
81                     } catch (Exception $e) {
82                         common_log(LOG_WARNING, $e->getMessage());
83                         continue;
84                     }
85                 }
86                 break;
87             case UserInviteReminderHandler::INVITE_REMINDER:
88                 $invitation = new Invitation();
89                 $invitation->find();
90                 while ($invitation->fetch()) {
91                     try {
92                         $qm->enqueue(array($invitation, $opts), 'uinvrem');
93                     } catch (Exception $e) {
94                         common_log(LOG_WARNING, $e->getMessage());
95                         continue;
96                     }
97                 }
98                 break;
99             default:
100                 // WTF?
101                 common_log(
102                     LOG_ERR,
103                     "Received unknown confirmation address type",
104                     __FILE__
105                 );
106             }
107         } catch (Exception $e) {
108             common_log(LOG_ERR, $e->getMessage());
109             return false;
110         }
111
112         return true;
113     }
114 }