You are here

function role_expire_update_8102 in Role Expire 8

Same name and namespace in other branches
  1. 2.x role_expire.install \role_expire_update_8102()

Migrate default durations table to configuration.

File

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

Code

function role_expire_update_8102() {
  $connection = Database::getConnection();

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

  // Save current configuration.
  if (!empty($durations)) {
    \Drupal::configFactory()
      ->getEditable('role_expire.config')
      ->set('role_expire_default_duration_roles', $durations)
      ->save();
  }

  // Drop current database table.
  $connection
    ->schema()
    ->dropTable('role_expire_length');
}