You are here

function cas_post_update_8002 in CAS 2.x

Set default value for new gateway method config option.

File

./cas.post_update.php, line 21
Post-update functions for CAS module.

Code

function cas_post_update_8002() {
  $casConfig = \Drupal::configFactory()
    ->getEditable('cas.settings');

  // We need to migrate away from the single config var we had for indicating
  // how CAS gateway operated into the new config settings.
  $oldGatewaySetting = $casConfig
    ->get('gateway.check_frequency');

  // This value was used to indicate CAS gateway was enabled and should check
  // every page request. We use a -1 recheck time to indicate that.
  if ($oldGatewaySetting === 0) {
    $enabled = TRUE;
    $recheckTime = -1;
  }
  elseif ($oldGatewaySetting === -1) {
    $enabled = TRUE;
    $recheckTime = 720;
  }
  else {
    $enabled = FALSE;
    $recheckTime = 720;
  }
  $casConfig
    ->set('gateway.method', 'server_side')
    ->set('gateway.recheck_time', $recheckTime)
    ->set('gateway.enabled', $enabled)
    ->clear('gateway.check_frequency')
    ->save();
}