3 * Table Definition for msn_waiting_message
\r
5 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
\r
7 class Msn_waiting_message extends Managed_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 $claimed; // datetime()
\r
14 public $created; // datetime() not_null
\r
15 public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
\r
17 public static function schemaDef()
\r
21 'id' => array('type' => 'serial', 'not null' => true, 'description' => 'Unique ID for entry'),
\r
22 'screenname' => array('type' => 'varchar', 'length' => 255, 'description' => 'from screenname'),
\r
23 'message' => array('type' => 'text', 'not null' => true, 'description' => 'MSN message text'),
\r
24 'claimed' => array('type' => 'datetime', 'description' => 'date this irc message was claimed'),
\r
25 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
\r
26 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
\r
28 'primary key' => array('id'),
\r
30 'msn_waiting_message_prioritise_idx' => array('screenname'),
\r
36 * @param string $screenname screenname or array of screennames to pull from
\r
37 * If not specified, checks all queues in the system.
\r
39 public static function top($screenname = null) {
\r
40 $wm = new Msn_waiting_message();
\r
42 if (is_array($screenname)) {
\r
43 // @fixme use safer escaping
\r
44 $list = implode("','", array_map('addslashes', $screenname));
\r
45 $wm->whereAdd("screenname in ('$list')");
\r
47 $wm->screenname = $screenname;
\r
50 $wm->orderBy('created');
\r
51 $wm->whereAdd('claimed is null');
\r
55 $cnt = $wm->find(true);
\r
58 // XXX: potential race condition
\r
59 // can we force it to only update if claimed is still null
\r
61 common_log(LOG_INFO, 'claiming msn waiting message id = ' . $wm->id);
\r
63 $wm->claimed = common_sql_now();
\r
64 $result = $wm->update($orig);
\r
66 common_log(LOG_INFO, 'claim succeeded.');
\r
69 common_log(LOG_INFO, 'claim failed.');
\r
77 * Release a claimed item.
\r
79 public function releaseClaim() {
\r
80 // DB_DataObject doesn't let us save nulls right now
\r
81 $sql = sprintf("UPDATE msn_waiting_message SET claimed=NULL WHERE id=%d", $this->id);
\r
84 $this->claimed = null;
\r