3 * Table Definition for irc_waiting_message
\r
6 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
\r
8 class Irc_waiting_message extends Managed_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 * return table definition for DB_DataObject
\r
21 * DB_DataObject needs to know something about the table to manipulate
\r
22 * instances. This method provides all the DB_DataObject needs to know.
\r
24 * @return array array of column definitions
\r
26 public function table() {
\r
27 return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
\r
28 'data' => DB_DATAOBJECT_BLOB + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
\r
29 'prioritise' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
\r
30 'created' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
\r
31 'claimed' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR);
\r
35 * return key definitions for DB_DataObject
\r
37 * DB_DataObject needs to know about keys that the table has, since it
\r
38 * won't appear in StatusNet's own keys list. In most cases, this will
\r
39 * simply reference your keyTypes() function.
\r
41 * @return array list of key field names
\r
43 public function keys() {
\r
44 return array_keys($this->keyTypes());
\r
48 * return key definitions for Memcached_DataObject
\r
50 * Our caching system uses the same key definitions, but uses a different
\r
51 * method to get them. This key information is used to store and clear
\r
52 * cached data, so be sure to list any key that will be used for static
\r
55 * @return array associative array of key definitions, field name to type:
\r
56 * 'K' for primary key: for compound keys, add an entry for each component;
\r
57 * 'U' for unique keys: compound keys are not well supported here.
\r
59 public function keyTypes() {
\r
60 return array('id' => 'K');
\r
64 * Magic formula for non-autoincrementing integer primary keys
\r
66 * If a table has a single integer column as its primary key, DB_DataObject
\r
67 * assumes that the column is auto-incrementing and makes a sequence table
\r
68 * to do this incrementation. Since we don't need this for our class, we
\r
69 * overload this method and return the magic formula that DB_DataObject needs.
\r
71 * @return array magic three-false array that stops auto-incrementing.
\r
73 public function sequenceKey() {
\r
74 return array(false, false, false);
\r
78 * Get the next item in the queue
\r
80 * @return Irc_waiting_message Next message if there is one
\r
82 public static function top() {
\r
83 $wm = new Irc_waiting_message();
\r
85 $wm->orderBy('prioritise DESC, created');
\r
86 $wm->whereAdd('claimed is null');
\r
90 $cnt = $wm->find(true);
\r
93 // XXX: potential race condition
\r
94 // can we force it to only update if claimed is still null
\r
96 common_log(LOG_INFO, 'claiming IRC waiting message id = ' . $wm->id);
\r
98 $wm->claimed = common_sql_now();
\r
99 $result = $wm->update($orig);
\r
101 common_log(LOG_INFO, 'claim succeeded.');
\r
104 common_log(LOG_INFO, 'claim failed.');
\r
112 * Increment the attempts count
\r
115 * @throws Exception
\r
117 public function incAttempts() {
\r
118 $orig = clone($this);
\r
120 $result = $this->update($orig);
\r
123 // TRANS: Exception thrown when an IRC attempts count could not be updated.
\r
124 // TRANS: %d is the object ID for which the count could not be updated.
\r
125 throw Exception(sprintf(_m('Could not increment attempts count for %d.'), $this->id));
\r
130 * Release a claimed item.
\r
132 public function releaseClaim() {
\r
133 // DB_DataObject doesn't let us save nulls right now
\r
134 $sql = sprintf("UPDATE irc_waiting_message SET claimed=NULL WHERE id=%d", $this->id);
\r
135 $this->query($sql);
\r
137 $this->claimed = null;
\r