# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: contributions/modules/inactive_user/inactive_user.module
--- contributions/modules/inactive_user/inactive_user.module Base (1.11)
+++ contributions/modules/inactive_user/inactive_user.module Locally Modified (Based On 1.11)
@@ -98,7 +98,7 @@
     '#default_value' => variable_get('inactive_user_notify_text', _inactive_user_mail_text('notify_text')),
     '#cols' => 70,
     '#rows' => 10,
-    '#description' => t('Customize the body of the notification e-mail sent to the user.') .' '. t('Available variables are:') . $mail_variables,
+    '#description' => t('Customize the body of the notification e-mail sent to the user.') . ' ' . t('Available variables are:') . $mail_variables,
     '#required' => TRUE,
   );
 
@@ -128,7 +128,7 @@
     '#default_value' => variable_get('inactive_user_block_notify_text', _inactive_user_mail_text('block_notify_text')),
     '#cols' => 70,
     '#rows' => 10,
-    '#description' => t('Customize the body of the notification e-mail sent to the user when their account has been blocked.') .' '. t('Available variables are:') . $mail_variables,
+    '#description' => t('Customize the body of the notification e-mail sent to the user when their account has been blocked.') . ' ' . t('Available variables are:') . $mail_variables,
     '#required' => TRUE,
   );
   $form['block_inactive_user']['inactive_user_notify_block_admin'] = array(
@@ -150,7 +150,7 @@
     '#default_value' => variable_get('inactive_user_block_warn_text', _inactive_user_mail_text('block_warn_text')),
     '#cols' => 70,
     '#rows' => 10,
-    '#description' => t('Customize the body of the notification e-mail sent to the user when their account is about to be blocked.') .' '. t('Available variables are:') . $mail_variables,
+    '#description' => t('Customize the body of the notification e-mail sent to the user when their account is about to be blocked.') . ' ' . t('Available variables are:') . $mail_variables,
     '#required' => TRUE,
   );
 
@@ -186,7 +186,7 @@
     '#default_value' => variable_get('inactive_user_delete_notify_text', _inactive_user_mail_text('delete_notify_text')),
     '#cols' => 70,
     '#rows' => 10,
-    '#description' => t('Customize the body of the notification e-mail sent to the user when their account has been deleted.') .' '. t('Available variables are:') . $mail_variables,
+    '#description' => t('Customize the body of the notification e-mail sent to the user when their account has been deleted.') . ' ' . t('Available variables are:') . $mail_variables,
     '#required' => TRUE,
   );
   $form['delete_inactive_user']['inactive_user_notify_delete_admin'] = array(
@@ -208,9 +208,26 @@
     '#default_value' => variable_get('inactive_user_delete_warn_text', _inactive_user_mail_text('delete_warn_text')),
     '#cols' => 70,
     '#rows' => 10,
-    '#description' => t('Customize the body of the notification e-mail sent to the user when their account is about to be deleted.') .' '. t('Available variables are:') . $mail_variables,
+    '#description' => t('Customize the body of the notification e-mail sent to the user when their account is about to be deleted.') . ' ' . t('Available variables are:') . $mail_variables,
     '#required' => TRUE,
   );
+
+  // cron settings
+  $form['inactive_user_cron'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Cron settings'),
+    '#collapsible' => TRUE,
+    '#collapsed' => TRUE,
+  );
+  $form['inactive_user_cron']['inactive_user_cron_limit'] = array(
+    '#type' => 'textfield',
+    '#title' => t('No. of users to execute'),
+    '#default_value' => variable_get('inactive_user_cron_limit', 10),
+    '#description' => t('Number of user accounts to execute per cron run. Please consider about this vaue with how often cron run per day to avoid database load.'),
+    '#maxlength' => 256,
+    '#required' => TRUE,
+  );
+
   return system_settings_form($form);
 }
 
@@ -222,10 +239,9 @@
       $count++;
     }
   }
