You are here

public function DrupalOAuthConsumer::write in OAuth 1.0 6.3

Same name and namespace in other branches
  1. 7.4 includes/DrupalOAuthConsumer.inc \DrupalOAuthConsumer::write()
  2. 7.3 includes/DrupalOAuthConsumer.inc \DrupalOAuthConsumer::write()

Writes the consumer to the database

Return value

void

File

includes/DrupalOAuthConsumer.inc, line 48

Class

DrupalOAuthConsumer

Code

public function write() {
  $update = !empty($this->csid);
  $primary = $update ? array(
    'csid',
  ) : array();
  if ($this->provider_consumer) {
    $this->changed = time();
    $values = array(
      'consumer_key' => $this->key,
      'created' => $this->created,
      'changed' => $this->changed,
      'uid' => $this->uid,
      'name' => $this->name,
      'context' => $this->context,
      'callback_url' => $this->callback_url,
    );
    if ($update) {
      $values['csid'] = $this->csid;
    }
    else {
      $this->created = time();
      $values['created'] = $this->created;
    }
    $ready = drupal_write_record('oauth_common_provider_consumer', $values, $primary);
    if (!$ready) {
      throw new OAuthException("Couldn't save consumer");
    }
  }
  $values = array(
    'key_hash' => sha1($this->key),
    'consumer_key' => $this->key,
    'secret' => $this->secret,
    'configuration' => serialize(empty($this->configuration) ? array() : $this->configuration),
  );
  if ($update) {
    $values['csid'] = $this->csid;
  }
  drupal_write_record('oauth_common_consumer', $values, $primary);
  $this->csid = $values['csid'];
  $this->in_database = TRUE;
  if (!$update) {
    $values = array(
      'csid' => $this->csid,
      'consumer_key' => $this->key,
    );
    drupal_write_record('oauth_common_provider_consumer', $values, array(
      'consumer_key',
    ));
  }
}