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:
@@ -57,68 +57,27 @@ class Notice_to_status extends Managed_DataObject
|
||||
{
|
||||
public $__table = 'notice_to_status'; // table name
|
||||
public $notice_id; // int(4) primary_key not_null
|
||||
public $status_id; // int(4)
|
||||
public $created; // datetime
|
||||
public $status_id; // bigint not_null
|
||||
public $created; // datetime() not_null
|
||||
public $modified; // datetime not_null default_0000-00-00%2000%3A00%3A00
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
function table()
|
||||
public static function schemaDef()
|
||||
{
|
||||
return array('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
|
||||
'status_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
|
||||
'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
function keyTypes()
|
||||
{
|
||||
return array('notice_id' => 'K', 'status_id' => 'U');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
return array(
|
||||
'fields' => array(
|
||||
'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'local notice id'),
|
||||
'status_id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'twitter status id'),
|
||||
'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('notice_id'),
|
||||
'unique keys' => array(
|
||||
'status_id_key' => array('status_id'),
|
||||
),
|
||||
'foreign keys' => array(
|
||||
'notice_to_status_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -404,28 +404,10 @@ class TwitterBridgePlugin extends Plugin
|
||||
|
||||
// For saving the last-synched status of various timelines
|
||||
// home_timeline, messages (in), messages (out), ...
|
||||
|
||||
$schema->ensureTable('twitter_synch_status',
|
||||
array(new ColumnDef('foreign_id', 'bigint', null,
|
||||
false, 'PRI'),
|
||||
new ColumnDef('timeline', 'varchar', 255,
|
||||
false, 'PRI'),
|
||||
new ColumnDef('last_id', 'bigint', null, // XXX: check for PostgreSQL
|
||||
false),
|
||||
new ColumnDef('created', 'datetime', null,
|
||||
false),
|
||||
new ColumnDef('modified', 'datetime', null,
|
||||
false)));
|
||||
$schema->ensureTable('twitter_synch_status', Twitter_sync_status::schemaDef());
|
||||
|
||||
// For storing user-submitted flags on profiles
|
||||
|
||||
$schema->ensureTable('notice_to_status',
|
||||
array(new ColumnDef('notice_id', 'integer', null,
|
||||
false, 'PRI'),
|
||||
new ColumnDef('status_id', 'bigint', null, // XXX: check for PostgreSQL
|
||||
false, 'UNI'),
|
||||
new ColumnDef('created', 'datetime', null,
|
||||
false)));
|
||||
$schema->ensureTable('notice_to_status', Notice_to_status::schemaDef());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -51,75 +51,24 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
|
||||
class Twitter_synch_status extends Managed_DataObject
|
||||
{
|
||||
public $__table = 'twitter_synch_status'; // table name
|
||||
public $foreign_id; // int(4) primary_key not_null
|
||||
public $foreign_id; // bigint primary_key not_null
|
||||
public $timeline; // varchar(255) primary_key not_null
|
||||
public $last_id; // bigint not_null
|
||||
public $created; // datetime not_null
|
||||
public $modified; // datetime not_null
|
||||
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
|
||||
*/
|
||||
function table()
|
||||
public static function schemaDef()
|
||||
{
|
||||
return array('foreign_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
|
||||
'timeline' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
|
||||
'last_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
|
||||
'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
|
||||
'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
function keyTypes()
|
||||
{
|
||||
return array('foreign_id' => 'K',
|
||||
'timeline' => '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);
|
||||
return array(
|
||||
'fields' => array(
|
||||
'foreign_id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'Foreign message ID'),
|
||||
'timeline' => array('type' => 'varchar', 'length' => 255, 'description' => 'timeline name'),
|
||||
'last_id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'last id fetched'),
|
||||
'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('foreign_id', 'timeline'),
|
||||
);
|
||||
}
|
||||
|
||||
static function getLastId($foreign_id, $timeline)
|
||||
|
Reference in New Issue
Block a user