-  if ($count ==  1) {
+  if ($count == 1) {
     form_set_error('inactive_user_admin_email', t('%mail is not a valid e-mail address', array('%mail' => $invalid[0])));
-  }
-  elseif ($count > 1) {
+  } elseif ($count > 1) {
     form_set_error('inactive_user_admin_email', t('The following e-mail addresses are invalid: %mail', array('%mail' => implode(', ', $invalid))));
   }
 }
@@ -234,9 +250,10 @@
  * Implementation of hook_cron().
  */
 function inactive_user_cron() {
-  if ((time() - variable_get('inactive_user_timestamp', '0')) >= 86100) { // Only check once every almost-day, so we slide around the clock and don't overload the server.
+  $user_limit = variable_get('inactive_user_cron_limit', 10);
+//  if ((time() - variable_get('inactive_user_timestamp', '0')) >= 86100) { // Only check once every almost-day, so we slide around the clock and don't overload the server.
     variable_set('inactive_user_timestamp', time());
-    $user_list = '';
+  unset($user_list);
 
     // reset notifications if recent user activity
     $users = db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid <> 1'));
@@ -246,14 +263,16 @@
         if ($u->access > time() - 604800) {
           // user activity in last week, remove from inactivity table
           db_query('DELETE FROM {inactive_users} WHERE uid = %d', $uid);
-          watchdog('user', 'recent user activity: %user removed from inactivity list', array('%user' => $u->name), WATCHDOG_NOTICE, l(t('edit user'), "user/$uid/edit", array('query' => array('destination' => 'admin/user/user'))));
+        watchdog('user', 'recent user activity: %user removed from inactivity list', array('%user' => $u->name), WATCHDOG_NOTICE, l(t('edit user'), "admin/user/edit/$uid"));
         }
       }
     }
 
     // notify administrator of inactive user accounts
     if ($notify_time = variable_get('inactive_user_notify_admin', 0)) {
-      $result = db_query('SELECT uid, name, mail, access, created FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND uid <> 1', time(), $notify_time, time(), $notify_time);
+    $start = variable_get('inactive_user_notify_admin_limit', 0);
+    $result = db_query('SELECT uid, name, mail, access, created FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND uid <> 1 LIMIT %d, %d', time(), $notify_time, time(), $notify_time, $start, $user_limit);
+    variable_set('inactive_user_notify_admin_limit', $user_limit + $start);
       while ($user = db_fetch_object($result)) {
         if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND notified_admin = 1', $user->uid)) && ($user->created < (time() - $notify_time))) {
           db_query('UPDATE {inactive_users} SET notified_admin = 1 WHERE uid = %d', $user->uid);
@@ -261,10 +280,10 @@
             // must create a new row
             @db_query('INSERT INTO {inactive_users} (uid, notified_admin) VALUES (%d, 1)', $user->uid);
           }
-          $user_list .= "$user->name ($user->mail) last active on ". format_date($user->access, 'large') .".\n";
+        $user_list .= "$user->name ($user->mail) last active on " . format_date($user->access, 'large') . ".\n";
         }
       }
