diff --git a/notify.install b/notify.install
index 69b57ed..e32c0de 100755
--- a/notify.install
+++ b/notify.install
@@ -14,13 +14,26 @@ function notify_schema() {
'comment' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0, 'disp-width' => '2'),
'attempts' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0, 'disp-width' => '4'),
'teasers' => array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0, 'disp-width' => '4'),
- ),
+ 'send_last' => array('type' => 'int', 'not null' => TRUE, 'default' => 0),
+ ),
'primary key' => array('uid'),
);
return $schema;
}
+function notify_update_6001() {
+ $ret = array();
+ switch ($GLOBALS['db_type']) {
+ case 'mysql':
+ case 'mysqli':
+ $ret[] = update_sql("ALTER TABLE {notify} ADD COLUMN send_last int NOT NULL DEFAULT 0;");
+ break;
+ }
+
+ return $ret;
+}
+
function notify_install() {
// Create my tables.
drupal_install_schema('notify');
diff --git a/notify.module b/notify.module
index ad7a678..d9d427b 100644
--- a/notify.module
+++ b/notify.module
@@ -146,7 +146,7 @@ function notify_user($type, &$edit, &$user, $category = NULL) {
case 'insert':
if (isset($edit['notify_decision']) && $edit['notify_decision'] == 1) {
- db_query('INSERT INTO {notify} (uid, status, node, teasers, comment) VALUES (%d, %d, %d, %d, %d)', $user->uid, 1, 1, 0, 0);
+ db_query('INSERT INTO {notify} (uid, status, node, teasers, comment, send_last) VALUES (%d, %d, %d, %d, %d, %d)', $user->uid, 1, 1, 0, 0, 0);
$edit['notify_decision'] = NULL;
}
break;
@@ -273,7 +273,7 @@ function notify_user_settings_form(&$form_state, $arg) {
return;
}
- $result = db_query('SELECT u.uid, u.name, u.mail, n.status, n.node, n.teasers, n.comment FROM {users} u LEFT JOIN {notify} n ON u.uid = n.uid WHERE u.uid = %d AND u.status = 1', $account->uid);
+ $result = db_query('SELECT u.uid, u.name, u.mail, n.status, n.node, n.teasers, n.comment, n.send_last FROM {users} u LEFT JOIN {notify} n ON u.uid = n.uid WHERE u.uid = %d AND u.status = 1', $account->uid);
$notify = db_fetch_object($result);
$form = array();
if (!$notify->mail) {
@@ -307,6 +307,11 @@ function notify_user_settings_form(&$form_state, $arg) {
'#options' => array(t('Disabled'), t('Enabled')),
'#description' => t('Include new comments in the notification mail.'),
);
+ $form['notify_send_last'] = array('#type' => 'markup',
+ '#title' => t('Notify last send'),
+ '#description' => t('The date of the last notification for this user.'),
+ '#value' => '
' . t('Last Send: !date', array('!date' => $notify->send_last > 0 ? date('n/j/y g:i a', $notify->send_last) : "never")) . '
',
+ );
$form['uid'] = array('#type' => 'value', '#value' => $account->uid);
$form['submit'] = array('#type' => 'submit', '#value' => t('Save settings'));
@@ -339,6 +344,7 @@ function notify_admin_users() {
$form['users'][$notify->uid]['teasers'] = array('#type' => 'select', '#default_value' => $notify->teasers, '#options' => array(t('Title only'), t('Title + Teaser'), t('Title + Body')));
$form['users'][$notify->uid]['comment'] = array('#type' => 'checkbox', '#default_value' => $notify->comment);
$form['users'][$notify->uid]['attempts'] = array('#type' => 'textfield', '#size' => 2, '#default_value' => $notify->attempts ? intval($notify->attempts) : 0);
+ $form['users'][$notify->uid]['send_last'] = array('#type' => 'markup', '#value' => $notify->send_last > 0 ? date('n/j/y g:i a', $notify->send_last) : "never");
}
$form['flush'] = array(
@@ -388,7 +394,7 @@ function notify_admin_users_submit($form, &$form_state) {
*/
function theme_notify_admin_users($form) {
$output = drupal_render($form['info']);
- $header = array(t('Username'), t('E-mail address'), t('Content'), t('Teasers'), t('Comment'), t('Failed attempts'));
+ $header = array(t('Username'), t('E-mail address'), t('Content'), t('Teasers'), t('Comment'), t('Failed attempts'), t('Last Send'));
$rows = array();
foreach (element_children($form['users']) as $uid) {
@@ -486,9 +492,26 @@ function _notify_send($send_start = NULL) {
if (count($nodes) || count($comments)) {
// Fetch users with notify enabled
- $uresult = db_query('SELECT u.uid, u.name, u.mail, u.language, n.status, n.node, n.teasers, n.comment FROM {notify} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND u.status = 1 AND n.attempts <= %d', variable_get('notify_attempts', 5));
+ $uresult = db_query('SELECT u.uid, u.name, u.mail, u.language, n.status, n.node, n.teasers, n.comment, n.send_last FROM {notify} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND u.status = 1 AND n.attempts <= %d', variable_get('notify_attempts', 5));
while ($user = db_fetch_object($uresult)) {
+ // check to see if the send_last for this user is > the global
+ // notify send_last setting. if so, this indicates cron was aborted
+ // for taking too long and that this user should be considered done.
+ // technically, we should look for new updates since then, but since
+ // cron isn't finishing in time, it's better to let it continue to the
+ // rest of the users.
+ $notify_send_last = variable_get('notify_send_last', 0);
+ if ( !empty($user->send_last) && $notify_send_last <= $user->send_last ) {
+ // enable this if you want lots of debug messages confirming it's
+ // doing the right thing
+ /*
+ watchdog('notify', 'Skipping user %name (%mail), was already done at !send_last and global notify is earlier (!notify_send_last)',
+ array('%name'=> $user->name, '%mail' => $user->mail, '!send_last' => date('n/j/y g:i a', $user->send_last), '!notify_send_last' => date('n/j/y g:i a', $notify_send_last)), WATCHDOG_INFO);
+ */
+ continue;
+ }
+
// Switch current user to this account to use node_access functions, etc.
_notify_switch_user($user->uid);
@@ -596,6 +619,7 @@ function _notify_send($send_start = NULL) {
$num_sent++;
watchdog('notify', 'User %name (%mail) notified successfully.', array('%name' => $user->name, '%mail' => $user->mail), WATCHDOG_INFO);
}
+ db_query('UPDATE {notify} SET send_last = UNIX_TIMESTAMP(NOW()) WHERE uid = %d', $user->uid);
}
}
}
@@ -647,4 +671,4 @@ function _notify_switch_user($uid = NULL) {
else {
$orig_user[] = $user;
}
-}
+}
\ No newline at end of file