You are here

public function TokenManager::updateToken in Persistent Login 8

Update the provided token's instance identifier.

The new instance value is also propagated the to the database.

Parameters

\Drupal\persistent_login\PersistentToken $token: The token.

Return value

\Drupal\persistent_login\PersistentToken An updated token.

File

src/TokenManager.php, line 195

Class

TokenManager
Class TokenManager.

Namespace

Drupal\persistent_login

Code

public function updateToken(PersistentToken $token) {
  $originalInstance = $token
    ->getInstance();
  $token = $token
    ->updateInstance($this->csrfToken
    ->get(Crypt::randomBytesBase64()));
  try {
    $this->connection
      ->update('persistent_login')
      ->fields([
      'instance' => $token
        ->getInstance(),
      'refreshed' => $token
        ->getRefreshed()
        ->getTimestamp(),
    ])
      ->condition('series', $token
      ->getSeries())
      ->condition('instance', $originalInstance)
      ->execute();
  } catch (\Exception $e) {
    throw new TokenException("An error occurred updating the token", 0, $e);
  }
  return $token;
}