3 * Store last-touched ID for various timelines
9 * @author Evan Prodromou <evan@status.net>
10 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11 * @link http://status.net/
13 * StatusNet - the distributed open-source microblogging tool
14 * Copyright (C) 2010, StatusNet, Inc.
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.
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.
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/>.
30 if (!defined('STATUSNET')) {
34 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
37 * Store various timeline data
39 * We don't want to keep re-fetching the same statuses and direct messages from Twitter.
40 * So, we store the last ID we see from a timeline, and store it. Next time
41 * around, we use that ID in the since_id parameter.
45 * @author Evan Prodromou <evan@status.net>
46 * @license http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
47 * @link http://status.net/
51 class Twitter_synch_status extends Memcached_DataObject
53 public $__table = 'twitter_synch_status'; // table name
54 public $foreign_id; // int(4) primary_key not_null
55 public $timeline; // varchar(255) primary_key not_null
56 public $last_id; // bigint not_null
57 public $created; // datetime not_null
58 public $modified; // datetime not_null
61 * Get an instance by key
63 * @param string $k Key to use to lookup (usually 'foreign_id' for this class)
64 * @param mixed $v Value to lookup
66 * @return Twitter_synch_status object found, or null for no hits
69 function staticGet($k, $v=null)
71 throw new Exception("Use pkeyGet() for this class.");
75 * Get an instance by compound primary key
77 * @param array $kv key-value pair array
79 * @return Twitter_synch_status object found, or null for no hits
84 return Memcached_DataObject::pkeyGet('Twitter_synch_status', $kv);
88 * return table definition for DB_DataObject
90 * DB_DataObject needs to know something about the table to manipulate
91 * instances. This method provides all the DB_DataObject needs to know.
93 * @return array array of column definitions
97 return array('foreign_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
98 'timeline' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
99 'last_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
100 'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
101 'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL
106 * return key definitions for DB_DataObject
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.
112 * @return array list of key field names
116 return array_keys($this->keyTypes());
120 * return key definitions for Memcached_DataObject
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
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.
133 return array('foreign_id' => 'K',
138 * Magic formula for non-autoincrementing integer primary keys
140 * If a table has a single integer column as its primary key, DB_DataObject
141 * assumes that the column is auto-incrementing and makes a sequence table
142 * to do this incrementation. Since we don't need this for our class, we
143 * overload this method and return the magic formula that DB_DataObject needs.
145 * @return array magic three-false array that stops auto-incrementing.
147 function sequenceKey()
149 return array(false, false, false);
152 static function getLastId($foreign_id, $timeline)
154 $tss = self::pkeyGet(array('foreign_id' => $foreign_id,
155 'timeline' => $timeline));
160 return $tss->last_id;
164 static function setLastId($foreign_id, $timeline, $last_id)
166 $tss = self::pkeyGet(array('foreign_id' => $foreign_id,
167 'timeline' => $timeline));
170 $tss = new Twitter_synch_status();
172 $tss->foreign_id = $foreign_id;
173 $tss->timeline = $timeline;
174 $tss->last_id = $last_id;
175 $tss->created = common_sql_now();
176 $tss->modified = $tss->created;
184 $tss->last_id = $last_id;
185 $tss->modified = common_sql_now();