]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/YammerImport/classes/Yammer_state.php
Merge branch '1.0.x' of gitorious.org:statusnet/mainline into 1.0.x
[quix0rs-gnu-social.git] / plugins / YammerImport / classes / Yammer_state.php
1 <?php
2 /**
3  * Data class for remembering Yammer import state
4  *
5  * PHP version 5
6  *
7  * @category Data
8  * @package  StatusNet
9  * @author   Brion Vibber <brion@status.net>
10  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11  * @link     http://status.net/
12  *
13  * StatusNet - the distributed open-source microblogging tool
14  * Copyright (C) 2010, StatusNet, Inc.
15  *
16  * This program is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU Affero General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
24  * GNU Affero General Public License for more details.
25  *
26  * You should have received a copy of the GNU Affero General Public License
27  * along with this program. If not, see <http://www.gnu.org/licenses/>.
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 class Yammer_state extends Memcached_DataObject
35 {
36     public $__table = 'yammer_state'; // table name
37     public $id;                       // int  primary_key not_null
38     public $state;                    // import state key
39     public $last_error;               // text of last-encountered error, if any
40     public $oauth_token;              // actual oauth token! clear when import is done?
41     public $oauth_secret;             // actual oauth secret! clear when import is done?
42     public $users_page;               // last page of users we've fetched
43     public $groups_page;              // last page of groups we've fetched
44     public $messages_oldest;          // oldest message ID we've fetched
45     public $messages_newest;          // newest message ID we've imported
46     public $created;                  // datetime
47     public $modified;                 // datetime
48
49     /**
50      * Get an instance by key
51      *
52      * This is a utility method to get a single instance with a given key value.
53      *
54      * @param string $k Key to use to lookup
55      * @param mixed  $v Value to lookup
56      *
57      * @return Yammer_state object found, or null for no hits
58      */
59     function staticGet($k, $v=null)
60     {
61         return Memcached_DataObject::staticGet('Yammer_state', $k, $v);
62     }
63
64     /**
65      * Return schema definition to set this table up in onCheckSchema
66      */
67     static function schemaDef()
68     {
69         return array(new ColumnDef('id', 'int', null,
70                                    false, 'PRI'),
71                      new ColumnDef('state', 'text'),
72                      new ColumnDef('last_error', 'text'),
73                      new ColumnDef('oauth_token', 'text'),
74                      new ColumnDef('oauth_secret', 'text'),
75                      new ColumnDef('users_page', 'int'),
76                      new ColumnDef('groups_page', 'int'),
77                      new ColumnDef('messages_oldest', 'bigint'),
78                      new ColumnDef('messages_newest', 'bigint'),
79                      new ColumnDef('created', 'datetime'),
80                      new ColumnDef('modified', 'datetime'));
81     }
82
83     /**
84      * return table definition for DB_DataObject
85      *
86      * DB_DataObject needs to know something about the table to manipulate
87      * instances. This method provides all the DB_DataObject needs to know.
88      *
89      * @return array array of column definitions
90      */
91     function table()
92     {
93         return array('id'              => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
94                      'state'           => DB_DATAOBJECT_STR,
95                      'last_error'      => DB_DATAOBJECT_STR,
96                      'oauth_token'     => DB_DATAOBJECT_STR,
97                      'oauth_secret'    => DB_DATAOBJECT_STR,
98                      'users_page'      => DB_DATAOBJECT_INT,
99                      'groups_page'     => DB_DATAOBJECT_INT,
100                      'messages_oldest' => DB_DATAOBJECT_INT,
101                      'messages_newest' => DB_DATAOBJECT_INT,
102                      'created'         => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
103     }
104
105     /**
106      * return key definitions for DB_DataObject
107      *
108      * DB_DataObject needs to know about keys that the table has, since it
109      * won't appear in StatusNet's own keys list. In most cases, this will
110      * simply reference your keyTypes() function.
111      *
112      * @return array list of key field names
113      */
114     function keys()
115     {
116         return array_keys($this->keyTypes());
117     }
118
119     /**
120      * return key definitions for Memcached_DataObject
121      *
122      * Our caching system uses the same key definitions, but uses a different
123      * method to get them. This key information is used to store and clear
124      * cached data, so be sure to list any key that will be used for static
125      * lookups.
126      *
127      * @return array associative array of key definitions, field name to type:
128      *         'K' for primary key: for compound keys, add an entry for each component;
129      *         'U' for unique keys: compound keys are not well supported here.
130      */
131     function keyTypes()
132     {
133         return array('id' => 'K');
134     }
135
136     /**
137      * Magic formula for non-autoincrementing integer primary keys
138      *
139      * If a table has a single integer column as its primary key, DB_DataObject
140      * assumes that the column is auto-incrementing and makes a sequence table
141      * to do this incrementation. Since we don't need this for our class, we
142      * overload this method and return the magic formula that DB_DataObject needs.
143      *
144      * @return array magic three-false array that stops auto-incrementing.
145      */
146     function sequenceKey()
147     {
148         return array(false, false, false);
149     }
150 }