system_update_7007

Definition

system_update_7007()
modules/system/system.install, line 2956

Description

Convert to new method of storing permissions.

This update is in system.install rather than user.install so that all modules can use the updated permission scheme during their updates.

Code

<?php
function system_update_7007() {
  $ret = array();

  $schema['role_permission'] = array(
    'fields' => array(
      'rid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'permission' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array('rid', 'permission'),
    'indexes' => array(
      'permission' => array('permission'),
    ),
  );

  db_create_table($ret, 'role_permission', $schema['role_permission']);

  // Copy the permissions from the old {permission} table to the new {role_permission} table.
  $result = db_query("SELECT rid, perm FROM {permission} ORDER BY rid ASC");
  while ($role = db_fetch_object($result)) {
    foreach (explode(', ', $role->perm) as $perm) {
      db_query("INSERT INTO {role_permission} (rid, permission) VALUES (%d, '%s')", $role->rid, $perm);
    }
    $ret[] = array('success' => TRUE, 'query' => "Inserted into {role_permission} the permissions for role ID " . $role->rid);
  }
  db_drop_table($ret, 'permission');

  return $ret;
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.