From 68ec3f855d84025a124b5a25736f9cef7badd8d6 Mon Sep 17 00:00:00 2001 From: Luke Fitzgerald Date: Sat, 31 Jul 2010 10:47:58 -0700 Subject: [PATCH] Fix a bunch of bugs where DB object wasn't correctly defined --- plugins/Msn/MsnPlugin.php | 2 +- plugins/Msn/msn_waiting_message.php | 63 ++++++++++++++++++++++++++++- plugins/Msn/msnmanager.php | 5 ++- 3 files changed, 66 insertions(+), 4 deletions(-) diff --git a/plugins/Msn/MsnPlugin.php b/plugins/Msn/MsnPlugin.php index 3d9f19c0a5..9db3f7763b 100644 --- a/plugins/Msn/MsnPlugin.php +++ b/plugins/Msn/MsnPlugin.php @@ -136,7 +136,7 @@ class MsnPlugin extends ImPlugin { $schema->ensureTable('msn_waiting_message', array(new ColumnDef('id', 'integer', null, false, 'PRI', null, null, true), - new ColumnDef('screenname', 'integer', null, false), + new ColumnDef('screenname', 'varchar', 255, false), new ColumnDef('message', 'text', null, false), new ColumnDef('created', 'datetime', null, false), new ColumnDef('claimed', 'datetime'))); diff --git a/plugins/Msn/msn_waiting_message.php b/plugins/Msn/msn_waiting_message.php index 0efd8b0203..d69520b40b 100644 --- a/plugins/Msn/msn_waiting_message.php +++ b/plugins/Msn/msn_waiting_message.php @@ -1,6 +1,6 @@ DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL, + 'screenname' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL, + 'message' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL, + 'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL, + 'claimed' => DB_DATAOBJECT_STR); + } + + /** + * return key definitions for DB_DataObject + * + * DB_DataObject needs to know about keys that the table has, since it + * won't appear in StatusNet's own keys list. In most cases, this will + * simply reference your keyTypes() function. + * + * @return array list of key field names + */ + public function keys() { + return array_keys($this->keyTypes()); + } + + /** + * return key definitions for Memcached_DataObject + * + * Our caching system uses the same key definitions, but uses a different + * method to get them. This key information is used to store and clear + * cached data, so be sure to list any key that will be used for static + * lookups. + * + * @return array associative array of key definitions, field name to type: + * 'K' for primary key: for compound keys, add an entry for each component; + * 'U' for unique keys: compound keys are not well supported here. + */ + public function keyTypes() { + return array('id' => 'K'); + } + + /** + * Magic formula for non-autoincrementing integer primary keys + * + * If a table has a single integer column as its primary key, DB_DataObject + * assumes that the column is auto-incrementing and makes a sequence table + * to do this incrementation. Since we don't need this for our class, we + * overload this method and return the magic formula that DB_DataObject needs. + * + * @return array magic three-false array that stops auto-incrementing. + */ + function sequenceKey() { + return array(false, false, false); + } + + /** + * @param string $screenname screenname or array of screennames to pull from * If not specified, checks all queues in the system. */ public static function top($screenname = null) { diff --git a/plugins/Msn/msnmanager.php b/plugins/Msn/msnmanager.php index 9014501e7e..1eac596df2 100644 --- a/plugins/Msn/msnmanager.php +++ b/plugins/Msn/msnmanager.php @@ -170,13 +170,16 @@ class MsnManager extends ImManager { * @param array $data Data */ public function handle_session_ready($data) { - while (($wm = Msn_waiting_message::top($data['to']) != NULL)) { + $wm = Msn_waiting_message::top($data['to']); + while ($wm != NULL) { if ($this->conn->sendMessage($wm->screenname, $wm->message, $ignore)) { $wm->delete(); } else { // Requeue the message in the regular queue $this->plugin->send_message($wm->screenname, $wm->message); } + + $wm = Msn_waiting_message::top($data['to']); } }