You are here

function salesforce_update_8003 in Salesforce Suite 5.0.x

Same name and namespace in other branches
  1. 8.4 salesforce.install \salesforce_update_8003()
  2. 8.3 salesforce.install \salesforce_update_8003()

Move API credentials from state to config.

File

./salesforce.install, line 240
Salesforce install file.

Code

function salesforce_update_8003() {

  // Populate config from state.
  $config = \Drupal::configFactory()
    ->getEditable('salesforce.settings');
  if ($consumer_key = \Drupal::state()
    ->get('salesforce.consumer_key', FALSE)) {
    $config
      ->set('consumer_key', $consumer_key);
  }
  if ($consumer_secret = \Drupal::state()
    ->get('salesforce.consumer_secret', FALSE)) {
    $config
      ->set('consumer_secret', $consumer_secret);
  }
  if ($login_url = \Drupal::state()
    ->get('salesforce.login_url', FALSE)) {
    $config
      ->set('login_url', $login_url);
  }
  $config
    ->save();

  // Delete deprecated state variables.
  $delete = [
    'salesforce.consumer_key',
    'salesforce.consumer_secret',
    'salesforce.login_url',
  ];
  \Drupal::state()
    ->deleteMultiple($delete);
}