/** * Record a record of sending the reminder * * @param string $type type of reminder * @param Object $object an object with a 'code' property * (Confirm_address or Invitation) * @param int $days Number of days after the code was created * @return int $result row ID of the new reminder record */ static function recordReminder($type, $object, $days) { $reminder = new Email_reminder(); $reminder->type = $type; $reminder->code = $object->code; $reminder->days = $days; $reminder->sent = $reminder->created = common_sql_now(); $result = $reminder->insert(); if (empty($result)) { common_log_db_error($reminder, 'INSERT', __FILE__); throw new ServerException(_m('Database error inserting reminder record.')); } return $result; }
/** * Send an invitation reminder. We'll send one after one day, and then * one after three days. * * @todo Abstract this stuff further * * @param array $invitem Invitation obj and any special options * @return boolean success value */ function sendNextReminder($invitem) { list($invitation, $opts) = $invitem; $invDate = strtotime($invitation->created); $now = strtotime('now'); // Days since first invitation was sent $days = ($now - $invDate) / 86499; // 60*60*24 = 86499 // $days = ($now - $regDate) / 120; // Two mins, good for testing $siteName = common_config('site', 'name'); if ($days > 7 && isset($opts['onetime'])) { // Don't send the reminder if we're past the normal reminder window and // we've already pestered her at all before if (Email_reminder::needsReminder(self::INVITE_REMINDER, $invitation)) { common_log(LOG_INFO, "Sending one-time invitation reminder to {$invitation->address}", __FILE__); $subject = _m("Reminder - you have been invited to join {$siteName}!"); return EmailReminderPlugin::sendReminder(self::INVITE_REMINDER, $invitation, $subject, -1); } } switch ($days) { case $days > 1 && $days < 2: if (Email_reminder::needsReminder(self::INVITE_REMINDER, $invitation, 1)) { common_log(LOG_INFO, "Sending one day invitation reminder to {$invitation->address}", __FILE__); // TRANS: Subject for reminder e-mail. %s is the StatusNet sitename. $subject = sprintf(_m('Reminder - You have been invited to join %s!'), $siteName); return EmailReminderPlugin::sendReminder(self::INVITE_REMINDER, $invitation, $subject, 1); } else { return true; } break; case $days > 3 && $days < 4: if (Email_reminder::needsReminder(self::INVITE_REMINDER, $invitation, 3)) { common_log(LOG_INFO, "Sending three day invitation reminder to {$invitation->address}", __FILE__); // TRANS: Subject for reminder e-mail. %s is the StatusNet sitename. $subject = sprintf(_m('Final reminder - you have been invited to join %s!'), $siteName); return EmailReminderPlugin::sendReminder(self::INVITE_REMINDER, $invitation, $subject, 3); } else { return true; } break; default: common_log(LOG_INFO, "No need to send invitation reminder to {$invitation->address}.", __FILE__); break; } return true; }
/** * Send a reminder and record doing so * * @param string $type type of reminder * @param mixed $object Confirm_address or Invitation object * @param string $subject subjct of the email reminder * @param int $day number of days */ static function sendReminder($type, $object, $subject, $day) { // XXX: -1 is a for the special one-time reminder (maybe 30) would be // better? Like >= 30 days? if ($day == -1) { $title = "{$type}-onetime"; } else { $title = "{$type}-{$day}"; } // Record the fact that we sent a reminder if (self::sendReminderEmail($type, $object, $subject, $title)) { try { Email_reminder::recordReminder($type, $object, $day); common_log(LOG_INFO, "Sent {$type} reminder to {$object->address}.", __FILE__); } catch (Exception $e) { // oh noez common_log(LOG_ERR, $e->getMessage(), __FILE__); } } return true; }
/** * Send an email registration confirmation reminder until the user * confirms her registration. We'll send a reminder after one day, * three days, and a full week. * * @todo abstract this bit further * * @param array $regitem confirmation address and any special options * @return boolean success value */ function sendNextReminder($regitem) { list($confirm, $opts) = $regitem; $regDate = strtotime($confirm->modified); // Seems like my best bet $now = strtotime('now'); // Days since registration $days = ($now - $regDate) / 86499; // 60*60*24 = 86499 // $days = ($now - $regDate) / 120; // Two mins, good for testing if ($days > 7 && isset($opts['onetime'])) { // Don't send the reminder if we're past the normal reminder window and // we've already pestered her at all before if (Email_reminder::needsReminder(self::REGISTER_REMINDER, $confirm)) { common_log(LOG_INFO, "Sending one-time registration confirmation reminder to {$confirm->address}", __FILE__); $subject = _m("Reminder - please confirm your registration!"); return EmailReminderPlugin::sendReminder(self::REGISTER_REMINDER, $confirm, $subject, -1); } } // Welcome to one of the ugliest switch statement I've ever written switch ($days) { case $days > 1 && $days < 2: if (Email_reminder::needsReminder(self::REGISTER_REMINDER, $confirm, 1)) { common_log(LOG_INFO, "Sending one day registration confirmation reminder to {$confirm->address}", __FILE__); // TRANS: Subject for reminder e-mail. $subject = _m('Reminder - please confirm your registration!'); return EmailReminderPlugin::sendReminder(self::REGISTER_REMINDER, $confirm, $subject, 1); } else { return true; } break; case $days > 3 && $days < 4: if (Email_reminder::needsReminder(self::REGISTER_REMINDER, $confirm, 3)) { common_log(LOG_INFO, "Sending three day registration confirmation reminder to {$confirm->address}", __FILE__); // TRANS: Subject for reminder e-mail. $subject = _m('Second reminder - please confirm your registration!'); return EmailReminderPlugin::sendReminder(self::REGISTER_REMINDER, $confirm, $subject, 3); } else { return true; } break; case $days > 7 && $days < 8: if (Email_reminder::needsReminder(self::REGISTER_REMINDER, $confirm, 7)) { common_log(LOG_INFO, "Sending one week registration confirmation reminder to {$confirm->address}", __FILE__); // TRANS: Subject for reminder e-mail. $subject = _m('Final reminder - please confirm your registration!'); return EmailReminderPlugin::sendReminder(self::REGISTER_REMINDER, $confirm, $subject, 7); } else { return true; } break; default: common_log(LOG_INFO, "No need to send registration reminder to {$confirm->address}.", __FILE__); break; } return true; }