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:
Mikael Nordfeldth
2013-08-19 17:08:18 +02:00
parent b1465a7559
commit 3a7261f70a
42 changed files with 453 additions and 1332 deletions

View File

@@ -61,69 +61,9 @@ class GroupPrivateMessagePlugin extends Plugin
$schema = Schema::get();
// For storing user-submitted flags on profiles
$schema->ensureTable('group_privacy_settings',
array(new ColumnDef('group_id',
'integer',
null,
false,
'PRI'),
new ColumnDef('allow_privacy',
'integer'),
new ColumnDef('allow_sender',
'integer'),
new ColumnDef('created',
'datetime'),
new ColumnDef('modified',
'timestamp')));
$schema->ensureTable('group_message',
array(new ColumnDef('id',
'char',
36,
false,
'PRI'),
new ColumnDef('uri',
'varchar',
255,
false,
'UNI'),
new ColumnDef('from_profile',
'integer',
null,
false,
'MUL'),
new ColumnDef('to_group',
'integer',
null,
false,
'MUL'),
new ColumnDef('content',
'text'),
new ColumnDef('rendered',
'text'),
new ColumnDef('url',
'varchar',
255,
false,
'UNI'),
new ColumnDef('created',
'datetime')));
$schema->ensureTable('group_message_profile',
array(new ColumnDef('to_profile',
'integer',
null,
false,
'PRI'),
new ColumnDef('group_message_id',
'char',
36,
false,
'PRI'),
new ColumnDef('created',
'datetime')));
$schema->ensureTable('group_privacy_settings', Group_privacy_settings::schemaDef());
$schema->ensureTable('group_message', Group_message::schemaDef());
$schema->ensureTable('group_message_profile', Group_message_profile::schemaDef());
return true;
}

View File

@@ -47,59 +47,44 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
class Group_message extends Managed_DataObject
{
public $__table = 'group_message'; // table name
public $id; // char(36) primary_key not_null
public $id; // varchar(36) primary_key not_null
public $uri; // varchar(255)
public $from_profile; // int
public $to_group; // int
public $content;
public $rendered;
public $url;
public $created;
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('id' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'from_profile' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'to_group' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'content' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'rendered' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'url' => DB_DATAOBJECT_STR,
'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
*
* @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('id' => 'K', 'uri' => 'U');
return array(
'fields' => array(
'id' => array('type' => 'varchar', 'not null' => true, 'length' => 36, 'description' => 'message uuid'),
'uri' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'message uri'),
'url' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'representation url'),
'from_profile' => array('type' => 'int', 'not null' => true, 'description' => 'sending profile ID'),
'to_group' => array('type' => 'int', 'not null' => true, 'description' => 'receiving group ID'),
'content' => array('type' => 'text', 'not null' => true, 'description' => 'message content'),
'rendered' => array('type' => 'text', 'not null' => true, 'description' => 'rendered message'),
'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'),
'unique keys' => array(
'group_message_uri_key' => array('uri'),
),
'foreign keys' => array(
'group_message_from_profile_fkey' => array('profile', array('from_profile' => 'id')),
'group_message_to_group_fkey' => array('user_group', array('to_group' => 'id')),
),
'indexes' => array(
'group_message_from_profile_idx' => array('from_profile'),
'group_message_to_group_idx' => array('to_group'),
'group_message_url_idx' => array('url'),
),
);
}
static function send($user, $group, $text)

View File

@@ -48,56 +48,25 @@ class Group_message_profile extends Managed_DataObject
{
public $__table = 'group_message_profile'; // table name
public $to_profile; // int
public $group_message_id; // char(36) primary_key not_null
public $created;
public $group_message_id; // varchar(36) primary_key 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('to_profile' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'group_message_id' => DB_DATAOBJECT_STR + 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
*
* @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('to_profile' => 'K', 'group_message_id' => 'K');
}
/**
* No sequence keys in this table.
*/
function sequenceKey()
{
return array(false, false, false);
return array(
'fields' => array(
'to_profile' => array('type' => 'int', 'not null' => true, 'description' => 'id of group direct message'),
'group_message_id' => array('type' => 'varchar', 'not null' => true, 'length' => 36, 'description' => 'group message uuid'),
'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('to_profile', 'group_message_id'),
'foreign keys' => array(
'group_message_profile_to_profile_fkey' => array('profile', array('to_profile' => 'id')),
'group_message_profile_group_message_id_fkey' => array('group_message', array('group_message_id' => 'id')),
),
);
}
function send($gm, $profile)

View File

@@ -70,58 +70,21 @@ class Group_privacy_settings extends Managed_DataObject
const MEMBER = 2;
const ADMIN = 4;
/**
* 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('group_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'allow_privacy' => DB_DATAOBJECT_INT,
'allow_sender' => DB_DATAOBJECT_INT,
'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
*
* @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('group_id' => 'K');
}
/**
* Magic formula for non-autoincrementing integer primary keys
*
* @return array magic three-false array that stops auto-incrementing.
*/
function sequenceKey()
{
return array(false, false, false);
return array(
'fields' => array(
'group_id' => array('type' => 'int', 'not null' => true, 'description' => 'group_privacy_settings'),
'allow_privacy' => array('type' => 'int', 'not null' => true, 'description' => 'sometimes=-1, never=0, always=1'),
'allow_sender' => array('type' => 'int', 'not null' => true, 'description' => 'list of bit-mappy values in source code'),
'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('group_id'),
'foreign keys' => array(
'group_privacy_settings_group_id_fkey' => array('user_group', array('group_id' => 'id')),
),
);
}
function forGroup($group)