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

@@ -80,27 +80,8 @@ class BlacklistPlugin extends Plugin
$schema = Schema::get();
// For storing blacklist patterns for nicknames
$schema->ensureTable('nickname_blacklist',
array(new ColumnDef('pattern',
'varchar',
255,
false,
'PRI'),
new ColumnDef('created',
'datetime',
null,
false)));
$schema->ensureTable('homepage_blacklist',
array(new ColumnDef('pattern',
'varchar',
255,
false,
'PRI'),
new ColumnDef('created',
'datetime',
null,
false)));
$schema->ensureTable('nickname_blacklist', Nickname_blacklist::schemaDef());
$schema->ensureTable('homepage_blacklist', Homepage_blacklist::schemaDef());
return true;
}

View File

@@ -47,47 +47,20 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
class Homepage_blacklist extends Managed_DataObject
{
public $__table = 'homepage_blacklist'; // table name
public $pattern; // string pattern
public $created; // datetime
public $pattern; // varchar(255) pattern
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('pattern' => 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; this function
* defines them.
*
* @return array key definitions
*/
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.
*
* @return array key definitions
*/
function keyTypes()
{
return array('pattern' => 'K');
return array(
'fields' => array(
'pattern' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'blacklist pattern'),
'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('pattern'),
);
}
/**

View File

@@ -47,38 +47,20 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
class Nickname_blacklist extends Managed_DataObject
{
public $__table = 'nickname_blacklist'; // table name
public $pattern; // string pattern
public $created; // datetime
public $pattern; // varchar(255) pattern
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('pattern' => 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
*
* @return array key definitions
*/
function keys()
{
return array_keys($this->keyTypes());
}
/**
* return key definitions for Memcached_DataObject
*
* @return array key definitions
*/
function keyTypes()
{
return array('pattern' => 'K');
return array(
'fields' => array(
'pattern' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'blacklist pattern'),
'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('pattern'),
);
}
/**