]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Consumer.php
Our URLs are permanent redirects, mind you!
[quix0rs-gnu-social.git] / classes / Consumer.php
1 <?php
2 /**
3  * Table Definition for consumer
4  */
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6
7 class Consumer extends Managed_DataObject
8 {
9     ###START_AUTOCODE
10     /* the code below is auto generated do not remove the above tag */
11
12     public $__table = 'consumer';                        // table name
13     public $consumer_key;                    // varchar(191)  primary_key not_null   not 255 because utf8mb4 takes more space
14     public $consumer_secret;                 // varchar(191)   not_null   not 255 because utf8mb4 takes more space
15     public $seed;                            // char(32)   not_null
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     public static function schemaDef()
23     {
24         return array(
25             'description' => 'OAuth consumer record',
26             'fields' => array(
27                 'consumer_key' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'unique identifier, root URL'),
28                 'consumer_secret' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'secret value'),
29                 'seed' => array('type' => 'char', 'length' => 32, 'not null' => true, 'description' => 'seed for new tokens by this consumer'),
30
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('consumer_key'),
35         );
36     }
37
38     static function generateNew()
39     {
40         $cons = new Consumer();
41         $rand = common_random_hexstr(16);
42
43         $cons->seed            = $rand;
44         $cons->consumer_key    = md5(time() + $rand);
45         $cons->consumer_secret = md5(md5(time() + time() + $rand));
46         $cons->created         = common_sql_now();
47
48         return $cons;
49     }
50
51     /**
52      * Delete a Consumer and related tokens and nonces
53      *
54      * XXX: Should this happen in an OAuthDataStore instead?
55      *
56      */
57     function delete($useWhere=false)
58     {
59         // XXX: Is there any reason NOT to do this kind of cleanup?
60
61         $this->_deleteTokens();
62         $this->_deleteNonces();
63
64         return parent::delete($useWhere);
65     }
66
67     function _deleteTokens()
68     {
69         $token = new Token();
70         $token->consumer_key = $this->consumer_key;
71         $token->delete();
72     }
73
74     function _deleteNonces()
75     {
76         $nonce = new Nonce();
77         $nonce->consumer_key = $this->consumer_key;
78         $nonce->delete();
79     }
80 }