You are here

function deploy_uuid_user in Deploy - Content Staging 6

Implementation of hook_user().

This mostly relates to managing the mapped uid->uuid mapping. There is some non-uuid-related code below, which I decided to keep in this module anyways for the purposes of code organization.

File

modules/deploy_uuid/deploy_uuid.module, line 177
Deployment UUID management

Code

function deploy_uuid_user($op, &$edit, &$account, $category = NULL) {
  switch ($op) {
    case 'update':

      // Users submitted through deployment contain the original password, which has been MD5 hashed.
      // Unforutnately when this user object is passed through user_save, this password is then itself
      // MD5 hashed. So in this situation, we need to do an update to the user table forcing the
      // password back to its original value.
      if ($edit['deploy']) {
        db_query("UPDATE {users} SET pass = '%s' WHERE uid = %d", $edit['pass'], $account->uid);
      }
      break;
    case 'after update':
      break;
    case 'load':

      // If the user has an accompanying uuid, then add it to the $account object.
      // This makes things easier and cleaner than always having a uuid field and
      // having it sometimes be empty.
      $uuid = db_result(db_query("SELECT uuid FROM {users_uuid} WHERE uid = %d", $account->uid));
      if ($uuid) {
        $account->uuid = $uuid;
      }
      break;
    case 'insert':

      // The only case in which we would have a node come through insert with a uuid already in place
      // is the case where it's being deployed from a remote source. In this case, keep the existing
      // uuid. Otherwise, create a new one.
      if (!empty($edit['uuid'])) {
        db_query("INSERT INTO {users_uuid} (uid, uuid) VALUES (%d, '%s')", $account->uid, $edit['uuid']);
      }
      else {
        db_query("INSERT INTO {users_uuid} (uid, uuid) VALUES (%d, '%s')", $account->uid, deploy_uuid_create_uuid());
      }

      // Users submitted through deployment contain the original password, which has been MD5 hashed.
      // Unforutnately when this user object is passed through user_save, this password is then itself
      // MD5 hashed. So in this situation, we need to do an update to the user table forcing the
      // password back to its original value.
      if ($edit['deploy']) {
        db_query("UPDATE {users} SET pass = '%s' WHERE uid = %d", $edit['pass'], $account->uid);
      }
      break;
    case 'delete':
      db_query("DELETE FROM {users_uuid} WHERE uid = %d", $account->uid);
      break;
  }
}