You are here

function salesforce_update_8006 in Salesforce Suite 5.0.x

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

Convert legacy token to new auth plugin config.

File

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

Code

function salesforce_update_8006() {
  $oauth = SalesforceAuthConfig::load('oauth_default');
  if (!$oauth) {
    return "Auth config missing. Refused to update legacy token.";
  }
  try {
    \Drupal::service('salesforce.auth_token_storage')
      ->retrieveAccessToken($oauth
      ->id());
    return "Token exists. Refused to update.";
  } catch (TokenNotFoundException $e) {
    \Drupal::service('salesforce.auth_token_storage')
      ->storeAccessToken('oauth_default', new SalesforceToken(\Drupal::state()
      ->get('salesforce.access_token'), \Drupal::state()
      ->get('salesforce.refresh_token')));
    return "Updated legacy token to new plugin config.";
  }
}