3 * Table Definition for irc_waiting_message
\r
6 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
\r
8 class Irc_waiting_message extends Memcached_DataObject {
\r
10 public $__table = 'irc_waiting_message'; // table name
\r
11 public $id; // int primary_key not_null auto_increment
\r
12 public $data; // blob not_null
\r
13 public $prioritise; // tinyint(1) not_null
\r
14 public $attempts; // int not_null
\r
15 public $created; // datetime() not_null
\r
16 public $claimed; // datetime()
\r
19 public function staticGet($k, $v = null) {
\r
20 return Memcached_DataObject::staticGet('Irc_waiting_message', $k, $v);
\r
24 * return table definition for DB_DataObject
\r
26 * DB_DataObject needs to know something about the table to manipulate
\r
27 * instances. This method provides all the DB_DataObject needs to know.
\r
29 * @return array array of column definitions
\r
31 public function table() {
\r
32 return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
\r
33 'data' => DB_DATAOBJECT_BLOB + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
\r
34 'prioritise' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
\r
35 'created' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
\r
36 'claimed' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR);
\r
40 * return key definitions for DB_DataObject
\r
42 * DB_DataObject needs to know about keys that the table has, since it
\r
43 * won't appear in StatusNet's own keys list. In most cases, this will
\r
44 * simply reference your keyTypes() function.
\r
46 * @return array list of key field names
\r
48 public function keys() {
\r
49 return array_keys($this->keyTypes());
\r
53 * return key definitions for Memcached_DataObject
\r
55 * Our caching system uses the same key definitions, but uses a different
\r
56 * method to get them. This key information is used to store and clear
\r
57 * cached data, so be sure to list any key that will be used for static
\r
60 * @return array associative array of key definitions, field name to type:
\r
61 * 'K' for primary key: for compound keys, add an entry for each component;
\r
62 * 'U' for unique keys: compound keys are not well supported here.
\r
64 public function keyTypes() {
\r
65 return array('id' => 'K');
\r
69 * Magic formula for non-autoincrementing integer primary keys
\r
71 * If a table has a single integer column as its primary key, DB_DataObject
\r
72 * assumes that the column is auto-incrementing and makes a sequence table
\r
73 * to do this incrementation. Since we don't need this for our class, we
\r
74 * overload this method and return the magic formula that DB_DataObject needs.
\r
76 * @return array magic three-false array that stops auto-incrementing.
\r
78 public function sequenceKey() {
\r
79 return array(false, false, false);
\r
83 * Get the next item in the queue
\r
85 * @return Irc_waiting_message Next message if there is one
\r
87 public static function top() {
\r
88 $wm = new Irc_waiting_message();
\r
90 $wm->orderBy('prioritise DESC, created');
\r
91 $wm->whereAdd('claimed is null');
\r
95 $cnt = $wm->find(true);
\r
98 // XXX: potential race condition
\r
99 // can we force it to only update if claimed is still null
\r
101 common_log(LOG_INFO, 'claiming IRC waiting message id = ' . $wm->id);
\r
102 $orig = clone($wm);
\r
103 $wm->claimed = common_sql_now();
\r
104 $result = $wm->update($orig);
\r
106 common_log(LOG_INFO, 'claim succeeded.');
\r
109 common_log(LOG_INFO, 'claim failed.');
\r
117 * Increment the attempts count
\r
120 * @throws Exception
\r
122 public function incAttempts() {
\r
123 $orig = clone($this);
\r
125 $result = $this->update($orig);
\r
128 // TRANS: Exception thrown when an IRC attempts count could not be updated.
\r
129 // TRANS: %d is the object ID for which the count could not be updated.
\r
130 throw Exception(sprintf(_m('Could not increment attempts count for %d.'), $this->id));
\r
135 * Release a claimed item.
\r
137 public function releaseClaim() {
\r
138 // DB_DataObject doesn't let us save nulls right now
\r
139 $sql = sprintf("UPDATE irc_waiting_message SET claimed=NULL WHERE id=%d", $this->id);
\r
140 $this->query($sql);
\r
142 $this->claimed = null;
\r