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

@@ -554,25 +554,8 @@ class OpenIDPlugin extends Plugin
function onCheckSchema()
{
$schema = Schema::get();
$schema->ensureTable('user_openid',
array(new ColumnDef('canonical', 'varchar',
'255', false, 'PRI'),
new ColumnDef('display', 'varchar',
'255', false, 'UNI'),
new ColumnDef('user_id', 'integer',
null, false, 'MUL'),
new ColumnDef('created', 'datetime',
null, false),
new ColumnDef('modified', 'timestamp')));
$schema->ensureTable('user_openid_trustroot',
array(new ColumnDef('trustroot', 'varchar',
'255', false, 'PRI'),
new ColumnDef('user_id', 'integer',
null, false, 'PRI'),
new ColumnDef('created', 'datetime',
null, false),
new ColumnDef('modified', 'timestamp')));
$schema->ensureTable('user_openid', User_openid::schemaDef());
$schema->ensureTable('user_openid_trustroot', User_openid_trustroot::schemaDef());
$schema->ensureTable('user_openid_prefs', User_openid_prefs::schemaDef());
/* These are used by JanRain OpenID library */

View File

@@ -22,41 +22,27 @@ class User_openid extends Managed_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
function table()
public static function schemaDef()
{
$db = $this->getDatabaseConnection();
$dbtype = $db->phptype; // Database type is stored here. Crazy but true.
return array('canonical' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'display' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
'modified' => ($dbtype == 'mysql' || $dbtype == 'mysqli') ?
DB_DATAOBJECT_MYSQLTIMESTAMP + DB_DATAOBJECT_NOTNULL :
DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME
);
}
/**
* List primary and unique keys in this table.
* Unique keys used for lookup *MUST* be listed to ensure proper caching.
*/
function keys()
{
return array_keys($this->keyTypes());
}
function keyTypes()
{
return array('canonical' => 'K', 'display' => 'U', 'user_id' => 'U');
}
/**
* No sequence keys in this table.
*/
function sequenceKey()
{
return array(false, false, false);
return array(
'fields' => array(
'canonical' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'OpenID canonical string'),
'display' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'OpenID display string'),
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'User ID for OpenID owner'),
'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('canonical'),
'unique keys' => array(
'user_openid_display_key' => array('display'),
),
'indexes' => array(
'user_openid_user_id_idx' => array('user_id'),
),
'foreign keys' => array(
'user_openid_user_id_fkey' => array('user', array('user_id' => 'id')),
),
);
}
static function hasOpenID($user_id)

View File

@@ -21,27 +21,16 @@ class User_openid_trustroot extends Managed_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
function table()
public static function schemaDef()
{
$db = $this->getDatabaseConnection();
$dbtype = $db->phptype; // Database type is stored here. Crazy but true.
return array('trustroot' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
'modified' => ($dbtype == 'mysql' || $dbtype == 'mysqli') ?
DB_DATAOBJECT_MYSQLTIMESTAMP + DB_DATAOBJECT_NOTNULL :
DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME
);
}
function keys()
{
return array_keys($this->keyTypes());
}
function keyTypes()
{
return array('trustroot' => 'K', 'user_id' => 'K');
return array(
'fields' => array(
'trustroot' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'OpenID trustroot string'),
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'User ID for OpenID trustroot owner'),
'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('trustroot', 'user_id'),
);
}
}