]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Oauth_application_user.php
Don't abort on too long notices in Notice::saveActivity
[quix0rs-gnu-social.git] / classes / Oauth_application_user.php
1 <?php
2 /**
3  * Table Definition for oauth_application_user
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class Oauth_application_user extends Managed_DataObject
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
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
19
20     /* the code above is auto generated do not remove the tag below */
21     ###END_AUTOCODE
22
23     public static function schemaDef()
24     {
25         return array(
26             'fields' => array(
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'),
33             ),
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')),
38             ),
39         );
40     }
41
42     static function getByUserAndToken($user, $token)
43     {
44         if (empty($user) || empty($token)) {
45             return null;
46         }
47
48         $oau = new Oauth_application_user();
49
50         $oau->profile_id = $user->id;
51         $oau->token      = $token;
52         $oau->limit(1);
53
54         $result = $oau->find(true);
55
56         return empty($result) ? null : $oau;
57     }
58
59     function updateKeys(&$orig)
60     {
61         $this->_connect();
62         $parts = array();
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);
66             }
67         }
68         if (count($parts) == 0) {
69             // No changes
70             return true;
71         }
72         $toupdate = implode(', ', $parts);
73
74         $table = $this->tableName();
75         if(common_config('db','quote_identifiers')) {
76             $table = '"' . $table . '"';
77         }
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'";
82         $orig->decache();
83         $result = $this->query($qry);
84         if ($result) {
85             $this->encache();
86         }
87         return $result;
88     }
89 }