You are here

function role_expire_update_7101 in Role Expire 7

Update schema for default role_expire_length table. Convert integer days to text "# days".

File

./role_expire.install, line 88
Role expire install.

Code

function role_expire_update_7101() {

  // Fetch out all the current durations.
  $result = db_query('SELECT rid,duration FROM {role_expire_length}');
  $durations = array();
  while ($row = $result
    ->fetchObject()) {
    $durations[$row->rid] = $row->duration;
  }

  // Convert the original duration column from type int to type text
  $field = array(
    'type' => 'text',
    'size' => 'small',
    'not null' => TRUE,
    'description' => t('A strtotime-compatible default duration string.'),
  );
  db_change_field('role_expire_length', 'duration', 'duration', $field);

  // Append "days" since that's all it could've been before this revision.
  foreach ($durations as $rid => $duration) {
    db_update('role_expire_length')
      ->fields(array(
      'duration' => "{$duration} days",
    ))
      ->condition('rid', $rid)
      ->execute();
  }
}