-      if (isset($user_list)) {
+    if ($user_list) {
         _inactive_user_mail(t('[@sitename] Inactive users', array('@sitename' => variable_get('site_name', 'drupal'))), _inactive_user_mail_text('notify_admin_text'), $notify_time, NULL, $user_list);
         unset($user_list);
       }
@@ -272,7 +291,9 @@
 
     // notify users that their account has been inactive
     if ($notify_time = variable_get('inactive_user_notify', 0)) {
-      $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND status <> 0 AND uid <> 1', time(), $notify_time, time(), $notify_time);
+    $start = variable_get('inactive_user_notify_limit', 0);
+    $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND status <> 0 AND uid <> 1 LIMIT %d, %d', time(), $notify_time, time(), $notify_time, $start, $user_limit);
+    variable_set('inactive_user_notify_limit', $user_limit + $start);
       while ($user = db_fetch_object($result)) {
         if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE notified_user = 1 AND uid = %d', $user->uid)) && ($user->created < (time() - $notify_time))) {
           db_query('UPDATE {inactive_users} SET notified_user = 1 WHERE uid = %d', $user->uid);
@@ -280,7 +301,7 @@
             @db_query('INSERT INTO {inactive_users} (uid, notified_user) VALUES (%d, 1)', $user->uid);
           }
           _inactive_user_mail(t('[@sitename] Account inactivity', array('@sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_notify_text', _inactive_user_mail_text('notify_text')), $notify_time, $user, NULL);
-          watchdog('user', 'user %user notified of inactivity', array('%user' => $user->name), WATCHDOG_INFO, l(t('edit user'), "user/$user->uid/edit", array('query' => array('destination' => 'admin/user/user'))));
+        watchdog('user', 'user %user notified of inactivity', array('%user' => $user->name), WATCHDOG_INFO, l(t('edit user'), "admin/user/edit/$uid"));
         }
       }
     }
@@ -288,22 +309,26 @@
     // warn users when they are about to be blocked
     if (($warn_time = variable_get('inactive_user_auto_block_warn', 0)) &&
         ($block_time = variable_get('inactive_user_auto_block', 0))) {
-      $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND status <> 0 AND uid <> 1', time(), $warn_time, time(), $warn_time);
+    $start = variable_get('inactive_user_auto_block_limit', 0);
+    $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d - %d)) OR (login = 0 AND created < (%d - %d - %d))) AND status <> 0 AND uid <> 1 LIMIT %d, %d', time(), $warn_time, $block_time, time(), $warn_time, $block_time, $start, $user_limit);
+    variable_set('inactive_user_auto_block_limit', $user_limit + $start);
       while ($user = db_fetch_object($result)) {
-        if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND warned_user_block_timestamp > 0', $user->uid)) && ($user->created < (time() - $warn_time))) {
+      if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND warned_user_block_timestamp > 0', $user->uid)) && ($user->created < (time() - $warn_time - $block_time))) {
           db_query('UPDATE {inactive_users} SET warned_user_block_timestamp = %d WHERE uid = %d', time() + $warn_time, $user->uid);
           if (!db_affected_rows()) {
             @db_query('INSERT INTO {inactive_users} (uid, warned_user_block_timestamp) VALUES (%d, %d)', $user->uid, time() + $warn_time);
           }
           _inactive_user_mail(t('[@sitename] Account inactivity', array('@sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_block_warn_text', _inactive_user_mail_text('block_warn_text')), $warn_time, $user, NULL);
-          watchdog('user', 'user %user warned will be blocked due to inactivity', array('%user' => $user->name), WATCHDOG_NOTICE, l(t('edit user'), "user/$user->uid/edit", array('query' => array('destination' => 'admin/user/user'))));
+        watchdog('user', 'user %user warned will be blocked due to inactivity', array('%user' => $user->name), WATCHDOG_NOTICE, l(t('edit user'), "admin/user/edit/$uid"));
         }
       }
     }
 
     // automatically block users
     if ($block_time = variable_get('inactive_user_auto_block', 0)) {
-      $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND status <> 0 AND uid <> 1', time(), $block_time, time(), $block_time);
+    $start = variable_get('inactive_user_auto_block_user_limit', 0);
+    $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND status <> 0 AND uid <> 1 LIMIT %d, %d', time(), $block_time, time(), $block_time, $start, $user_limit);
+    variable_set('inactive_user_auto_block_user_limit', $user_limit + $start);
       while ($user = db_fetch_object($result)) {
         // don't block user yet if we sent a warning and it hasn't expired
         if ($user->uid && db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND warned_user_block_timestamp < %d', $user->uid, time())) && ($user->created < (time() - $block_time))) {
@@ -317,7 +342,7 @@
                 @db_query('INSERT INTO {inactive_users} (uid, notified_user_block) VALUES (%d, 1)', $user->uid);
               }
               _inactive_user_mail(t('[@sitename] Account blocked due to inactivity', array('@sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_block_notify_text', _inactive_user_mail_text('block_notify_text')), $block_time, $user, NULL);
-              watchdog('user', 'user %user blocked due to inactivity', array('%user' => $user->name), WATCHDOG_NOTICE, l(t('edit user'), "user/$user->uid/edit", array('query' => array('destination' => 'admin/user/user'))));
+            watchdog('user', 'user %user blocked due to inactivity', array('%user' => $user->name), WATCHDOG_NOTICE, l(t('edit user'), "admin/user/edit/$uid"));
             }
           }
 
@@ -328,7 +353,7 @@
               if (!db_affected_rows()) {
                 @db_query('INSERT INTO {inactive_users} (uid, notified_admin_block) VALUES(%d, 1)', $user->uid);
               }
-              $user_list .= "$user->name ($user->mail) last active on ". format_date($user->access, 'large') .".\n";
+            $user_list .= "$user->name ($user->mail) last active on " . format_date($user->access, 'large') . ".\n";
             }
           }
         }
