You are here

function module_grants_update_6207 in Module Grants 6.3

Same name and namespace in other branches
  1. 6.4 module_grants.install \module_grants_update_6207()

Rename permissions. Core doesn't support apostrophes so strip these out and capitalise the permission name for readibility. Example: "access 'I can edit' tab" is transformed to "access I Can Edit tab". See [#566290], [#572804].

File

./module_grants.install, line 56
Install and uninstall hooks for Module Grants module

Code

function module_grants_update_6207() {
  $ret = array();

  // permission.perm column contains a comma-separated string of permissions
  $result = db_query("SELECT rid,perm FROM {permission} WHERE perm LIKE '%access \\'%\\' tab%'");
  while ($permissions = db_fetch_object($result)) {

    // See http://www.php.net/manual/en/function.preg-replace-callback.php
    // Note: using create_function() as PHP 5.2 does not support closures (anonymous functions)
    $sanitized_permissions = preg_replace_callback("/access \\'([A-Z a-z]+)\\' tab/", create_function('$matches', 'return "access ". ucwords($matches[1]) ." tab";'), $permissions->perm);
    $ret[] = update_sql("UPDATE {permission} SET perm='" . db_escape_string($sanitized_permissions) . "' WHERE rid={$permissions->rid}");
  }
  return $ret;
}