You are here

function homebox_update_6005 in Homebox 6

Update the permissions table, to fix invalid permission names having non-English characters.

File

./homebox.install, line 122
The install file for Home box allows the module to install (and uninstall) itself. This is required as this module uses its own table.

Code

function homebox_update_6005() {
  $ret = array();
  $res = db_query('SELECT rid, perm FROM {permission}');
  $perms = array();
  drupal_load('module', 'homebox');
  while ($p = db_fetch_object($res)) {
    $perm = $p->perm;
    foreach (homebox_pages() as $page) {
      $perm = preg_replace('/access homebox ' . $page->name . '/', 'access homebox ' . $page->safe_name, $perm);
    }
    $perms[$p->rid] = $perm;
  }
  foreach ($perms as $rid => $permission) {

    // Use db_query as update_sql() could fail if single quotes are in a permission string.
    db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $permission, $rid);
    $ret[] = array(
      'success' => TRUE,
      'query' => 'UPDATE {permission} SET perm = ' . check_plain($permission) . ' WHERE rid = ' . $rid,
    );
  }
  return $ret;
}