]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - classes/Consumer.php
Merge branch 'master' of gitorious.org:statusnet/mainline into feedfix
[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 Memcached_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     static function generateNew()
27     {
28         $cons = new Consumer();
29         $rand = common_good_rand(16);
30
31         $cons->seed            = $rand;
32         $cons->consumer_key    = md5(time() + $rand);
33         $cons->consumer_secret = md5(md5(time() + time() + $rand));
34         $cons->created         = common_sql_now();
35
36         return $cons;
37     }
38
39     /**
40      * Delete a Consumer and related tokens and nonces
41      *
42      * XXX: Should this happen in an OAuthDataStore instead?
43      *
44      */
45     function delete()
46     {
47         // XXX: Is there any reason NOT to do this kind of cleanup?
48
49         $this->_deleteTokens();
50         $this->_deleteNonces();
51
52         parent::delete();
53     }
54
55     function _deleteTokens()
56     {
57         $token = new Token();
58         $token->consumer_key = $this->consumer_key;
59         $token->delete();
60     }
61
62     function _deleteNonces()
63     {
64         $nonce = new Nonce();
65         $nonce->consumer_key = $this->consumer_key;
66         $nonce->delete();
67     }
68 }