]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Oauth_token_association.php
Merge remote-tracking branch 'upstream/master' into social-master
[quix0rs-gnu-social.git] / classes / Oauth_token_association.php
1 <?php
2 /**
3  * Table Definition for oauth_association
4  */
5 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
6
7 class Oauth_token_association 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_token_association';          // table name
13     public $profile_id;                      // int(4)  primary_key not_null
14     public $application_id;                  // int(4)  primary_key not_null
15     public $token;                           // varchar(191) primary key not null   not 255 because utf8mb4 takes more space
16     public $created;                         // datetime   not_null
17     public $modified;                        // timestamp   not_null default_CURRENT_TIMESTAMP
18
19     /* the code above is auto generated do not remove the tag below */
20     ###END_AUTOCODE
21
22     static function getByUserAndToken($user, $token)
23     {
24         if (empty($user) || empty($token)) {
25             return null;
26         }
27
28         $oau = new oauth_request_token();
29
30         $oau->profile_id = $user->id;
31         $oau->token      = $token;
32         $oau->limit(1);
33
34         $result = $oau->find(true);
35
36         return empty($result) ? null : $oau;
37     }
38
39     public static function schemaDef()
40     {
41         return array(
42             'description' => 'Associate an application ID and profile ID with an OAuth token',
43             'fields' => array(
44                 'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'associated user'),
45                 'application_id' => array('type' => 'int', 'not null' => true, 'description' => 'the application'),
46                 'token' => array('type' => 'varchar', 'length' => '191', 'not null' => true, 'description' => 'token used for this association'),
47                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
48                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
49             ),
50             'primary key' => array('profile_id', 'application_id', 'token'),
51             'foreign keys' => array(
52                 'oauth_token_association_profile_fkey' => array('profile_id', array('profile' => 'id')),
53                 'oauth_token_association_application_fkey' => array('application_id', array('application' => 'id')),
54             )
55         );
56     }
57 }