You are here

function cas_update_6301 in CAS 6.3

Same name and namespace in other branches
  1. 7 cas.install \cas_update_6301()

Migrate authmap entries to new {cas_user} table.

File

./cas.install, line 203
Installation hooks for the CAS module.

Code

function cas_update_6301() {
  $schema = array();
  $schema['cas_user'] = array(
    'description' => 'Stores CAS authentication mapping.',
    'fields' => array(
      'aid' => array(
        'description' => 'Primary Key: Unique CAS authentication mapping ID.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'uid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => "User's {users}.uid.",
      ),
      'cas_name' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Unique CAS username.',
      ),
    ),
    'unique keys' => array(
      'cas_name' => array(
        'cas_name',
      ),
    ),
    'primary key' => array(
      'aid',
    ),
  );

  // Create {cas_user} table.
  $ret = array();
  db_create_table($ret, 'cas_user', $schema['cas_user']);

  // Migrate entries from {authmap} to {cas_user}.
  db_query('INSERT INTO {cas_user} (uid, cas_name) SELECT a.uid AS uid, a.authname AS cas_name FROM {authmap} a WHERE a.module = "cas" AND a.uid <> 0');

  // Remove old entries in {authmap}.
  db_query('DELETE FROM {authmap} WHERE module = "cas"');
  return $ret;
}