You are here

function uuid_user in Universally Unique IDentifier 6

Same name and namespace in other branches
  1. 5 uuid.module \uuid_user()

Implementation of hook_user().

File

./uuid.module, line 205
Main module functions for the uuid module.

Code

function uuid_user($op, &$edit, &$user, $category = NULL) {
  switch ($op) {
    case 'load':
      $user->uuid = db_result(db_query('SELECT uuid FROM {uuid_users} WHERE uid = %d', $user->uid));
      break;
    case 'insert':
      $insert = NULL;
      if (isset($user->uuid) && uuid_is_valid($user->uuid)) {
        $insert = $user->uuid;
      }
      else {
        if (isset($edit['uuid']) && uuid_is_valid($edit['uuid'])) {
          $insert = $user->uuid = $edit['uuid'];
        }
        else {
          if (variable_get('uuid_automatic_for_users', FALSE)) {
            $insert = $user->uuid = uuid_uuid();
          }
        }
      }
      if ($insert) {
        db_query("INSERT INTO {uuid_users} (uid, uuid) VALUES (%d, '%s')", $user->uid, $user->uuid);
      }
      break;
    case 'update':
      if (isset($user->uuid) && uuid_is_valid($user->uuid)) {
        $exists = db_result(db_query('SELECT 1 FROM {uuid_users} WHERE uid = %d', $user->uid));
        if (!$exists) {
          db_query("INSERT INTO {uuid_users} (uid, uuid) VALUES (%d, '%s')", $user->uid, $user->uuid);
        }
      }
      break;
    case 'delete':
      db_query('DELETE FROM {uuid_users} WHERE uid = %d', $user->uid);
      break;
  }
}