BOINC /
boinc
| 1 | #!/usr/bin/env php |
||
| 2 | |||
|
0 ignored issues
–
show
Coding Style
introduced
by
Loading history...
|
|||
| 3 | <?php |
||
|
0 ignored issues
–
show
|
|||
| 4 | // This file is part of BOINC. |
||
| 5 | // http://boinc.berkeley.edu |
||
| 6 | // Copyright (C) 2008 University of California |
||
| 7 | // |
||
| 8 | // BOINC is free software; you can redistribute it and/or modify it |
||
| 9 | // under the terms of the GNU Lesser General Public License |
||
| 10 | // as published by the Free Software Foundation, |
||
| 11 | // either version 3 of the License, or (at your option) any later version. |
||
| 12 | // |
||
| 13 | // BOINC 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. |
||
| 16 | // See the GNU Lesser General Public License for more details. |
||
| 17 | // |
||
| 18 | // You should have received a copy of the GNU Lesser General Public License |
||
| 19 | // along with BOINC. If not, see <http://www.gnu.org/licenses/>. |
||
| 20 | |||
| 21 | // Script to delete old notifications and send notification emails. |
||
| 22 | // Run once a day. |
||
| 23 | // |
||
| 24 | // We send emails for notifications generated in the last day. |
||
| 25 | // This is a slight kludge - since the timing of period tasks |
||
| 26 | // is not precise, notifications may be delivered twice or not at all. |
||
| 27 | // We use a 1-hour slop factor to err on the side of twice. |
||
| 28 | // |
||
| 29 | |||
| 30 | $cli_only = true; |
||
| 31 | require_once("../inc/boinc_db.inc"); |
||
| 32 | require_once("../inc/util_ops.inc"); |
||
| 33 | require_once("../project/project.inc"); |
||
| 34 | |||
| 35 | // delete notifications older than 90 days |
||
| 36 | // |
||
| 37 | function delete_old_notifies() { |
||
| 38 | $t = time()-90*86400; |
||
| 39 | BoincNotify::delete_aux("create_time < $t"); |
||
| 40 | } |
||
| 41 | |||
| 42 | function send_notify_email($userid, $message) { |
||
| 43 | $user = BoincUser::lookup_id($userid); |
||
| 44 | $subject = "Daily notification summary from ".PROJECT; |
||
| 45 | $body = "The following events occurred in the past day at ".PROJECT.". |
||
| 46 | For details, visit your Account page at |
||
| 47 | ".secure_url_base()."home.php |
||
| 48 | |||
| 49 | $message |
||
| 50 | --------------- |
||
| 51 | To change your email preferences for ".PROJECT.", visit: |
||
| 52 | ".secure_url_base()."edit_forum_preferences_form.php |
||
| 53 | |||
| 54 | Do not reply to this email. |
||
| 55 | "; |
||
| 56 | send_email($user, $subject, $body); |
||
| 57 | |||
| 58 | echo "sending to $user->email_addr\n"; |
||
| 59 | } |
||
| 60 | |||
| 61 | function send_notify_emails() { |
||
| 62 | $db = BoincDb::get(); |
||
| 63 | |||
| 64 | $t = time() - (86400 + 3600); // 1-hour slop factor |
||
| 65 | $query = "select notify.* from ".$db->db_name.".notify, ".$db->db_name.".forum_preferences where forum_preferences.pm_notification=2 and notify.userid = forum_preferences.userid and notify.create_time > $t"; |
||
| 66 | |||
| 67 | $notifies = BoincNotify::enum_general($query); |
||
| 68 | $userid = 0; |
||
| 69 | $message = ""; |
||
| 70 | $i = 1; |
||
| 71 | foreach ($notifies as $notify) { |
||
| 72 | if ($userid && $notify->userid != $userid && strlen($message)) { |
||
| 73 | send_notify_email($userid, $message); |
||
| 74 | $message = ""; |
||
| 75 | $found = false; |
||
| 76 | $i = 1; |
||
| 77 | } |
||
| 78 | $userid = $notify->userid; |
||
| 79 | $x = null; |
||
| 80 | switch ($notify->type) { |
||
| 81 | case NOTIFY_FRIEND_REQ: |
||
| 82 | $x = friend_notify_req_email_line($notify); |
||
| 83 | break; |
||
| 84 | case NOTIFY_FRIEND_ACCEPT: |
||
| 85 | $x = friend_notify_accept_email_line($notify); |
||
| 86 | break; |
||
| 87 | case NOTIFY_PM: |
||
| 88 | $x = pm_email_line($notify); |
||
| 89 | break; |
||
| 90 | case NOTIFY_SUBSCRIBED_THREAD: |
||
| 91 | $x = subscribed_thread_email_line($notify); |
||
| 92 | break; |
||
| 93 | } |
||
| 94 | if ($x) { |
||
| 95 | $message .= "$i) $x\n"; |
||
| 96 | $i++; |
||
| 97 | } else { |
||
| 98 | $notify->delete(); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | if ($userid && strlen($message)) { |
||
| 102 | send_notify_email($userid, $message); |
||
| 103 | } |
||
| 104 | } |
||
| 105 | |||
| 106 | $t = time_str(time()); |
||
| 107 | echo "Starting at $t\n"; |
||
| 108 | |||
| 109 | delete_old_notifies(); |
||
| 110 | send_notify_emails(); |
||
| 111 | |||
| 112 | $t = time_str(time()); |
||
| 113 | echo "Ending at $t\n\n"; |
||
| 114 | |||
| 115 | ?> |
||
| 116 |