You are here

function roleassign_update_1 in RoleAssign 5

Implementation of hook_update_1(). Removes data stored by misstake in the data column of the user table. Thank you hunmonk for pointing this out.

File

./roleassign.install, line 9

Code

function roleassign_update_1() {
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      $users = db_query('SELECT uid FROM {users}');
      while ($user = db_fetch_object($users)) {
        $data = unserialize(db_result(db_query('SELECT data FROM {users} WHERE uid = %d', $user->uid)));
        if (isset($data['roleassign_roles'])) {
          unset($data['roleassign_roles']);
          $data = serialize($data);
          $sql = "UPDATE {users} SET data = '%s' WHERE uid = %d";
          $result = db_query($sql, $data, $user->uid);
          $ret[] = array(
            'success' => $result !== FALSE,
            'query' => check_plain(sprintf($sql, '...', $user->uid)),
          );

          // See update_sql().
        }
      }
      break;
    case 'pgsql':
      _roleassign_install_message(t('RoleAssign doesn\'t support PostgreSQL – yet.'));
      break;
  }
  return $ret;
}