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

@ -19,6 +19,23 @@ class User_username extends Managed_DataObject
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
public static function schemaDef()
{
return array(
'fields' => array(
'provider_name' => array('type' => 'varchar', 'length' => 255, 'description' => 'provider name'),
'username' => array('type' => 'varchar', 'length' => 255, 'description' => 'username'),
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice id this title relates to'),
'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('provider_name', 'username'),
'foreign keys' => array(
'user_username_user_id_fkey' => array('user', array('user_id' => 'id')),
),
);
}
/**
* Register a user with a username on a given provider
* @param User User object
@ -40,18 +57,4 @@ class User_username extends Managed_DataObject
return false;
}
}
function table() {
return array(
'user_id' => DB_DATAOBJECT_INT,
'username' => DB_DATAOBJECT_STR,
'provider_name' => DB_DATAOBJECT_STR ,
'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME
);
}
// now define the keys.
function keys() {
return array('provider_name' => 'K', 'username' => 'K');
}
}

View File

@ -250,16 +250,7 @@ abstract class AuthenticationPlugin extends Plugin
function onCheckSchema() {
$schema = Schema::get();
$schema->ensureTable('user_username',
array(new ColumnDef('provider_name', 'varchar',
'255', false, 'PRI'),
new ColumnDef('username', 'varchar',
'255', false, 'PRI'),
new ColumnDef('user_id', 'integer',
null, false),
new ColumnDef('created', 'datetime',
null, false),
new ColumnDef('modified', 'timestamp')));
$schema->ensureTable('user_username', User_username::schemaDef());
return true;
}

View File

@ -80,22 +80,7 @@ class AnonymousFavePlugin extends Plugin
$schema = Schema::get();
// For storing total number of times a notice has been faved
$schema->ensureTable('fave_tally',
array(
new ColumnDef('notice_id', 'integer', null, false, 'PRI'),
new ColumnDef('count', 'integer', null, false),
new ColumnDef(
'modified',
'timestamp',
null,
false,
null,
'CURRENT_TIMESTAMP',
'on update CURRENT_TIMESTAMP'
)
)
);
$schema->ensureTable('fave_tally', Fave_tally::schemaDef());
return true;
}

View File

@ -52,72 +52,28 @@ class Fave_tally extends Managed_DataObject
public $__table = 'fave_tally'; // table name
public $notice_id; // int(4) primary_key not_null
public $count; // int(4) not_null
public $created; // datetime() not_null
public $modified; // datetime not_null default_0000-00-00%2000%3A00%3A00
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* return table definition for DB_DataObject
*
* @return array array of column definitions
*/
function table()
public static function schemaDef()
{
return array(
'notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'count' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL
'fields' => array(
'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice id'),
'count' => array('type' => 'int', 'not null' => true, 'description' => 'the fave tally count'),
'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'),
'foreign keys' => array(
'fave_tally_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
),
);
}
/**
* 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');
}
/**
* 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);
}
/**
* Increment a notice's tally
*

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'),
);
}
/**

View File

@ -55,19 +55,7 @@ class EmailSummaryPlugin extends Plugin
$schema = Schema::get();
// For storing user-submitted flags on profiles
$schema->ensureTable('email_summary_status',
array(new ColumnDef('user_id', 'integer', null,
false, 'PRI'),
new ColumnDef('send_summary', 'tinyint', null,
false, null, 1),
new ColumnDef('last_summary_id', 'integer', null,
true),
new ColumnDef('created', 'datetime', null,
false),
new ColumnDef('modified', 'datetime', null,
false),
)
);
$schema->ensureTable('email_summary_status', Email_summary_status::schemaDef());
return true;
}

View File

@ -55,58 +55,21 @@ class Email_summary_status extends Managed_DataObject
public $created; // datetime not_null
public $modified; // datetime not_null
/**
* 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('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'send_summary' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'last_summary_id' => DB_DATAOBJECT_INT,
'created' => DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
'modified' => DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
}
/**
* return key definitions for DB_DataObject
*
* @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('user_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(
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id'),
'send_summary' => array('type' => 'int', 'size' => 'tiny', 'default' => 1, 'not null' => true, 'description' => 'whether to send a summary or not'),
'last_summary_id' => array('type' => 'int', 'description' => 'last summary 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('user_id'),
'foreign keys' => array(
'email_summary_status_user_id_fkey' => array('user', array('user_id' => 'id')),
),
);
}
/**

View File

@ -114,11 +114,7 @@ class FollowEveryonePlugin extends Plugin
$schema = Schema::get();
// For storing user-submitted flags on profiles
$schema->ensureTable('user_followeveryone_prefs',
array(new ColumnDef('user_id', 'integer', null,
true, 'PRI'),
new ColumnDef('followeveryone', 'tinyint', null,
false, null, 1)));
$schema->ensureTable('user_followeveryone_prefs', User_followeveryone_prefs::schemaDef());
return true;
}

View File

@ -57,65 +57,23 @@ class User_followeveryone_prefs extends Managed_DataObject
public $__table = 'user_followeveryone_prefs'; // table name
public $user_id; // int(4) primary_key not_null
public $followeveryone; // tinyint(1)
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('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'followeveryone' => DB_DATAOBJECT_INT + DB_DATAOBJECT_BOOL);
}
/**
* 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('user_id' => '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(
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id'),
'followeveryone' => array('type' => 'int', 'default' => 1, 'size' => 'tiny', 'description' => 'whether to follow everyone'),
'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(
'user_followeveryone_prefs_user_id_fkey' => array('user', array('user_id' => 'id')),
),
);
}
static function followEveryone($user_id)

View File

@ -71,20 +71,8 @@ class GNUsocialPhotosPlugin extends Plugin
function onCheckSchema()
{
$schema = Schema::get();
$schema->ensureTable('GNUsocialPhoto',
array(new ColumnDef('id', 'int(11)', null, false, 'PRI', null, null, true),
new ColumnDef('notice_id', 'int(11)', null, false),
new ColumnDef('album_id', 'int(11)', null, false),
new ColumnDef('uri', 'varchar(512)', null, false),
new ColumnDef('thumb_uri', 'varchar(512)', null, false),
new ColumnDef('title', 'varchar(512)', null, false),
new ColumnDef('photo_description', 'text', null, false)));
$schema->ensureTable('GNUsocialPhotoAlbum',
array(new ColumnDef('album_id', 'int(11)', null, false, 'PRI', null, null, true),
new ColumnDef('profile_id', 'int(11)', null, false),
new ColumnDef('album_name', 'varchar(256)', null, false),
new ColumnDef('album_description', 'text', null, false)));
$schema->ensureTable('GNUsocialPhoto', GNUsocialPhoto::schemaDef());
$schema->ensureTable('GNUsocialPhotoAlbum', GNUsocialPhotoAlbum::schemaDef());
}
function onRouterInitialized($m)

View File

@ -38,10 +38,12 @@ class GNUsocialPhoto extends Managed_DataObject
public $id; // int(11)
public $notice_id; // int(11)
public $album_id; // int(11)
public $uri; // varchar(512)
public $thumb_uri; // varchar(512)
public $title; // varchar(512)
public $uri; // varchar(255)
public $thumb_uri; // varchar(255)
public $title; // varchar(255)
public $photo_description; // text
public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* function delete()
{
@ -54,34 +56,32 @@ class GNUsocialPhoto extends Managed_DataObject
return parent::delete();
} */
/*
* TODO: Foriegn key on album_id.
*/
function table()
public static function schemaDef()
{
return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'album_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'thumb_uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'title' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'photo_description' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
}
function keys()
{
return array_keys($this->keyTypes());
}
function keyTypes()
{
return array('notice_id' => 'K');
}
function sequenceKey()
{
return array(false, false, false);
return array(
'fields' => array(
'id' => array('type' => 'int', 'not null' => true, 'description' => 'Unique ID for Photo'),
'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'Notice ID for the related notice'),
'album_id' => array('type' => 'int', 'not null' => true, 'description' => 'The parent album ID'),
'uri' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'unique address for this photo'),
'thumb_uri' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'unique address for this photo thumbnail'),
'title' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'The Photo title'),
'photo_description' => array('type' => 'text', 'not null' => true, 'description' => 'A description for this photo'),
'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(
'gnusocialphoto_uri' => array('uri'),
),
'foreign keys' => array(
'gnusocialphoto_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
'gnusocialphoto_album_id_fkey' => array('GNUsocialPhotoAlbum', array('album_id' => 'id')),
),
'indexes' => array(
'gnusocialphoto_title_idx' => array('title'),
),
);
}
function saveNew($profile_id, $album_id, $thumb_uri, $uri, $source, $insert_now, $title = null, $photo_description = null)

