]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/Irc/Irc_waiting_message.php
Woops, forgot auto_increment (comes with 'serial')
[quix0rs-gnu-social.git] / plugins / Irc / Irc_waiting_message.php
index 59eec63d8d697e8ad4855cd3108140493fe581df..eefd9049855df6cd3edca76be5ef2f745d1d04c0 100644 (file)
@@ -2,80 +2,37 @@
 /**\r
  * Table Definition for irc_waiting_message\r
  */\r
+\r
 require_once INSTALLDIR.'/classes/Memcached_DataObject.php';\r
 \r
-class Irc_waiting_message extends Memcached_DataObject {\r
+class Irc_waiting_message extends Managed_DataObject {\r
 \r
     public $__table = 'irc_waiting_message'; // table name\r
     public $id;                              // int primary_key not_null auto_increment\r
     public $data;                            // blob not_null\r
     public $prioritise;                      // tinyint(1) not_null\r
     public $attempts;                        // int not_null\r
-    public $created;                         // datetime() not_null\r
     public $claimed;                         // datetime()\r
-\r
-    /* Static get */\r
-    public function staticGet($k, $v = null) {\r
-        return Memcached_DataObject::staticGet('Irc_waiting_message', $k, $v);\r
-    }\r
-\r
-    /**\r
-    * return table definition for DB_DataObject\r
-    *\r
-    * DB_DataObject needs to know something about the table to manipulate\r
-    * instances. This method provides all the DB_DataObject needs to know.\r
-    *\r
-    * @return array array of column definitions\r
-    */\r
-    public function table() {\r
-        return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,\r
-                     'data' => DB_DATAOBJECT_BLOB + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,\r
-                     'prioritise' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,\r
-                     'created' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,\r
-                     'claimed' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR);\r
-    }\r
-\r
-    /**\r
-    * return key definitions for DB_DataObject\r
-    *\r
-    * DB_DataObject needs to know about keys that the table has, since it\r
-    * won't appear in StatusNet's own keys list. In most cases, this will\r
-    * simply reference your keyTypes() function.\r
-    *\r
-    * @return array list of key field names\r
-    */\r
-    public function keys() {\r
-        return array_keys($this->keyTypes());\r
-    }\r
-\r
-    /**\r
-    * return key definitions for Memcached_DataObject\r
-    *\r
-    * Our caching system uses the same key definitions, but uses a different\r
-    * method to get them. This key information is used to store and clear\r
-    * cached data, so be sure to list any key that will be used for static\r
-    * lookups.\r
-    *\r
-    * @return array associative array of key definitions, field name to type:\r
-    *         'K' for primary key: for compound keys, add an entry for each component;\r
-    *         'U' for unique keys: compound keys are not well supported here.\r
-    */\r
-    public function keyTypes() {\r
-        return array('id' => 'K');\r
-    }\r
-\r
-    /**\r
-    * Magic formula for non-autoincrementing integer primary keys\r
-    *\r
-    * If a table has a single integer column as its primary key, DB_DataObject\r
-    * assumes that the column is auto-incrementing and makes a sequence table\r
-    * to do this incrementation. Since we don't need this for our class, we\r
-    * overload this method and return the magic formula that DB_DataObject needs.\r
-    *\r
-    * @return array magic three-false array that stops auto-incrementing.\r
-    */\r
-    public function sequenceKey() {\r
-        return array(false, false, false);\r
+    public $created;                         // datetime()   not_null\r
+    public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP\r
+\r
+    public static function schemaDef()\r
+    {\r
+        return array(\r
+            'fields' => array(\r
+                'id' => array('type' => 'serial', 'not null' => true, 'description' => 'Unique ID for entry'),\r
+                'data' => array('type' => 'blob', 'not null' => true, 'description' => 'data blob'),\r
+                'prioritise' => array('type' => 'int', 'size' => 'tiny', 'description' => 'tinyint priority value'),\r
+                'attempts' => array('type' => 'int', 'not null' => true, 'description' => 'attempts count'),\r
+                'claimed' => array('type' => 'datetime', 'description' => 'date this irc message was claimed'),\r
+                'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),\r
+                'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),\r
+            ),\r
+            'primary key' => array('id'),\r
+            'indexes' => array(\r
+                'irc_waiting_message_prioritise_idx' => array('prioritise'),\r
+            ),\r
+        );\r
     }\r
 \r
     /**\r
@@ -94,9 +51,9 @@ class Irc_waiting_message extends Memcached_DataObject {
         $cnt = $wm->find(true);\r
 \r
         if ($cnt) {\r
-            # XXX: potential race condition\r
-            # can we force it to only update if claimed is still null\r
-            # (or old)?\r
+            // XXX: potential race condition\r
+            // can we force it to only update if claimed is still null\r
+            // (or old)?\r
             common_log(LOG_INFO, 'claiming IRC waiting message id = ' . $wm->id);\r
             $orig = clone($wm);\r
             $wm->claimed = common_sql_now();\r
@@ -124,7 +81,9 @@ class Irc_waiting_message extends Memcached_DataObject {
         $result = $this->update($orig);\r
 \r
         if (!$result) {\r
-            throw Exception(sprintf(_m("Could not increment attempts count for %d"), $this->id));\r
+            // TRANS: Exception thrown when an IRC attempts count could not be updated.\r
+            // TRANS: %d is the object ID for which the count could not be updated.\r
+            throw Exception(sprintf(_m('Could not increment attempts count for %d.'), $this->id));\r
         }\r
     }\r
 \r