3 * Table Definition for irc_waiting_message
\r
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
\r
7 class Irc_waiting_message extends Memcached_DataObject {
\r
9 public $__table = 'irc_waiting_message'; // table name
\r
10 public $id; // int primary_key not_null auto_increment
\r
11 public $data; // blob not_null
\r
12 public $prioritise; // tinyint(1) not_null
\r
13 public $attempts; // int not_null
\r
14 public $created; // datetime() not_null
\r
15 public $claimed; // datetime()
\r
18 public function staticGet($k, $v = null) {
\r
19 return Memcached_DataObject::staticGet('Irc_waiting_message', $k, $v);
\r
23 * return table definition for DB_DataObject
\r
25 * DB_DataObject needs to know something about the table to manipulate
\r
26 * instances. This method provides all the DB_DataObject needs to know.
\r
28 * @return array array of column definitions
\r
30 public function table() {
\r
31 return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
\r
32 'data' => DB_DATAOBJECT_BLOB + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
\r
33 'prioritise' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
\r
34 'created' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
\r
35 'claimed' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR);
\r
39 * return key definitions for DB_DataObject
\r
41 * DB_DataObject needs to know about keys that the table has, since it
\r
42 * won't appear in StatusNet's own keys list. In most cases, this will
\r
43 * simply reference your keyTypes() function.
\r
45 * @return array list of key field names
\r
47 public function keys() {
\r
48 return array_keys($this->keyTypes());
\r
52 * return key definitions for Memcached_DataObject
\r
54 * Our caching system uses the same key definitions, but uses a different
\r
55 * method to get them. This key information is used to store and clear
\r
56 * cached data, so be sure to list any key that will be used for static
\r
59 * @return array associative array of key definitions, field name to type:
\r
60 * 'K' for primary key: for compound keys, add an entry for each component;
\r
61 * 'U' for unique keys: compound keys are not well supported here.
\r
63 public function keyTypes() {
\r
64 return array('id' => 'K');
\r
68 * Magic formula for non-autoincrementing integer primary keys
\r
70 * If a table has a single integer column as its primary key, DB_DataObject
\r
71 * assumes that the column is auto-incrementing and makes a sequence table
\r
72 * to do this incrementation. Since we don't need this for our class, we
\r
73 * overload this method and return the magic formula that DB_DataObject needs.
\r
75 * @return array magic three-false array that stops auto-incrementing.
\r
77 public function sequenceKey() {
\r
78 return array(false, false, false);
\r
82 * Get the next item in the queue
\r
84 * @return Irc_waiting_message Next message if there is one
\r
86 public static function top() {
\r
87 $wm = new Irc_waiting_message();
\r
89 $wm->orderBy('prioritise DESC, created');
\r
90 $wm->whereAdd('claimed is null');
\r
94 $cnt = $wm->find(true);
\r
97 # XXX: potential race condition
\r
98 # can we force it to only update if claimed is still null
\r
100 common_log(LOG_INFO, 'claiming IRC waiting message id = ' . $wm->id);
\r
101 $orig = clone($wm);
\r
102 $wm->claimed = common_sql_now();
\r
103 $result = $wm->update($orig);
\r
105 common_log(LOG_INFO, 'claim succeeded.');
\r
108 common_log(LOG_INFO, 'claim failed.');
\r
116 * Increment the attempts count
\r
119 * @throws Exception
\r
121 public function incAttempts() {
\r
122 $orig = clone($this);
\r
124 $result = $this->update($orig);
\r
127 throw Exception(sprintf(_m("Could not increment attempts count for %d"), $this->id));
\r
132 * Release a claimed item.
\r
134 public function releaseClaim() {
\r
135 // DB_DataObject doesn't let us save nulls right now
\r
136 $sql = sprintf("UPDATE irc_waiting_message SET claimed=NULL WHERE id=%d", $this->id);
\r
137 $this->query($sql);
\r
139 $this->claimed = null;
\r