Merge branch '1.0.x' into testing
* 1.0.x: Add ability to send special one-time reminders
This commit is contained in:
commit
6943f00e37
|
@ -114,22 +114,25 @@ class EmailReminderPlugin extends Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Send a reminder and record doing so
|
||||||
*
|
*
|
||||||
* @param type $object
|
* @param string $type type of reminder
|
||||||
* @param type $subject
|
* @param mixed $object Confirm_address or Invitation object
|
||||||
* @param type $day
|
* @param string $subject subjct of the email reminder
|
||||||
|
* @param int $day number of days
|
||||||
*/
|
*/
|
||||||
static function sendReminder($type, $object, $subject, $day)
|
static function sendReminder($type, $object, $subject, $day)
|
||||||
{
|
{
|
||||||
common_debug("QQQQQ sendReminder() enter ... ", __FILE__);
|
// 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}";
|
$title = "{$type}-{$day}";
|
||||||
|
}
|
||||||
common_debug("QQQQ title = {$title}", __FILE__);
|
|
||||||
|
|
||||||
// Record the fact that we sent a reminder
|
// Record the fact that we sent a reminder
|
||||||
if (self::sendReminderEmail($type, $object, $subject, $title)) {
|
if (self::sendReminderEmail($type, $object, $subject, $title)) {
|
||||||
common_debug("Recording reminder record for {$object->address}", __FILE__);
|
|
||||||
try {
|
try {
|
||||||
Email_reminder::recordReminder($type, $object, $day);
|
Email_reminder::recordReminder($type, $object, $day);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
@ -138,17 +141,19 @@ class EmailReminderPlugin extends Plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
common_debug("QQQQQ sendReminder() exit ... ", __FILE__);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Send a real live email reminder
|
||||||
*
|
*
|
||||||
* @param type $object
|
* @todo This would probably be better as two or more sep functions
|
||||||
* @param type $subject
|
*
|
||||||
* @param type $title
|
* @param string $type type of reminder
|
||||||
* @return type
|
* @param mixed $object Confirm_address or Invitation object
|
||||||
|
* @param string $subject subjct of the email reminder
|
||||||
|
* @param string $title title of the email reminder
|
||||||
|
* @return boolean true if the email subsystem doesn't explode
|
||||||
*/
|
*/
|
||||||
static function sendReminderEmail($type, $object, $subject, $title = null) {
|
static function sendReminderEmail($type, $object, $subject, $title = null) {
|
||||||
|
|
||||||
|
@ -177,14 +182,15 @@ class EmailReminderPlugin extends Plugin
|
||||||
|
|
||||||
$template = DocFile::forTitle($title, DocFile::mailPaths());
|
$template = DocFile::forTitle($title, DocFile::mailPaths());
|
||||||
|
|
||||||
$body = $template->toHTML(
|
$blankfillers = array('confirmurl' => $confirmUrl);
|
||||||
array(
|
|
||||||
'confirmurl' => $confirmUrl,
|
if ($type == UserInviteReminderHandler::INVITE_REMINDER) {
|
||||||
'inviter' => $inviter,
|
$blankfillers['inviter'] = $inviter;
|
||||||
'inviterurl' => $inviterUrl
|
$blankfillers['inviterurl'] = $inviterUrl;
|
||||||
// @todo private invitation message
|
// @todo private invitation message?
|
||||||
)
|
}
|
||||||
);
|
|
||||||
|
$body = $template->toHTML($blankfillers);
|
||||||
|
|
||||||
return mail_send($recipients, $headers, $body);
|
return mail_send($recipients, $headers, $body);
|
||||||
}
|
}
|
||||||
|
@ -206,4 +212,5 @@ class EmailReminderPlugin extends Plugin
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,6 @@
|
||||||
|
|
||||||
class Email_reminder extends Managed_DataObject
|
class Email_reminder extends Managed_DataObject
|
||||||
{
|
{
|
||||||
const INVITE_REMINDER = 'invite'; // @todo Move this to the invite reminder handler
|
|
||||||
|
|
||||||
public $__table = 'email_reminder';
|
public $__table = 'email_reminder';
|
||||||
|
|
||||||
public $type; // type of reminder
|
public $type; // type of reminder
|
||||||
|
@ -55,40 +53,45 @@ class Email_reminder extends Managed_DataObject
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Do we need to send a reminder?
|
||||||
*
|
*
|
||||||
* @param type $type
|
* @param string $type type of reminder
|
||||||
* @param type $confirm
|
* @param Object $object an object with a 'code' property
|
||||||
* @param type $day
|
* (Confirm_address or Invitation)
|
||||||
* @return type
|
* @param int $days Number of days after the code was created
|
||||||
|
* @return boolean true if any Email_reminder records were found
|
||||||
*/
|
*/
|
||||||
static function needsReminder($type, $confirm, $days) {
|
static function needsReminder($type, $object, $days = null) {
|
||||||
|
|
||||||
$reminder = new Email_reminder();
|
$reminder = new Email_reminder();
|
||||||
$reminder->type = $type;
|
$reminder->type = $type;
|
||||||
$reminder->code = $confirm->code;
|
$reminder->code = $object->code;
|
||||||
|
if (!empty($days)) {
|
||||||
$reminder->days = $days;
|
$reminder->days = $days;
|
||||||
|
|
||||||
$result = $reminder->find(true);
|
|
||||||
|
|
||||||
if (empty($result)) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
$result = $reminder->find();
|
||||||
|
|
||||||
|
if (!empty($result)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Record a record of sending the reminder
|
||||||
*
|
*
|
||||||
* @param type $type
|
* @param string $type type of reminder
|
||||||
* @param type $confirm
|
* @param Object $object an object with a 'code' property
|
||||||
* @param type $day
|
* (Confirm_address or Invitation)
|
||||||
* @return type
|
* @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, $confirm, $days) {
|
static function recordReminder($type, $object, $days) {
|
||||||
|
|
||||||
$reminder = new Email_reminder();
|
$reminder = new Email_reminder();
|
||||||
$reminder->type = $type;
|
$reminder->type = $type;
|
||||||
$reminder->code = $confirm->code;
|
$reminder->code = $object->code;
|
||||||
$reminder->days = $days;
|
$reminder->days = $days;
|
||||||
$reminder->sent = $reminder->created = common_sql_now();
|
$reminder->sent = $reminder->created = common_sql_now();
|
||||||
$result = $reminder->insert();
|
$result = $reminder->insert();
|
||||||
|
|
|
@ -60,22 +60,24 @@ class SiteConfirmReminderHandler extends QueueHandler
|
||||||
/**
|
/**
|
||||||
* Handle the site
|
* Handle the site
|
||||||
*
|
*
|
||||||
* @param string $reminderType type of reminder to send
|
* @param array $remitem type of reminder to send and any special options
|
||||||
* @return boolean true on success, false on failure
|
* @return boolean true on success, false on failure
|
||||||
*/
|
*/
|
||||||
function handle($reminderType)
|
function handle($remitem)
|
||||||
{
|
{
|
||||||
|
list($type, $opts) = $remitem;
|
||||||
|
|
||||||
$qm = QueueManager::get();
|
$qm = QueueManager::get();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch($reminderType) {
|
switch($type) {
|
||||||
case UserConfirmRegReminderHandler::REGISTER_REMINDER:
|
case UserConfirmRegReminderHandler::REGISTER_REMINDER:
|
||||||
$confirm = new Confirm_address();
|
$confirm = new Confirm_address();
|
||||||
$confirm->address_type = $object;
|
$confirm->address_type = $type;
|
||||||
$confirm->find();
|
$confirm->find();
|
||||||
while ($confirm->fetch()) {
|
while ($confirm->fetch()) {
|
||||||
try {
|
try {
|
||||||
$qm->enqueue($confirm, 'uregrem');
|
$qm->enqueue(array($confirm, $opts), 'uregrem');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
common_log(LOG_WARNING, $e->getMessage());
|
common_log(LOG_WARNING, $e->getMessage());
|
||||||
continue;
|
continue;
|
||||||
|
@ -87,7 +89,7 @@ class SiteConfirmReminderHandler extends QueueHandler
|
||||||
$invitation->find();
|
$invitation->find();
|
||||||
while ($invitation->fetch()) {
|
while ($invitation->fetch()) {
|
||||||
try {
|
try {
|
||||||
$qm->enqueue($invitation, 'uinvrem');
|
$qm->enqueue(array($invitation, $opts), 'uinvrem');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
common_log(LOG_WARNING, $e->getMessage());
|
common_log(LOG_WARNING, $e->getMessage());
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -64,16 +64,34 @@ class UserConfirmRegReminderHandler extends UserReminderHandler {
|
||||||
*
|
*
|
||||||
* @todo abstract this bit further
|
* @todo abstract this bit further
|
||||||
*
|
*
|
||||||
* @param Confirm_address $confirm
|
* @param array $regitem confirmation address and any special options
|
||||||
* @return boolean success value
|
* @return boolean success value
|
||||||
*/
|
*/
|
||||||
function sendNextReminder($confirm)
|
function sendNextReminder($regitem)
|
||||||
{
|
{
|
||||||
|
list($confirm, $opts) = $regitem;
|
||||||
|
|
||||||
$regDate = strtotime($confirm->modified); // Seems like my best bet
|
$regDate = strtotime($confirm->modified); // Seems like my best bet
|
||||||
$now = strtotime('now');
|
$now = strtotime('now');
|
||||||
|
|
||||||
// Days since registration
|
// Days since registration
|
||||||
$days = ($now - $regDate) / 86499; // 60*60*24 = 86499
|
$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("One time reminder - please confirm your registration!");
|
||||||
|
return EmailReminderPlugin::sendReminder(
|
||||||
|
self::REGISTER_REMINDER,
|
||||||
|
$confirm,
|
||||||
|
$subject,
|
||||||
|
-1 // special one-time indicator
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Welcome to one of the ugliest switch statement I've ever written
|
// Welcome to one of the ugliest switch statement I've ever written
|
||||||
|
|
||||||
|
@ -87,7 +105,8 @@ class UserConfirmRegReminderHandler extends UserReminderHandler {
|
||||||
self::REGISTER_REMINDER,
|
self::REGISTER_REMINDER,
|
||||||
$confirm,
|
$confirm,
|
||||||
$subject,
|
$subject,
|
||||||
1);
|
1
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,19 +63,37 @@ class UserInviteReminderHandler extends UserReminderHandler {
|
||||||
*
|
*
|
||||||
* @todo Abstract this stuff further
|
* @todo Abstract this stuff further
|
||||||
*
|
*
|
||||||
* @param Invitation $invitation
|
* @param array $invitem Invitation obj and any special options
|
||||||
* @return boolean success value
|
* @return boolean success value
|
||||||
*/
|
*/
|
||||||
function sendNextReminder($invitation)
|
function sendNextReminder($invitem)
|
||||||
{
|
{
|
||||||
|
list($invitation, $opts) = $invitem;
|
||||||
|
|
||||||
$invDate = strtotime($invitation->created);
|
$invDate = strtotime($invitation->created);
|
||||||
$now = strtotime('now');
|
$now = strtotime('now');
|
||||||
|
|
||||||
// Days since first invitation was sent
|
// Days since first invitation was sent
|
||||||
$days = ($now - $invDate) / 86499; // 60*60*24 = 86499
|
$days = ($now - $invDate) / 86499; // 60*60*24 = 86499
|
||||||
|
// $days = ($now - $regDate) / 120; // Two mins, good for testing
|
||||||
|
|
||||||
$siteName = common_config('site', 'name');
|
$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("One time reminder - you have been invited to join {$siteName}!");
|
||||||
|
return EmailReminderPlugin::sendReminder(
|
||||||
|
self::INVITE_REMINDER,
|
||||||
|
$invitation,
|
||||||
|
$subject,
|
||||||
|
-1 // special one-time indicator
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch($days) {
|
switch($days) {
|
||||||
case ($days > 1 && $days < 2):
|
case ($days > 1 && $days < 2):
|
||||||
if (Email_reminder::needsReminder(self::INVITE_REMINDER, $invitation, 1)) {
|
if (Email_reminder::needsReminder(self::INVITE_REMINDER, $invitation, 1)) {
|
||||||
|
|
26
plugins/EmailReminder/mail-src/invite-onetime
Normal file
26
plugins/EmailReminder/mail-src/invite-onetime
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
Special ONE TIME reminder...
|
||||||
|
|
||||||
|
%%arg.inviter%% has invited you to join them on %%site.name%%.
|
||||||
|
|
||||||
|
%%site.name%% is a micro-blogging service that lets you keep
|
||||||
|
up-to-date with people you know and people who interest you.
|
||||||
|
|
||||||
|
You can also share news about yourself, your thoughts, or your life
|
||||||
|
online with people who know about you.
|
||||||
|
|
||||||
|
It's great for meeting new people who share your interests.
|
||||||
|
|
||||||
|
You can see %%arg.inviter%%'s profile page on %%site.name%% here:
|
||||||
|
|
||||||
|
> [%%arg.inviterurl%%](%%arg.inviterurl%%)
|
||||||
|
|
||||||
|
If you'd like to try the service, click on the link below to accept
|
||||||
|
the invitation.
|
||||||
|
|
||||||
|
> [%%arg.confirmurl%%](%%arg.confirmurl%%)
|
||||||
|
|
||||||
|
If not, you can ignore this message. Thanks for your patience and your time.
|
||||||
|
|
||||||
|
Sincerely,
|
||||||
|
|
||||||
|
%%site.name%%
|
|
@ -1,4 +1,4 @@
|
||||||
Hey, it's been a whole day!
|
Reminder:
|
||||||
|
|
||||||
Someone (probably you) has requested an account on %%site.name%% using this email address.
|
Someone (probably you) has requested an account on %%site.name%% using this email address.
|
||||||
|
|
||||||
|
|
9
plugins/EmailReminder/mail-src/register-onetime
Normal file
9
plugins/EmailReminder/mail-src/register-onetime
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
Hi, this is a special ONE TIME reminder.
|
||||||
|
|
||||||
|
Someone (probably you) has requested an account on %%site.name%% using this email address.
|
||||||
|
|
||||||
|
To confirm the address, click the following URL or copy it into the address bar of your browser.
|
||||||
|
|
||||||
|
> [%%arg.confirmurl%%](%%arg.confirmurl%%)
|
||||||
|
|
||||||
|
If it was not you, you can safely ignore this message.
|
|
@ -20,8 +20,8 @@
|
||||||
|
|
||||||
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
|
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
|
||||||
|
|
||||||
$shortoptions = 't:e:au';
|
$shortoptions = 't:e:auo';
|
||||||
$longoptions = array('type=', 'email=', 'all', 'universe');
|
$longoptions = array('type=', 'email=', 'all', 'universe', 'onetime');
|
||||||
|
|
||||||
$helptext = <<<END_OF_SENDEMAILREMINDER_HELP
|
$helptext = <<<END_OF_SENDEMAILREMINDER_HELP
|
||||||
sendemailreminder.php [options]
|
sendemailreminder.php [options]
|
||||||
|
@ -31,6 +31,7 @@ Send an email summary of the inbox to users
|
||||||
-e --email email address to send reminder to
|
-e --email email address to send reminder to
|
||||||
-a --all send reminder to all addresses
|
-a --all send reminder to all addresses
|
||||||
-u --universe send reminder to all addresses on all sites
|
-u --universe send reminder to all addresses on all sites
|
||||||
|
-o --onetime send one-time reminder to older addresses
|
||||||
|
|
||||||
END_OF_SENDEMAILREMINDER_HELP;
|
END_OF_SENDEMAILREMINDER_HELP;
|
||||||
|
|
||||||
|
@ -55,6 +56,7 @@ $types = array(
|
||||||
);
|
);
|
||||||
|
|
||||||
$type = null;
|
$type = null;
|
||||||
|
$opts = array(); // special options like "onetime"
|
||||||
|
|
||||||
if (have_option('t', 'type')) {
|
if (have_option('t', 'type')) {
|
||||||
$type = trim(get_option_value('t', 'type'));
|
$type = trim(get_option_value('t', 'type'));
|
||||||
|
@ -67,6 +69,11 @@ if (have_option('t', 'type')) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (have_option('o', 'onetime')) {
|
||||||
|
$opts['onetime'] = true;
|
||||||
|
if (!$quiet) { print "Special one-time reminder mode.\n"; }
|
||||||
|
}
|
||||||
|
|
||||||
$reminders = array();
|
$reminders = array();
|
||||||
|
|
||||||
switch($type) {
|
switch($type) {
|
||||||
|
@ -91,7 +98,7 @@ if (have_option('u', 'universe')) {
|
||||||
$qm = QueueManager::get();
|
$qm = QueueManager::get();
|
||||||
foreach ($reminders as $reminder) {
|
foreach ($reminders as $reminder) {
|
||||||
extract($reminder);
|
extract($reminder);
|
||||||
$qm->enqueue($type, 'siterem');
|
$qm->enqueue(array($type, $opts), 'siterem');
|
||||||
if (!$quiet) { print "Sent pending {$type} reminders to all unconfirmed addresses in the known universe.\n"; }
|
if (!$quiet) { print "Sent pending {$type} reminders to all unconfirmed addresses in the known universe.\n"; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,13 +118,13 @@ if (have_option('u', 'universe')) {
|
||||||
if (empty($result)) {
|
if (empty($result)) {
|
||||||
throw new Exception("No confirmation code found for {$address}.");
|
throw new Exception("No confirmation code found for {$address}.");
|
||||||
}
|
}
|
||||||
$qm->enqueue($confirm, $utransport);
|
$qm->enqueue(array($confirm, $opts), $utransport);
|
||||||
if (!$quiet) { print "Sent all pending {$type} reminder to {$address}.\n"; }
|
if (!$quiet) { print "Sent all pending {$type} reminder to {$address}.\n"; }
|
||||||
}
|
}
|
||||||
} else if (have_option('a', 'all')) {
|
} else if (have_option('a', 'all')) {
|
||||||
foreach ($reminders as $reminder) {
|
foreach ($reminders as $reminder) {
|
||||||
extract($reminder);
|
extract($reminder);
|
||||||
$qm->enqueue($type, 'siterem');
|
$qm->enqueue(array($type, $opts), 'siterem');
|
||||||
if (!$quiet) { print "Sent pending {$type} reminders to all unconfirmed addresses on the site.\n"; }
|
if (!$quiet) { print "Sent pending {$type} reminders to all unconfirmed addresses on the site.\n"; }
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user