3 * Table Definition for oauth_application_user
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
7 class Oauth_application_user extends Managed_DataObject
10 /* the code below is auto generated do not remove the above tag */
12 public $__table = 'oauth_application_user'; // table name
13 public $profile_id; // int(4) primary_key not_null
14 public $application_id; // int(4) primary_key not_null
15 public $access_type; // tinyint(1)
16 public $token; // varchar(191) not 255 because utf8mb4 takes more space
17 public $created; // datetime not_null
18 public $modified; // timestamp not_null default_CURRENT_TIMESTAMP
20 /* the code above is auto generated do not remove the tag below */
23 public static function schemaDef()
27 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'user of the application'),
28 'application_id' => array('type' => 'int', 'not null' => true, 'description' => 'id of the application'),
29 'access_type' => array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'description' => 'access type, bit 1 = read, bit 2 = write'),
30 'token' => array('type' => 'varchar', 'length' => 191, 'description' => 'request or access token'),
31 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
32 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
34 'primary key' => array('profile_id', 'application_id'),
35 'foreign keys' => array(
36 'oauth_application_user_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
37 'oauth_application_user_application_id_fkey' => array('oauth_application', array('application_id' => 'id')),
42 static function getByUserAndToken($user, $token)
44 if (empty($user) || empty($token)) {
48 $oau = new Oauth_application_user();
50 $oau->profile_id = $user->id;
54 $result = $oau->find(true);
56 return empty($result) ? null : $oau;
59 function updateKeys(&$orig)
63 foreach (array('profile_id', 'application_id', 'token', 'access_type') as $k) {
64 if (strcmp($this->$k, $orig->$k) != 0) {
65 $parts[] = $k . ' = ' . $this->_quote($this->$k);
68 if (count($parts) == 0) {
72 $toupdate = implode(', ', $parts);
74 $table = $this->tableName();
75 if(common_config('db','quote_identifiers')) {
76 $table = '"' . $table . '"';
78 $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
79 ' WHERE profile_id = ' . $orig->profile_id
80 . ' AND application_id = ' . $orig->application_id
81 . " AND token = '$orig->token'";
83 $result = $this->query($qry);