View File

@ -38,33 +38,31 @@ class GNUsocialPhotoAlbum extends Managed_DataObject
public $__table = 'GNUsocialPhotoAlbum';
public $album_id; // int(11) -- Unique identifier for the album
public $profile_id; // int(11) -- Profile ID for the owner of the album
public $album_name; // varchar(256) -- Title for this album
public $album_name; // varchar(255) -- Title for this album
public $album_description; // text -- A description of the album
public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* TODO: Primary key on both album_id, profile_id / foriegn key on profile_id */
function table()
public static function schemaDef()
{
return array('album_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'profile_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'album_name' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'album_description' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
}
function keys()
{
return array_keys($this->keyTypes());
}
/* Using album_id as the primary key for now.. */
function keyTypes()
{
return array('album_id' => 'K');
}
function sequenceKey()
{
return array('album_id', true, false);
return array(
'fields' => array(
'album_id' => array('type' => 'int', 'not null' => true, 'description' => 'Unique identifier for the album'),
'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'Profile ID for the owner of the album'),
'album_name' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'Title for this album'),
'album_description' => array('type' => 'text', 'not null' => true, 'description' => 'A description for this album'),
'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(
'gnusocialphotoalbum_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
),
'indexes' => array(
'gnusocialphotoalbum_album_name_idx' => array('album_name'),
),
);
}
function getPageLink()