@@ -342,13 +367,14 @@
     // warn users when they are about to be deleted
     if (($warn_time = variable_get('inactive_user_auto_delete_warn', 0)) &&
         ($delete_time = variable_get('inactive_user_auto_delete', 0))) {
-      $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND uid <> 1', time(), $warn_time, time(), $warn_time);
+    $start = variable_get('inactive_user_auto_delete_limit', 0);
+    $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d - %d)) OR (login = 0 AND created < (%d - %d - %d))) AND uid <> 1 LIMIT %d, %d', time(), $warn_time, $delete_time, time(), $warn_time, $delete_time, $start, $user_limit);
+    variable_set('inactive_user_auto_delete_limit', $user_limit + $start);
       while ($user = db_fetch_object($result)) {
-        if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND warned_user_delete_timestamp > 0', $user->uid)) && ($user->created < (time() - $warn_time))) {
+      if ($user->uid && !db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND warned_user_delete_timestamp > 0', $user->uid)) && ($user->created < (time() - $warn_time - $delete_time))) {
           if (variable_get('inactive_user_preserve_content', 1) && _inactive_user_with_content($user->uid)) {
             $protected = 1;
-          }
-          else {
+        } else {
             $protected = 0;
           }
           db_query('UPDATE {inactive_users} SET warned_user_delete_timestamp = %d AND protected = %d WHERE uid = %d', time() + $warn_time, $protected, $user->uid);
@@ -357,7 +383,7 @@
           }
           if (!$protected) {
             _inactive_user_mail(t('[@sitename] Account inactivity', array('@sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_delete_warn_text', _inactive_user_mail_text('delete_warn_text')), $warn_time, $user, NULL);
-            watchdog('user', 'user %user warned will be deleted due to inactivity', array('%user' => $user->mail), WATCHDOG_NOTICE, l(t('edit user'), "user/$user->uid/edit", array('query' => array('destination' => 'admin/user/user'))));
+          watchdog('user', 'user %user warned will be deleted due to inactivity', array('%user' => $user->mail), WATCHDOG_NOTICE, l(t('edit user'), "admin/user/edit/$uid"));
           }
         }
       }
