You are here

function cas_update_6301 in CAS 7

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

Migrate authmap entries to new {cas_user} table.

File

./cas.install, line 217
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',
    ),
    'foreign keys' => array(
      'user' => array(
        'table' => 'users',
        'columns' => array(
          'uid' => 'uid',
        ),
      ),
    ),
  );

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

  // Migrate entries from {authmap} to {cas_user}.
  $query = db_select('authmap', 'a')
    ->condition('module', 'cas')
    ->condition('uid', 0, '<>');
  $query
    ->addField('a', 'uid');
  $query
    ->addField('a', 'authname', 'cas_name');
  db_insert('cas_user')
    ->from($query)
    ->execute();

  // Remove old entries in {authmap}.
  db_delete('authmap')
    ->condition('module', 'cas')
    ->execute();
}