View File

@ -59,17 +59,8 @@ class GNUsocialProfileExtensionsPlugin extends Plugin
function onCheckSchema()
{
$schema = Schema::get();
$schema->ensureTable('GNUsocialProfileExtensionField',
array(new ColumnDef('id', 'int(11)', null, false, 'PRI', null, null, true),
new ColumnDef('systemname', 'varchar(64)', null, false),
new ColumnDef('title', 'varchar(256)', null, false),
new ColumnDef('description', 'text', null, false),
new ColumnDef('type', 'varchar(256)', null, false)));
$schema->ensureTable('GNUsocialProfileExtensionResponse',
array(new ColumnDef('id', 'int(11)', null, false, 'PRI', null, null, true),
new ColumnDef('extension_id', 'int(11)', null, false),
new ColumnDef('profile_id', 'int(11)', null, false),
new ColumnDef('value', 'text', null, false)));
$schema->ensureTable('GNUsocialProfileExtensionField', GNUsocialProfileExtensionField::schemaDef());
$schema->ensureTable('GNUsocialProfileExtensionResponse', GNUsocialProfileExtensionResponse::schemaDef());
}

View File

@ -37,22 +37,29 @@ class GNUsocialProfileExtensionField extends Managed_DataObject
public $__table = 'GNUsocialProfileExtensionField';
public $id; // int(11)
public $systemname; // varchar(64)
public $title; // varchar(256)
public $title; // varchar(255)
public $description; // text
public $type; // varchar(256)
public $type; // varchar(255)
public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
function table()
public static function schemaDef()
{
return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'systemname' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'title' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'description' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'type' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
}
function keys()
{
return array_keys($this->keyTypes());
return array(
'fields' => array(
'id' => array('type' => 'int', 'not null' => true, 'description' => 'Unique ID for extension field'),
'systemname' => array('type' => 'varchar', 'not null' => true, 'length' => 64, 'description' => 'field systemname'),
'title' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'field title'),
'description' => array('type' => 'text', 'not null' => true, 'description' => 'field description'),
'type' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'field type'),
'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'),
'indexes' => array(
'gnusocialprofileextensionfield_title_idx' => array('title'),
),
);
}
function keyTypes()

View File

