Skip to content
Snippets Groups Projects
Commit de95342e authored by Aaron Bauman's avatar Aaron Bauman
Browse files

Remove deprecated method calls from salesforce.install update hooks

parent 5694c6f1
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ use Drupal\Core\Url; ...@@ -9,6 +9,7 @@ use Drupal\Core\Url;
use Drupal\Component\Serialization\Json; use Drupal\Component\Serialization\Json;
use Drupal\salesforce\Entity\SalesforceAuthConfig; use Drupal\salesforce\Entity\SalesforceAuthConfig;
use Drupal\salesforce\SalesforceAuthProviderPluginManager; use Drupal\salesforce\SalesforceAuthProviderPluginManager;
use Drupal\salesforce\Token\SalesforceToken;
use OAuth\Common\Storage\Exception\TokenNotFoundException; use OAuth\Common\Storage\Exception\TokenNotFoundException;
/** /**
...@@ -267,9 +268,6 @@ function salesforce_update_8004() { ...@@ -267,9 +268,6 @@ function salesforce_update_8004() {
\Drupal::cache()->delete('salesforce:objects'); \Drupal::cache()->delete('salesforce:objects');
} }
/**
* Convert legacy oauth credentials to new auth plugin config.
*/
/** /**
* Convert legacy oauth credentials to new auth plugin config. * Convert legacy oauth credentials to new auth plugin config.
*/ */
...@@ -290,7 +288,27 @@ function salesforce_update_8005() { ...@@ -290,7 +288,27 @@ function salesforce_update_8005() {
$message = 'Existing "oauth_default" provider config detected. Refused to set legacy credentials.'; $message = 'Existing "oauth_default" provider config detected. Refused to set legacy credentials.';
} }
else { else {
SalesforceAuthProviderPluginManager::updateAuthConfig(); /** @var \Drupal\salesforce\Entity\SalesforceAuthConfig $oauth */
$oauth = NULL;
$config = \Drupal::configFactory()->getEditable('salesforce.settings');
// Config to new plugin config system.
$values = [
'id' => 'oauth_default',
'label' => 'OAuth Default',
'provider' => 'oauth',
];
$oauth = SalesforceAuthConfig::create($values);
$settings = [
'consumer_key' => $config->get('consumer_key'),
'consumer_secret' => $config->get('consumer_secret'),
'login_url' => $config->get('login_url'),
];
$oauth
->set('provider_settings', $settings)
->save();
$config
->set('salesforce_auth_provider', 'oauth_default')
->save();
$message = 'Default OAuth provider created from legacy credentials.'; $message = 'Default OAuth provider created from legacy credentials.';
} }
return $message; return $message;
...@@ -300,19 +318,21 @@ function salesforce_update_8005() { ...@@ -300,19 +318,21 @@ function salesforce_update_8005() {
* Convert legacy token to new auth plugin config. * Convert legacy token to new auth plugin config.
*/ */
function salesforce_update_8006() { function salesforce_update_8006() {
/** @var \Drupal\salesforce\Entity\SalesforceAuthConfig $oauth */ $oauth = SalesforceAuthConfig::load('oauth_default');
$oauth = SalesforceAuthProviderPluginManager::getAuthConfig();
if (!$oauth) { if (!$oauth) {
return "Auth config missing. Refused to update legacy token."; return "Auth config missing. Refused to update legacy token.";
} }
try { try {
if (\Drupal::service('salesforce.auth_token_storage') \Drupal::service('salesforce.auth_token_storage')
->retrieveAccessToken($oauth->id())) { ->retrieveAccessToken($oauth->id());
return "Token exists. Refused to update."; return "Token exists. Refused to update.";
}
} }
catch (TokenNotFoundException $e) { catch (TokenNotFoundException $e) {
\Drupal::service('salesforce.auth_token_storage')->updateToken(); \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."; return "Updated legacy token to new plugin config.";
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment