--- notify.module Sun Aug 01 15:05:40 2010 +++ notify.module.new Sun Aug 01 20:36:26 2010 @@ -155,7 +155,7 @@ function notify_user($type, &$edit, &$us 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; @@ -282,7 +282,7 @@ function notify_user_settings_form(&$for 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) { @@ -317,6 +317,11 @@ function notify_user_settings_form(&$for '#description' => t('Include new comments in the notification mail.'), ); $form['uid'] = array('#type' => 'value', '#value' => $account->uid); + $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['submit'] = array('#type' => 'submit', '#value' => t('Save settings')); return $form; @@ -348,6 +353,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( @@ -397,7 +403,7 @@ function notify_admin_users_submit($form */ 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) { @@ -496,9 +502,26 @@ function _notify_send($send_start) { 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); @@ -603,6 +626,7 @@ function _notify_send($send_start) { $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); } } }