forked from GNUsocial/gnu-social
IMPORTANT: Making prev. Memcached_DataObject working again with schemaDef
Lots of the Memcached_DataObject classes stopped working when upgraded to Managed_DataObject because they lacked schemaDef(). I have _hopefully_ made it so that all the references to the table uses each class' schemaDef, rather than the more manual ColumnDef stuff. Not all plugins have been tested thoroughly yet. NOTE: This is applied with getKV calls instead of staticGet, as it was important for PHP Strict Standards compliance to avoid calling the non- static functions statically. (unfortunately DB and DB_DataObject still do this within themselves...)
This commit is contained in:
@@ -133,14 +133,7 @@ class MsnPlugin extends ImPlugin {
|
||||
$schema = Schema::get();
|
||||
|
||||
// For storing messages while sessions become ready
|
||||
$schema->ensureTable('msn_waiting_message',
|
||||
array(new ColumnDef('id', 'integer', null,
|
||||
false, 'PRI', null, null, true),
|
||||
new ColumnDef('screenname', 'varchar', 255, false),
|
||||
new ColumnDef('message', 'text', null, false),
|
||||
new ColumnDef('created', 'datetime', null, false),
|
||||
new ColumnDef('claimed', 'datetime')));
|
||||
|
||||
$schema->ensureTable('msn_waiting_message', Msn_waiting_message::schemaGet());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -10,66 +10,26 @@ class Msn_waiting_message extends Managed_DataObject {
|
||||
public $id; // int primary_key not_null auto_increment
|
||||
public $screenname; // varchar(255) not_null
|
||||
public $message; // text not_null
|
||||
public $created; // datetime() not_null
|
||||
public $claimed; // datetime()
|
||||
public $created; // datetime() not_null
|
||||
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
|
||||
|
||||
/**
|
||||
* return table definition for DB_DataObject
|
||||
*
|
||||
* DB_DataObject needs to know something about the table to manipulate
|
||||
* instances. This method provides all the DB_DataObject needs to know.
|
||||
*
|
||||
* @return array array of column definitions
|
||||
*/
|
||||
public function table() {
|
||||
return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
|
||||
'screenname' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
|
||||
'message' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
|
||||
'created' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
|
||||
'claimed' => DB_DATAOBJECT_TIME + 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);
|
||||
public static function schemaDef()
|
||||
{
|
||||
return array(
|
||||
'fields' => array(
|
||||
'id' => array('type' => 'int', 'not null' => true, 'description' => 'Unique ID for entry'),
|
||||
'screenname' => array('type' => 'varchar', 'length' => 255, 'description' => 'from screenname'),
|
||||
'message' => array('type' => 'text', 'not null' => true, 'description' => 'MSN message text'),
|
||||
'claimed' => array('type' => 'datetime', 'description' => 'date this irc message was claimed'),
|
||||
'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
|
||||
'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
|
||||
),
|
||||
'primary key' => array('id'),
|
||||
'indexes' => array(
|
||||
'msn_waiting_message_prioritise_idx' => array('screenname'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user