Multiple emails being sent every cron run ignoring reminder settings
Cromicon - July 1, 2006 - 12:18
| Project: | Remindme |
| Version: | 4.6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Description
Ello!
In 4.6, the remind me settings you can choose on a particular event currently give you the options to get a reminder 15m, 1 day, 1 week etc before the event.
If you choose for example, 1 week before an event and your event is obviously 1 week away, everytime cron runs, no matter what options you choose, you get an email.
This can be tested by selecting 5 times on the reminder and every cron you will get 5 duplicate emails.
This is the bit of code that needs looking at I think but I can't see what could be wrong, can anyone help?
/**
* Implementation of hook_cron()
*/
function remindme_cron() {
if (time() - variable_get('remindme_send_last', 0) > variable_get('remindme_send', 86400)) {
$sql = db_rewrite_sql('SELECT n.nid,(r.nid), r.timestamp, u.uid AS user, u.name, u.mail, n.title, n.body, e.event_start FROM {node} n INNER JOIN {remindme_node} r ON r.nid = n.nid INNER JOIN {users} u ON r.uid = u.uid INNER JOIN {event} e ON e.nid = r.nid WHERE n.status = 1 AND r.timestamp > 0 AND '. variable_get('remindme_send_last', time()) .' + r.timestamp > e.event_start');
$result = db_query($sql);
while ($node = db_fetch_object($result)) {
$status = remindme_mail($node);
if ($status) {
db_query('DELETE FROM {remindme_node} WHERE timestamp = %d AND nid = %d AND uid = %d', $node->timestamp, $node->nid, $node->user);
watchdog('remindme', "reminded user $node->user about event $node->title");
}
}
variable_set('remindme_send_last', time());
}
} 