You are here

public function UserManager::updateToken in Social Post 3.x

Same name and namespace in other branches
  1. 8.2 src/User/UserManager.php \Drupal\social_post\User\UserManager::updateToken()

Update token of a particular record.

Parameters

string $plugin_id: Type of social network.

string $provider_user_id: Unique Social ID returned by social network.

string $token: Token provided by social_network.

Return value

bool True if updated False otherwise

File

src/User/UserManager.php, line 152

Class

UserManager
Manages database related tasks.

Namespace

Drupal\social_post\User

Code

public function updateToken($plugin_id, $provider_user_id, $token) {

  /** @var \Drupal\social_post\Entity\SocialPost|false $social_post_user */
  $social_post_user = current($this->entityTypeManager
    ->getStorage($this->entityType)
    ->loadByProperties([
    'plugin_id' => $plugin_id,
    'provider_user_id' => $provider_user_id,
  ]));
  if ($social_post_user === FALSE) {
    return FALSE;
  }
  try {
    $social_post_user
      ->setToken($token)
      ->save();
    return TRUE;
  } catch (EntityStorageException $e) {
    $this->loggerFactory
      ->get($this
      ->getPluginId())
      ->error('Failed to save user with updated token. Error @error', [
      '@error' => $e
        ->getMessage(),
    ]);
    return FALSE;
  }
}