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:
@@ -79,12 +79,7 @@ class RegisterThrottlePlugin extends Plugin
|
||||
$schema = Schema::get();
|
||||
|
||||
// For storing user-submitted flags on profiles
|
||||
$schema->ensureTable('registration_ip',
|
||||
array(new ColumnDef('user_id', 'integer', null,
|
||||
false, 'PRI'),
|
||||
new ColumnDef('ipaddress', 'varchar', 15, false, 'MUL'),
|
||||
new ColumnDef('created', 'timestamp', null, false, 'MUL')));
|
||||
|
||||
$schema->ensureTable('registration_ip', Registration_ip::schemaDef());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -47,59 +47,27 @@ class Registration_ip extends Managed_DataObject
|
||||
public $__table = 'registration_ip'; // table name
|
||||
public $user_id; // int(4) primary_key not_null
|
||||
public $ipaddress; // varchar(15)
|
||||
public $created; // timestamp
|
||||
public $created; // datetime() not_null
|
||||
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
|
||||
|
||||
/**
|
||||
* return table definition for DB_DataObject
|
||||
*
|
||||
* @return array array of column definitions
|
||||
*/
|
||||
function table()
|
||||
public static function schemaDef()
|
||||
{
|
||||
return array('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
|
||||
'ipaddress' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
|
||||
'created' => DB_DATAOBJECT_MYSQLTIMESTAMP + DB_DATAOBJECT_NOTNULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* return key definitions for DB_DataObject
|
||||
*
|
||||
* DB_DataObject needs to know about keys that the table has; this function
|
||||
* defines them.
|
||||
*
|
||||
* @return array key definitions
|
||||
*/
|
||||
function keys()
|
||||
{
|
||||
return array('user_id' => 'K');
|
||||
}
|
||||
|
||||
/**
|
||||
* return key definitions for Memcached_DataObject
|
||||
*
|
||||
* Our caching system uses the same key definitions, but uses a different
|
||||
* method to get them.
|
||||
*
|
||||
* @return array key definitions
|
||||
*/
|
||||
function keyTypes()
|
||||
{
|
||||
return $this->keys();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(
|
||||
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id this registration relates to'),
|
||||
'ipaddress' => array('type' => 'varchar', 'length' => 45, 'description' => 'IP address, max 45+null in IPv6'),
|
||||
'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('user_id'),
|
||||
'foreign keys' => array(
|
||||
'registration_ip_user_id_fkey' => array('user', array('user_id' => 'id')),
|
||||
),
|
||||
'indexes' => array(
|
||||
'registration_ip_ipaddress_idx' => array('ipaddress'),
|
||||
'registration_ip_created_idx' => array('created'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user