@@ -365,7 +391,9 @@
 
     // automatically delete users
     if ($delete_time = variable_get('inactive_user_auto_delete', 0)) {
-      $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND uid <> 1', time(), $delete_time, time(), $delete_time);
+    $start = variable_get('inactive_user_auto_delete_user_limit', 0);
+    $result = db_query('SELECT * FROM {users} WHERE ((access <> 0 AND login <> 0 AND access < (%d - %d)) OR (login = 0 AND created < (%d - %d))) AND uid <> 1 LIMIT %d, %d', time(), $delete_time, time(), $delete_time, $start, $user_limit);
+    variable_get('inactive_user_auto_delete_user_limit', $user_limit + $start);
       while ($user = db_fetch_object($result)) {
         if ($user->uid && ((variable_get('inactive_user_auto_delete_warn', 0) && db_fetch_object(db_query('SELECT uid FROM {inactive_users} WHERE uid = %d AND warned_user_delete_timestamp < %d AND protected <> 1', $user->uid, time()))) || (!variable_get('inactive_user_auto_delete_warn', 0))) && ($user->created < (time() - $delete_time))) {
           if (variable_get('inactive_user_preserve_content', 1) && _inactive_user_with_content($user->uid)) {
@@ -374,8 +402,7 @@
             if (!db_affected_rows()) {
               @db_query('INSERT INTO {inactive_users} (uid, protected) VALUES (%d, 1)', $user->uid, $protected);
             }
-          }
-          else {
+        } else {
             // delete the user
             // not using user_delete() so we can send custom emails and watchdog
             $array = (array) $user;
@@ -388,7 +415,7 @@
               _inactive_user_mail(t('[@sitename] Account removed', array('@sitename' => variable_get('site_name', 'drupal'))), variable_get('inactive_user_delete_notify_text', _inactive_user_mail_text('delete_notify_text')), $delete_time, $user, NULL);
             }
             if (variable_get('inactive_user_notify_delete_admin', 0)) {
-              $user_list .= "$user->name ($user->mail) last active on ". format_date($user->access, 'large') .".\n";
+            $user_list .= "$user->name ($user->mail) last active on " . format_date($user->access, 'large') . ".\n";
             }
             watchdog('user', 'user %user deleted due to inactivity', array('%user' => $user->name));
           }
@@ -399,19 +426,19 @@
         unset($user_list);
       }
     }
+//  }
   }
-}
 
 /**
- * Slighty modified from format_interval() in common.inc to include months.
+ * Slighty modified from format_interval() in common.inc to include months
  */
 function _format_interval($timestamp, $granularity = 2) {
-  $units = array('1 year|@count years' => 31536000, '1 month|@count months' => 2592000, '1 week|@count weeks' => 604800, '1 day|@count days' => 86400, '1 hour|@count hours' => 3600, '1 min|@count min' => 60, '1 sec|@count sec' => 1);
   $output = '';
+  $units = array('1 year|@count years' => 31536000, '1 month|@count months' => 2592000, '1 week|@count weeks' => 604800, '1 day|@count days' => 86400, '1 hour|@count hours' => 3600, '1 min|@count min' => 60, '1 sec|@count sec' => 1);
   foreach ($units as $key => $value) {
     $key = explode('|', $key);
     if ($timestamp >= $value) {
-      $output .= ($output ? ' ' : '') . format_plural(floor($timestamp / $value), $key[0], $key[1]);
+      $output .= ( $output ? ' ' : '') . format_plural(floor($timestamp / $value), $key[0], $key[1]);
       $timestamp %= $value;
       $granularity--;
     }
@@ -437,7 +464,7 @@
 }
 
 /**
- * Wrapper for user_mail.
+ * Wrapper for user_mail
  */
 function _inactive_user_mail($subject, $message, $period, $user = NULL, $user_list = NULL) {
   global $base_url;
@@ -449,8 +476,7 @@
       '%siteurl' => $base_url,
       "%userlist" => $user_list
     );
-  }
-  elseif (isset($user->uid)) {
+  } elseif (isset($user->uid)) {
     $to = $user->mail;
     $variables = array(
       '%username' => $user->name,
@@ -477,14 +503,14 @@
         'headers' => $headers
       );
       $user = user_load(array('mail' => $recipient));
-      $language = isset($user->uid) ? user_preferred_language($user) :  language_default();
+      $language = isset($user->uid) ? user_preferred_language($user) : language_default();
       drupal_mail('inactive_user', 'inactive_user_notice', $recipient, $language, $params, $from, TRUE);
     }
   }
 }
 
 /**
- * Some default e-mail notification strings.
+ * Some default e-mail notification strings
  */
 function _inactive_user_mail_text($message) {
   switch ($message) {
