You are here

function logintoboggan_cron in LoginToboggan 6

Same name and namespace in other branches
  1. 8 logintoboggan.module \logintoboggan_cron()
  2. 7 logintoboggan.module \logintoboggan_cron()

Implementation of hook_cron().

File

./logintoboggan.module, line 27
Logintoboggan Module

Code

function logintoboggan_cron() {

  // If set password is enabled, and a purge interval is set, check for
  // unvalidated users to purge.
  if (($purge_interval = variable_get('logintoboggan_purge_unvalidated_user_interval', 0)) && !variable_get('user_email_verification', TRUE)) {
    $validating_id = logintoboggan_validating_id();

    // As a safety check, make sure that we have a non-core role as the
    // pre-auth role -- otherwise skip.
    if (!in_array($validating_id, array(
      DRUPAL_ANONYMOUS_RID,
      DRUPAL_AUTHENTICATED_RID,
    ))) {
      $purge_time = time() - $purge_interval;
      $accounts = db_query("SELECT u.uid, u.name FROM {users} u INNER JOIN {users_roles} ur ON u.uid = ur.uid WHERE ur.rid = %d AND u.created < %d", $validating_id, $purge_time);
      $purged_users = array();

      // Delete the users from the system.
      while ($account = db_fetch_object($accounts)) {
        user_delete(array(), $account->uid);
        $purged_users[] = check_plain($account->name);
      }

      // Log the purged users.
      if (!empty($purged_users)) {
        watchdog('logintoboggan', 'Purged the following unvalidated users: !purged_users', array(
          '!purged_users' => theme('item_list', $purged_users),
        ));
      }
    }
  }
}