@ -39,28 +39,29 @@ class GNUsocialProfileExtensionResponse extends Managed_DataObject
public $extension_id; // int(11)
public $profile_id; // int(11)
public $value; // text
public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
function table()
public static function schemaDef()
{
return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'extension_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'profile_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'value' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL);
}
function keys()
{
return array_keys($this->keyTypes());
}
function keyTypes()
{
return array('id' => 'K');
}
function sequenceKey()
{
return array(false, false, false);
return array(
'fields' => array(
'id' => array('type' => 'int', 'not null' => true, 'description' => 'Unique ID for extension response'),
'extension_id' => array('type' => 'int', 'not null' => true, 'description' => 'The extension field ID'),
'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'Profile id that made the response'),
'value' => array('type' => 'text', 'not null' => true, 'description' => 'response entry'),
'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'),
'foreign keys' => array(
'gnusocialprofileextensionresponse_profile_id_fkey' => array('profile', array('profile_id' => 'id')),
'gnusocialprofileextensionresponse_extension_id_fkey' => array('GNUsocialProfileExtensionField', array('extension_id' => 'id')),
),
'indexes' => array(
'gnusocialprofileextensionresponse_extension_id_idx' => array('extension_id'),
),
);
}
static function newResponse($extension_id, $profile_id, $value)

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)

View File

@ -160,15 +160,7 @@ class IrcPlugin extends ImPlugin {
$schema = Schema::get();
// For storing messages while sessions become ready
$schema->ensureTable('irc_waiting_message',
array(new ColumnDef('id', 'integer', null,
false, 'PRI', null, null, true),
new ColumnDef('data', 'blob', null, false),
new ColumnDef('prioritise', 'tinyint', 1, false),
new ColumnDef('attempts', 'integer', null, false),
new ColumnDef('created', 'datetime', null, false),
new ColumnDef('claimed', 'datetime')));
$schema->ensureTable('irc_waiting_message', Irc_waiting_message::schemaDef());
return true;
}

View File

