3 * Table Definition for msn_waiting_message
\r
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
\r
7 class Msn_waiting_message extends Memcached_DataObject {
\r
9 public $__table = 'msn_waiting_message'; // table name
\r
10 public $id; // int primary_key not_null auto_increment
\r
11 public $screenname; // varchar(255) not_null
\r
12 public $message; // text not_null
\r
13 public $created; // datetime() not_null
\r
14 public $claimed; // datetime()
\r
17 public function staticGet($k, $v = null) {
\r
18 return Memcached_DataObject::staticGet('Msn_waiting_message', $k, $v);
\r
22 * return table definition for DB_DataObject
\r
24 * DB_DataObject needs to know something about the table to manipulate
\r
25 * instances. This method provides all the DB_DataObject needs to know.
\r
27 * @return array array of column definitions
\r
29 public function table() {
\r
30 return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
\r
31 'screenname' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
\r
32 'message' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
\r
33 'created' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
\r
34 'claimed' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR);
\r
38 * return key definitions for DB_DataObject
\r
40 * DB_DataObject needs to know about keys that the table has, since it
\r
41 * won't appear in StatusNet's own keys list. In most cases, this will
\r
42 * simply reference your keyTypes() function.
\r
44 * @return array list of key field names
\r
46 public function keys() {
\r
47 return array_keys($this->keyTypes());
\r
51 * return key definitions for Memcached_DataObject
\r
53 * Our caching system uses the same key definitions, but uses a different
\r
54 * method to get them. This key information is used to store and clear
\r
55 * cached data, so be sure to list any key that will be used for static
\r
58 * @return array associative array of key definitions, field name to type:
\r
59 * 'K' for primary key: for compound keys, add an entry for each component;
\r
60 * 'U' for unique keys: compound keys are not well supported here.
\r
62 public function keyTypes() {
\r
63 return array('id' => 'K');
\r
67 * Magic formula for non-autoincrementing integer primary keys
\r
69 * If a table has a single integer column as its primary key, DB_DataObject
\r
70 * assumes that the column is auto-incrementing and makes a sequence table
\r
71 * to do this incrementation. Since we don't need this for our class, we
\r
72 * overload this method and return the magic formula that DB_DataObject needs.
\r
74 * @return array magic three-false array that stops auto-incrementing.
\r
76 function sequenceKey() {
\r
77 return array(false, false, false);
\r
81 * @param string $screenname screenname or array of screennames to pull from
\r
82 * If not specified, checks all queues in the system.
\r
84 public static function top($screenname = null) {
\r
85 $wm = new Msn_waiting_message();
\r
87 if (is_array($screenname)) {
\r
88 // @fixme use safer escaping
\r
89 $list = implode("','", array_map('addslashes', $screenname));
\r
90 $wm->whereAdd("screenname in ('$list')");
\r
92 $wm->screenname = $screenname;
\r
95 $wm->orderBy('created');
\r
96 $wm->whereAdd('claimed is null');
\r
100 $cnt = $wm->find(true);
\r
103 # XXX: potential race condition
\r
104 # can we force it to only update if claimed is still null
\r
106 common_log(LOG_INFO, 'claiming msn waiting message id = ' . $wm->id);
\r
107 $orig = clone($wm);
\r
108 $wm->claimed = common_sql_now();
\r
109 $result = $wm->update($orig);
\r
111 common_log(LOG_INFO, 'claim succeeded.');
\r
114 common_log(LOG_INFO, 'claim failed.');
\r
122 * Release a claimed item.
\r
124 public function releaseClaim() {
\r
125 // DB_DataObject doesn't let us save nulls right now
\r
126 $sql = sprintf("UPDATE msn_waiting_message SET claimed=NULL WHERE id=%d", $this->id);
\r
127 $this->query($sql);
\r
129 $this->claimed = null;
\r