? patch Index: notify.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/notify/notify.install,v retrieving revision 1.5 diff -u -p -r1.5 notify.install --- notify.install 3 Feb 2009 01:52:57 -0000 1.5 +++ notify.install 2 Jul 2010 07:08:36 -0000 @@ -1,5 +1,5 @@ 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'), @@ -18,6 +19,18 @@ function notify_schema() { return $schema; } +function notify_update_1() { + $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'); @@ -26,4 +39,4 @@ function notify_install() { function notify_uninstall() { // Drop my tables. drupal_uninstall_schema('notify'); -} \ No newline at end of file +} Index: notify.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/notify/notify.module,v retrieving revision 2.78 diff -u -p -r2.78 notify.module --- notify.module 23 Jun 2009 23:38:12 -0000 2.78 +++ notify.module 2 Jul 2010 07:08:36 -0000 @@ -1,5 +1,5 @@ variable_get('notify_attempts', array(5)), '#options' => array(t('Disabled'), 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20), ); - - $form[notify_settings]['notify_reg_default'] = array( - '#type' => 'checkbox', - '#title' => 'Notification checkbox default on new user registration form', - '#return_value' => 1, - '#default_value' => variable_get('notify_reg_default',1), - ); $set = 'ntype'; $form[$set] = array( @@ -128,7 +121,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; @@ -141,8 +134,6 @@ function notify_user($type, &$edit, &$us * Returns form fields to be added to User Regsitration form */ function _notify_user_reg_fields() { - if (!user_access('access notify')) return; - // Get the variable for how often the notifications are sent out $period = variable_get("notify_send", 86400); @@ -158,7 +149,7 @@ function _notify_user_reg_fields() { '#type' => 'checkbox', '#title' => t('Receive email notifications of news posted to this site. Notifications are sent every ' . format_interval($period).'.'), '#return_value' => 1, - '#default_value' => variable_get('notify_reg_default',1), + '#default_value' => 1, '#description' => t('By accepting to receive daily email news notifications, you will be kept informed of news associated with ' . variable_get('site_name', 'Drupal') . '.') ); @@ -194,8 +185,8 @@ function notify_menu() { 'title' => 'Notification settings', 'page callback' => 'drupal_get_form', 'page arguments' => array('notify_user_settings_form', 1), - 'access callback' => 'notify_user_access', - 'access arguments' => array(1), + 'access callback' => 'user_access', + 'access arguments' => array('access notify'), 'type' => MENU_LOCAL_TASK ); $items['admin/user/user/notify'] = array( @@ -209,21 +200,7 @@ function notify_menu() { return $items; } - -/** - * Checks access to notifications settings tab - */ -function notify_user_access($account = NULL) -{ - return $account->uid && - ( - // Always let users view their own profile. - ($GLOBALS['user']->uid == $account->uid && user_access('access notify')) || - // Administrators can view all accounts. - user_access('administer notify') - ); -} - + /** * Register the themeing the form data into a table at * admin/user/user/notify @@ -243,7 +220,7 @@ function notify_user_access($account = N */ function notify_user_settings_form(&$form_state, $arg) { global $user; - if ($user->uid != $arg->uid && !user_access('administer notify') ) { + if ($user->uid != $arg->uid && $user->uid != 1) { drupal_access_denied(); return; } @@ -254,7 +231,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) { @@ -289,6 +266,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; @@ -320,6 +302,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( @@ -368,7 +351,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) { @@ -439,9 +422,26 @@ function _notify_send() { } // 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); @@ -453,12 +453,10 @@ function _notify_send() { } // Fetch new comments. + $cresult = db_query(db_rewrite_sql('SELECT c.nid, c.cid, c.subject, c.name FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid WHERE c.status = %d AND c.timestamp > %d AND c.timestamp <= %d '. $reqntype . ' ORDER BY c.nid, c.timestamp', 'c'), COMMENT_PUBLISHED, $period, time()); $comments = array(); - if (module_exists('comment')) { - $cresult = db_query(db_rewrite_sql('SELECT c.nid, c.cid, c.subject, c.name FROM {comments} c INNER JOIN {node} n ON c.nid = n.nid WHERE c.status = %d AND c.timestamp > %d AND c.timestamp <= %d '. $reqntype . ' ORDER BY c.nid, c.timestamp', 'c'), COMMENT_PUBLISHED, $period, time()); - while ($comment = db_fetch_object($cresult)) { - $comments[$comment->nid][] = $comment; - } + while ($comment = db_fetch_object($cresult)) { + $comments[$comment->nid][] = $comment; } $node_body = ''; @@ -498,7 +496,7 @@ function _notify_send() { // Prepend node e-mail header as long as user could access at least one node. if ($node_count > 0) { $node_body = $separator ."\n" - . t('Recent content - !count', array('!count' => format_plural(count($nodes), '1 new post', '@count new posts'))) ."\n" + . t('Recent content - !count', array('!count' => format_plural(count($nodes), '1 new post', count($nodes) .' new posts'))) ."\n" . $separator ."\n\n". $node_body; } } @@ -521,7 +519,7 @@ function _notify_send() { if ($comment_body) { $comment_body .= $mini_separator ."\n\n"; } - $comment_body .= t('!count attached to !type posted by !author: !title', array('!count' => format_plural(count($comment), '1 new comment', '@count new comments'), '!title' => $nodes[$nid]->title, '!type' => node_get_types('name', $nodes[$nid]), '!author' => $nodes[$nid]->name ? $nodes[$nid]->name : variable_get('anonymous', 'Anonymous'))) ."\n"; + $comment_body .= t('!count attached to !type posted by !author: !title', array('!count' => format_plural(count($comment), '1 new comment', count($comment).' new comments'), '!title' => $nodes[$nid]->title, '!type' => node_get_types('name', $nodes[$nid]), '!author' => $nodes[$nid]->name ? $nodes[$nid]->name : variable_get('anonymous', 'Anonymous'))) ."\n"; $comment_count = 0; foreach ($comment as $c) { @@ -533,7 +531,7 @@ function _notify_send() { if ($total_comment_count > 0) { $comment_body = $separator ."\n" - . t('Recent comments - !count', array('!count' => format_plural($total_comment_count, '1 new comment', '@count new comments'))) ."\n" + . t('Recent comments - !count', array('!count' => format_plural($total_comment_count, '1 new comment', $total_comment_count.' new comments'))) ."\n" . $separator ."\n\n". $comment_body; } } @@ -554,6 +552,7 @@ function _notify_send() { $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); } } // Restore user.