View source
<?php
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)),
);
}
}
break;
case 'pgsql':
_roleassign_install_message(t('RoleAssign doesn\'t support PostgreSQL – yet.'));
break;
}
return $ret;
}
function roleassign_uninstall() {
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);
}
}