]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Consumer.php
1d32d853bd015fef055c3ca9ac965c3c0d2955c9
[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(255)  primary_key not_null
14     public $consumer_secret;                 // varchar(255)   not_null
15     public $seed;                            // char(32)   not_null
16     public $created;                         // datetime   not_null
17     public $modified;                        // timestamp   not_null default_CURRENT_TIMESTAMP
18
19     /* Static get */
20     function staticGet($k,$v=null)
21     { return Memcached_DataObject::staticGet('Consumer',$k,$v); }
22
23     /* the code above is auto generated do not remove the tag below */
24     ###END_AUTOCODE
25
26     public static function schemaDef()
27     {
28         return array(
29             'description' => 'OAuth consumer record',
30             'fields' => array(
31                 'consumer_key' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'unique identifier, root URL'),
32                 'consumer_secret' => array('type' => 'varchar', 'length' => 255, 'not null' => true, 'description' => 'secret value'),
33                 'seed' => array('type' => 'char', 'length' => 32, 'not null' => true, 'description' => 'seed for new tokens by this consumer'),
34
35                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
36                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
37             ),
38             'primary key' => array('consumer_key'),
39         );
40     }
41
42     static function generateNew()
43     {
44         $cons = new Consumer();
45         $rand = common_good_rand(16);
46
47         $cons->seed            = $rand;
48         $cons->consumer_key    = md5(time() + $rand);
49         $cons->consumer_secret = md5(md5(time() + time() + $rand));
50         $cons->created         = common_sql_now();
51
52         return $cons;
53     }
54
55     /**
56      * Delete a Consumer and related tokens and nonces
57      *
58      * XXX: Should this happen in an OAuthDataStore instead?
59      *
60      */
61     function delete()
62     {
63         // XXX: Is there any reason NOT to do this kind of cleanup?
64
65         $this->_deleteTokens();
66         $this->_deleteNonces();
67
68         parent::delete();
69     }
70
71     function _deleteTokens()
72     {
73         $token = new Token();
74         $token->consumer_key = $this->consumer_key;
75         $token->delete();
76     }
77
78     function _deleteNonces()
79     {
80         $nonce = new Nonce();
81         $nonce->consumer_key = $this->consumer_key;
82         $nonce->delete();
83     }
84 }