git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

Oauth_application_user.php 3.44 KB
Newer Older
1 2 3 4
<?php
/**
 * Table Definition for oauth_application_user
 */
5
require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
6

7
class Oauth_application_user extends Managed_DataObject
8 9 10 11 12
{
    ###START_AUTOCODE
    /* the code below is auto generated do not remove the above tag */

    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 21

    /* the code above is auto generated do not remove the tag below */
    ###END_AUTOCODE
22

23 24 25 26 27 28 29
    public static function schemaDef()
    {
        return array(
            'fields' => array(
                'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'user of the application'),
                'application_id' => array('type' => 'int', 'not null' => true, 'description' => 'id of the application'),
                '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 32 33 34 35 36 37 38 39 40 41
                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
            ),
            'primary key' => array('profile_id', 'application_id'),
            'foreign keys' => array(
                'oauth_application_user_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
                'oauth_application_user_application_id_fkey' => array('oauth_application', array('application_id' => 'id')),
            ),
        );
    }

42
    static function getByUserAndToken($user, $token)
43
    {
44
        if (empty($user) || empty($token)) {
45 46 47 48 49
            return null;
        }

        $oau = new Oauth_application_user();

50 51
        $oau->profile_id = $user->id;
        $oau->token      = $token;
52 53 54 55 56 57
        $oau->limit(1);

        $result = $oau->find(true);

        return empty($result) ? null : $oau;
    }
58 59 60 61 62 63 64 65 66 67 68

    function updateKeys(&$orig)
    {
        $this->_connect();
        $parts = array();
        foreach (array('profile_id', 'application_id', 'token', 'access_type') as $k) {
            if (strcmp($this->$k, $orig->$k) != 0) {
                $parts[] = $k . ' = ' . $this->_quote($this->$k);
            }
        }
        if (count($parts) == 0) {
69
            // No changes
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
            return true;
        }
        $toupdate = implode(', ', $parts);

        $table = $this->tableName();
        if(common_config('db','quote_identifiers')) {
            $table = '"' . $table . '"';
        }
        $qry = 'UPDATE ' . $table . ' SET ' . $toupdate .
          ' WHERE profile_id = ' . $orig->profile_id
          . ' AND application_id = ' . $orig->application_id
          . " AND token = '$orig->token'";
        $orig->decache();
        $result = $this->query($qry);
        if ($result) {
            $this->encache();
        }
        return $result;
    }
89
}