@ -12,66 +12,27 @@ class Irc_waiting_message extends Managed_DataObject {
public $data; // blob not_null
public $prioritise; // tinyint(1) not_null
public $attempts; // int not_null
public $created; // datetime() not_null
public $claimed; // datetime()
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
*/
public function table() {
return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'data' => DB_DATAOBJECT_BLOB + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'prioritise' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'created' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'claimed' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR);
}
/**
* 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
*/
public 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.
*/
public function keyTypes() {
return array('id' => '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.
*/
public function sequenceKey() {
return array(false, false, false);
public static function schemaDef()
{
return array(
'fields' => array(
'id' => array('type' => 'int', 'not null' => true, 'description' => 'Unique ID for entry'),
'data' => array('type' => 'blob', 'not null' => true, 'description' => 'data blob'),
'prioritise' => array('type' => 'int', 'size' => 'tiny', 'description' => 'tinyint priority value'),
'attempts' => array('type' => 'int', 'not null' => true, 'description' => 'attempts count'),
'claimed' => array('type' => 'datetime', 'description' => 'date this irc message was claimed'),
'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'),
'indexes' => array(
'irc_waiting_message_prioritise_idx' => array('prioritise'),
),
);
}
/**

View File

@ -133,14 +133,7 @@ class MsnPlugin extends ImPlugin {
$schema = Schema::get();
// For storing messages while sessions become ready
$schema->ensureTable('msn_waiting_message',
array(new ColumnDef('id', 'integer', null,
false, 'PRI', null, null, true),
new ColumnDef('screenname', 'varchar', 255, false),
new ColumnDef('message', 'text', null, false),
new ColumnDef('created', 'datetime', null, false),
new ColumnDef('claimed', 'datetime')));
$schema->ensureTable('msn_waiting_message', Msn_waiting_message::schemaGet());
return true;
}

View File

@ -10,66 +10,26 @@ class Msn_waiting_message extends Managed_DataObject {
public $id; // int primary_key not_null auto_increment
public $screenname; // varchar(255) not_null
public $message; // text not_null
public $created; // datetime() not_null
public $claimed; // datetime()
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
*/
public function table() {
return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'screenname' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'message' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'created' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL,
'claimed' => DB_DATAOBJECT_TIME + DB_DATAOBJECT_STR);
}
/**
* 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
*/
public 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.
*/
public function keyTypes() {
return array('id' => '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);
public static function schemaDef()
{
return array(
'fields' => array(
'id' => array('type' => 'int', 'not null' => true, 'description' => 'Unique ID for entry'),
'screenname' => array('type' => 'varchar', 'length' => 255, 'description' => 'from screenname'),
'message' => array('type' => 'text', 'not null' => true, 'description' => 'MSN message text'),
'claimed' => array('type' => 'datetime', 'description' => 'date this irc message was claimed'),
'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'),
'indexes' => array(
'msn_waiting_message_prioritise_idx' => array('screenname'),
),
);
}
/**

View File

@ -71,18 +71,7 @@ class NoticeTitlePlugin extends Plugin
$schema = Schema::get();
// For storing titles for notices
$schema->ensureTable('notice_title',
array(new ColumnDef('notice_id',
'integer',
null,
true,
'PRI'),
new ColumnDef('title',
'varchar',
Notice_title::MAXCHARS,
false)));
$schema->ensureTable('notice_title', Notice_title::schemaDef());
return true;
}

View File

@ -49,51 +49,25 @@ class Notice_title extends Managed_DataObject
const MAXCHARS = 255;
public $__table = 'notice_title'; // table name
public $notice_id; // int(4) primary_key not_null
public $notice_id; // int(11) primary_key not_null
public $title; // varchar(255)
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('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'title' => DB_DATAOBJECT_STR);
}
/**
* return key definitions for DB_DataObject
*
* @return array list of key field names
*/
function keys()
{
return array_keys($this->keyTypes());
}
/**
* return key definitions for Memcached_DataObject
*
* @return array list mapping field names to key types
*/
function keyTypes()
{
return array('notice_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(
'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice id this title relates to'),
'title' => array('type' => 'varchar', 'length' => Notice_title::MAXCHARS, 'description' => 'title to notice'),
'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'),
'foreign keys' => array(
'notice_title_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
),
);
}
/**

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'),
);
}
}

View File

@ -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;
}

View File

@ -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'),
),
);
}
/**

View File

@ -170,23 +170,7 @@ class SamplePlugin extends Plugin
$schema = Schema::get();
// For storing user-submitted flags on profiles
$schema->ensureTable('user_greeting_count',
array(
'fields' => array(
'user_id' => array('type' => 'int', 'not null' => true),
'greeting_count' => array('type' => 'int'),
),
'primary key' => array('user_id'),
'foreign keys' => array(
// Not all databases will support foreign keys, but even
// when not enforced it's helpful to include these definitions
// as documentation.
'user_greeting_count_user_id_fkey' => array('user', array('user_id' => 'id')),
),
)
);
$schema->ensureTable('user_greeting_count', User_greeting_count::schemaDef());
return true;
}

View File

@ -57,65 +57,23 @@ class User_greeting_count extends Managed_DataObject
public $__table = 'user_greeting_count'; // table name
public $user_id; // int(4) primary_key not_null
public $greeting_count; // int(4)
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('user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'greeting_count' => DB_DATAOBJECT_INT);
}
/**
* 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('user_id' => '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(
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id'),
'greeting_count' => array('type' => 'int', 'not null' => true, 'description' => 'the greeting count'),
'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(
'user_greeting_count_user_id_fkey' => array('user', array('user_id' => 'id')),
),
);
}
/**

View File

@ -180,22 +180,8 @@ class SitemapPlugin extends Plugin
{
$schema = Schema::get();
$schema->ensureTable('sitemap_user_count',
array(new ColumnDef('registration_date', 'date', null,
true, 'PRI'),
new ColumnDef('user_count', 'integer'),
new ColumnDef('created', 'datetime',
null, false),
new ColumnDef('modified', 'timestamp')));
$schema->ensureTable('sitemap_notice_count',
array(new ColumnDef('notice_date', 'date', null,
true, 'PRI'),
new ColumnDef('notice_count', 'integer'),
new ColumnDef('created', 'datetime',
null, false),
new ColumnDef('modified', 'timestamp')));
$schema->ensureTable('sitemap_user_count', Sitemap_user_count::schemaDef());
$schema->ensureTable('sitemap_notice_count', Sitemap_notice_count::schemaDef());
return true;
}

View File

@ -57,49 +57,20 @@ class Sitemap_notice_count extends Managed_DataObject
public $notice_date; // date primary_key not_null
public $notice_count; // int(4)
public $created;
public $modified;
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_date' => DB_DATAOBJECT_DATE + DB_DATAOBJECT_NOTNULL,
'notice_count' => 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; this function
* defines them.
*
* @return array key definitions
*/
function keys()
{
return array('notice_date' => '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();
return array(
'fields' => array(
'notice_date' => array('type' => 'date', 'not null' => true, 'description' => 'record date'),
'notice_count' => array('type' => 'int', 'not null' => true, 'description' => 'the notice count'),
'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_date'),
);
}
static function getAll()

View File

@ -53,55 +53,20 @@ class Sitemap_user_count extends Managed_DataObject
public $registration_date; // date primary_key not_null
public $user_count; // int(4)
public $created;
public $modified;
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('registration_date' => DB_DATAOBJECT_DATE + DB_DATAOBJECT_NOTNULL,
'user_count' => 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; this function
* defines them.
*
* @return array key definitions
*/
function keys()
{
return array('registration_date' => 'K');
}
function sequenceKey()
{
return array(false, false, false);
}
/**
* 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();
return array(
'fields' => array(
'registration_date' => array('type' => 'date', 'not null' => true, 'description' => 'record date'),
'user_count' => array('type' => 'int', 'not null' => true, 'description' => 'the user count of the recorded date'),
'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('registration_date'),
);
}
static function getAll()

View File

@ -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')),
),
);
}
/**

View File

@ -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;
}

View File

@ -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)

View File

@ -60,17 +60,7 @@ class UserFlagPlugin extends Plugin
$schema = Schema::get();
// For storing user-submitted flags on profiles
$schema->ensureTable('user_flag_profile',
array(new ColumnDef('profile_id', 'integer', null,
false, 'PRI'),
new ColumnDef('user_id', 'integer', null,
false, 'PRI'),
new ColumnDef('created', 'datetime', null,
false, 'MUL'),
new ColumnDef('cleared', 'datetime', null,
true, 'MUL')));
$schema->ensureTable('user_flag_profile', User_flag_profile::schemaDef());
return true;
}

View File

@ -50,62 +50,31 @@ class User_flag_profile extends Managed_DataObject
/* the code below is auto generated do not remove the above tag */
public $__table = 'user_flag_profile'; // table name
public $profile_id; // int(4) primary_key not_null
public $user_id; // int(4) primary_key not_null
public $created; // datetime not_null default_0000-00-00%2000%3A00%3A00
public $cleared; // datetime not_null default_0000-00-00%2000%3A00%3A00
public $profile_id; // int(11) primary_key not_null
public $user_id; // int(11) primary_key not_null
public $cleared; // datetime default_0000-00-00%2000%3A00%3A00
public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* the code above is auto generated do not remove the tag below */
###END_AUTOCODE
/**
* return table definition for DB_DataObject
*
* @return array array of column definitions
*/
function table()
public static function schemaDef()
{
return array(
'profile_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'user_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
'cleared' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME
);
}
/**
* return key definitions for DB_DataObject
*
* @return array of key names
*/
function keys()
{
return array_keys($this->keyTypes());
}
/**
* return key definitions for DB_DataObject
*
* @return array map of key definitions
*/
function keyTypes()
{
return array('profile_id' => 'K', 'user_id' => '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);
'fields' => array(
'profile_id' => array('type' => 'int', 'not null' => true, 'description' => 'profile id flagged'),
'user_id' => array('type' => 'int', 'not null' => true, 'description' => 'user id of the actor'),
'cleared' => array('type' => 'datetime', 'description' => 'when flag was removed'),
'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('profile_id', 'user_id'),
'indexes' => array(
'user_flag_profile_cleared_idx' => array('cleared'),
'user_flag_profile_created_idx' => array('created'),
),
);
}
/**