You are here

function logintoboggan_update_2 in LoginToboggan 6

Same name and namespace in other branches
  1. 5 logintoboggan.install \logintoboggan_update_2()

Implementation of hook_update_2()

File

./logintoboggan.install, line 14

Code

function logintoboggan_update_2() {

  // get all serialized user data.
  $users = db_query('SELECT uid, data FROM {users}');
  while ($user = db_fetch_object($users)) {
    $data = unserialize($user->data);
    $updated_data = array();

    // Extract conf_mail and conf_pass from the user's data
    if (is_array($data)) {
      foreach ($data as $key => $value) {
        if (!in_array($key, array(
          'conf_mail',
          'conf_pass',
        ))) {
          $updated_data[$key] = $value;
        }
      }

      // reinsert the cleaned data for the user
      $updated_data = serialize($updated_data);
      db_query("UPDATE {users} SET data = '%s' WHERE uid = %d", $updated_data, $user->uid);
    }
  }
  drupal_set_message(t('logintoboggan cleaning of user data successful'));
  return array();
}