You are here

function shib_auth_update_7000 in Shibboleth Authentication 7.4

Updates the database structure for compatibility with Drupal 7.

D7 database API don't support datetime type anymore, so we change the database structure.

File

./shib_auth.install, line 147
Install file of the Shibboleth authentication module for Drupal system.

Code

function shib_auth_update_7000(&$sandbox) {

  // Save the created datetime temporaly.
  $res = db_select('shib_authmap', 'sa')
    ->fields('sa', array(
    'id',
    'created',
  ))
    ->execute()
    ->fetchAll();

  // Change to the created column type from datetime to int.
  db_add_field('shib_authmap', 'created_unix', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => FALSE,
  ));

  // Fill the database with unixtimestamps.
  foreach ($res as $row) {
    if (is_numeric($row->created)) {

      // Suppose it's already a timestamp, see #1380826.
      continue;
    }
    if (!($created_unix = strtotime($row->created))) {
      $created_unix = $row->created;
    }
    db_update('shib_authmap')
      ->fields(array(
      'created_unix' => $created_unix,
    ))
      ->condition('id', $row->id, '=')
      ->execute();
  }
  db_drop_field('shib_authmap', 'created');
  db_change_field('shib_authmap', 'created_unix', 'created', array(
    'type' => 'int',
  ));

  // Update the menu system cache.
  menu_rebuild();
}