public function DrupalOAuthToken::write in OAuth 1.0 7.4
Same name and namespace in other branches
- 6.3 includes/DrupalOAuthToken.inc \DrupalOAuthToken::write()
- 7.3 includes/DrupalOAuthToken.inc \DrupalOAuthToken::write()
Writes the token to the database
Return value
void
File
- includes/
DrupalOAuthToken.inc, line 48
Class
Code
public function write() {
$update = !empty($this->tid);
$primary = $update ? array(
'tid',
) : array();
if ($this->consumer->provider_consumer) {
$this->changed = REQUEST_TIME;
$values = array(
'token_key' => $this->key,
'changed' => $this->changed,
'services' => json_encode($this->services),
'authorized' => $this->authorized,
);
if ($update) {
$values['tid'] = $this->tid;
}
else {
$this->created = REQUEST_TIME;
$values['created'] = $this->created;
}
$ready = drupal_write_record('oauth_common_provider_token', $values, $primary);
if (!$ready) {
throw new OAuthException("Couldn't save token");
}
}
$values = array(
'csid' => $this->consumer->csid,
'key_hash' => sha1($this->key),
'token_key' => $this->key,
'secret' => $this->secret,
'expires' => $this->expires,
'type' => $this->type,
'uid' => $this->uid,
);
if ($update) {
$values['tid'] = $this->tid;
}
drupal_write_record('oauth_common_token', $values, $primary);
$this->tid = $values['tid'];
$this->in_database = TRUE;
if (!$update) {
$values = array(
'tid' => $this->tid,
'token_key' => $this->key,
);
drupal_write_record('oauth_common_provider_token', $values, array(
'token_key',
));
}
}