You are here

roleassign.install in RoleAssign 5

Same filename and directory in other branches
  1. 6 roleassign.install
  2. 7.2 roleassign.install
  3. 7 roleassign.install

File

roleassign.install
View source
<?php

/**
 * 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.  
 */
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;
}

/**
 * Implementation of hook_uninstall().
 */
function roleassign_uninstall() {

  // Deleted RoleAssign's variables
  global $conf;
  $result = db_query("SELECT name FROM {variable} WHERE name LIKE 'roleassign_%'");
  while ($row = db_fetch_array($result)) {
    unset($conf[$row['name']]);
  }
  $result = $result && db_query("DELETE FROM {variable} WHERE name LIKE 'roleassign_%'");
  _roleassign_install_message(t('Failed to delete variables for RoleAssign.'), $result);
  cache_clear_all('variables', 'cache');
  _roleassign_install_message();
}
function _roleassign_install_message($message = '', $result = NULL) {
  static $success = true;
  if (isset($result)) {
    if (!$result) {
      drupal_set_message($message, 'error');
      $success = false;
    }
  }
  elseif ($success) {
    drupal_set_message($message);
  }
}

Functions

Namesort descending Description
roleassign_uninstall Implementation of hook_uninstall().
roleassign_update_1 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.
_roleassign_install_message