From 3a7261f70a62e28f47b45847c8ab31ff6f441a61 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Mon, 19 Aug 2013 17:08:18 +0200 Subject: [PATCH] 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...) --- classes/User_username.php | 31 ++++---- lib/authenticationplugin.php | 11 +-- plugins/AnonymousFave/AnonymousFavePlugin.php | 17 +--- plugins/AnonymousFave/Fave_tally.php | 68 +++------------- plugins/Blacklist/BlacklistPlugin.php | 23 +----- plugins/Blacklist/Homepage_blacklist.php | 51 +++--------- plugins/Blacklist/Nickname_blacklist.php | 42 +++------- plugins/EmailSummary/EmailSummaryPlugin.php | 14 +--- plugins/EmailSummary/Email_summary_status.php | 65 ++++----------- .../FollowEveryone/FollowEveryonePlugin.php | 6 +- .../User_followeveryone_prefs.php | 72 ++++------------- .../GNUsocialPhotos/GNUsocialPhotosPlugin.php | 16 +--- .../classes/gnusocialphoto.php | 60 +++++++------- .../classes/gnusocialphotoalbum.php | 44 +++++------ .../GNUsocialProfileExtensionsPlugin.php | 13 +-- .../GNUsocialProfileExtensionField.php | 33 +++++--- .../GNUsocialProfileExtensionResponse.php | 41 +++++----- .../GroupPrivateMessagePlugin.php | 66 +--------------- plugins/GroupPrivateMessage/Group_message.php | 75 +++++++----------- .../Group_message_profile.php | 65 ++++----------- .../Group_privacy_settings.php | 65 ++++----------- plugins/Irc/IrcPlugin.php | 10 +-- plugins/Irc/Irc_waiting_message.php | 77 +++++------------- plugins/Msn/MsnPlugin.php | 9 +-- plugins/Msn/msn_waiting_message.php | 76 +++++------------- plugins/NoticeTitle/NoticeTitlePlugin.php | 13 +-- plugins/NoticeTitle/Notice_title.php | 58 ++++---------- plugins/OpenID/OpenIDPlugin.php | 21 +---- plugins/OpenID/User_openid.php | 54 +++++-------- plugins/OpenID/User_openid_trustroot.php | 31 +++----- .../RegisterThrottlePlugin.php | 7 +- plugins/RegisterThrottle/Registration_ip.php | 70 +++++----------- plugins/Sample/SamplePlugin.php | 18 +---- plugins/Sample/User_greeting_count.php | 72 ++++------------- plugins/Sitemap/SitemapPlugin.php | 18 +---- plugins/Sitemap/Sitemap_notice_count.php | 53 +++---------- plugins/Sitemap/Sitemap_user_count.php | 59 +++----------- plugins/TwitterBridge/Notice_to_status.php | 79 +++++-------------- plugins/TwitterBridge/TwitterBridgePlugin.php | 22 +----- .../TwitterBridge/Twitter_synch_status.php | 79 ++++--------------- plugins/UserFlag/UserFlagPlugin.php | 12 +-- plugins/UserFlag/User_flag_profile.php | 69 +++++----------- 42 files changed, 453 insertions(+), 1332 deletions(-) diff --git a/classes/User_username.php b/classes/User_username.php index 31dc66faea..5f0ef63185 100644 --- a/classes/User_username.php +++ b/classes/User_username.php @@ -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'); - } } diff --git a/lib/authenticationplugin.php b/lib/authenticationplugin.php index ad031e7852..bf5f3aafe3 100644 --- a/lib/authenticationplugin.php +++ b/lib/authenticationplugin.php @@ -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; } diff --git a/plugins/AnonymousFave/AnonymousFavePlugin.php b/plugins/AnonymousFave/AnonymousFavePlugin.php index c3f810d6ee..e0b2a17d1f 100644 --- a/plugins/AnonymousFave/AnonymousFavePlugin.php +++ b/plugins/AnonymousFave/AnonymousFavePlugin.php @@ -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; } diff --git a/plugins/AnonymousFave/Fave_tally.php b/plugins/AnonymousFave/Fave_tally.php index eb23a7cb0a..c9fe181b6d 100644 --- a/plugins/AnonymousFave/Fave_tally.php +++ b/plugins/AnonymousFave/Fave_tally.php @@ -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 * diff --git a/plugins/Blacklist/BlacklistPlugin.php b/plugins/Blacklist/BlacklistPlugin.php index e0d2a04dd8..5f31be63d4 100644 --- a/plugins/Blacklist/BlacklistPlugin.php +++ b/plugins/Blacklist/BlacklistPlugin.php @@ -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; } diff --git a/plugins/Blacklist/Homepage_blacklist.php b/plugins/Blacklist/Homepage_blacklist.php index 440084702c..fb2712f565 100644 --- a/plugins/Blacklist/Homepage_blacklist.php +++ b/plugins/Blacklist/Homepage_blacklist.php @@ -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'), + ); } /** diff --git a/plugins/Blacklist/Nickname_blacklist.php b/plugins/Blacklist/Nickname_blacklist.php index bf1d1e5ab7..f4f387a2e0 100644 --- a/plugins/Blacklist/Nickname_blacklist.php +++ b/plugins/Blacklist/Nickname_blacklist.php @@ -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'), + ); } /** diff --git a/plugins/EmailSummary/EmailSummaryPlugin.php b/plugins/EmailSummary/EmailSummaryPlugin.php index 15cc0b5bd8..f99a10bc02 100644 --- a/plugins/EmailSummary/EmailSummaryPlugin.php +++ b/plugins/EmailSummary/EmailSummaryPlugin.php @@ -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; } diff --git a/plugins/EmailSummary/Email_summary_status.php b/plugins/EmailSummary/Email_summary_status.php index de9e491fa6..460053f9f8 100644 --- a/plugins/EmailSummary/Email_summary_status.php +++ b/plugins/EmailSummary/Email_summary_status.php @@ -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')), + ), + ); } /** diff --git a/plugins/FollowEveryone/FollowEveryonePlugin.php b/plugins/FollowEveryone/FollowEveryonePlugin.php index 98f61c3a99..0bea8d9aa4 100644 --- a/plugins/FollowEveryone/FollowEveryonePlugin.php +++ b/plugins/FollowEveryone/FollowEveryonePlugin.php @@ -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; } diff --git a/plugins/FollowEveryone/User_followeveryone_prefs.php b/plugins/FollowEveryone/User_followeveryone_prefs.php index 79e3bfa130..c1a654df92 100644 --- a/plugins/FollowEveryone/User_followeveryone_prefs.php +++ b/plugins/FollowEveryone/User_followeveryone_prefs.php @@ -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) diff --git a/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php b/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php index f187a22a77..3a7e882236 100644 --- a/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php +++ b/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php @@ -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) diff --git a/plugins/GNUsocialPhotos/classes/gnusocialphoto.php b/plugins/GNUsocialPhotos/classes/gnusocialphoto.php index 3898d42994..6e9daac2ed 100644 --- a/plugins/GNUsocialPhotos/classes/gnusocialphoto.php +++ b/plugins/GNUsocialPhotos/classes/gnusocialphoto.php @@ -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) diff --git a/plugins/GNUsocialPhotos/classes/gnusocialphotoalbum.php b/plugins/GNUsocialPhotos/classes/gnusocialphotoalbum.php index 722a8f69ae..208c341851 100644 --- a/plugins/GNUsocialPhotos/classes/gnusocialphotoalbum.php +++ b/plugins/GNUsocialPhotos/classes/gnusocialphotoalbum.php @@ -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() diff --git a/plugins/GNUsocialProfileExtensions/GNUsocialProfileExtensionsPlugin.php b/plugins/GNUsocialProfileExtensions/GNUsocialProfileExtensionsPlugin.php index cf5fb0a067..e6c961f865 100644 --- a/plugins/GNUsocialProfileExtensions/GNUsocialProfileExtensionsPlugin.php +++ b/plugins/GNUsocialProfileExtensions/GNUsocialProfileExtensionsPlugin.php @@ -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()); } diff --git a/plugins/GNUsocialProfileExtensions/classes/GNUsocialProfileExtensionField.php b/plugins/GNUsocialProfileExtensions/classes/GNUsocialProfileExtensionField.php index f8568c26e4..9574863c58 100644 --- a/plugins/GNUsocialProfileExtensions/classes/GNUsocialProfileExtensionField.php +++ b/plugins/GNUsocialProfileExtensions/classes/GNUsocialProfileExtensionField.php @@ -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() diff --git a/plugins/GNUsocialProfileExtensions/classes/GNUsocialProfileExtensionResponse.php b/plugins/GNUsocialProfileExtensions/classes/GNUsocialProfileExtensionResponse.php index de87447e81..4163d4d077 100644 --- a/plugins/GNUsocialProfileExtensions/classes/GNUsocialProfileExtensionResponse.php +++ b/plugins/GNUsocialProfileExtensions/classes/GNUsocialProfileExtensionResponse.php @@ -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) diff --git a/plugins/GroupPrivateMessage/GroupPrivateMessagePlugin.php b/plugins/GroupPrivateMessage/GroupPrivateMessagePlugin.php index 468e0eb92e..467f384f4d 100644 --- a/plugins/GroupPrivateMessage/GroupPrivateMessagePlugin.php +++ b/plugins/GroupPrivateMessage/GroupPrivateMessagePlugin.php @@ -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; } diff --git a/plugins/GroupPrivateMessage/Group_message.php b/plugins/GroupPrivateMessage/Group_message.php index 05fcdc5c43..30b98adecd 100644 --- a/plugins/GroupPrivateMessage/Group_message.php +++ b/plugins/GroupPrivateMessage/Group_message.php @@ -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) diff --git a/plugins/GroupPrivateMessage/Group_message_profile.php b/plugins/GroupPrivateMessage/Group_message_profile.php index 845997f21f..5f16dc2eab 100644 --- a/plugins/GroupPrivateMessage/Group_message_profile.php +++ b/plugins/GroupPrivateMessage/Group_message_profile.php @@ -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) diff --git a/plugins/GroupPrivateMessage/Group_privacy_settings.php b/plugins/GroupPrivateMessage/Group_privacy_settings.php index 771c2ec782..9e983ba323 100644 --- a/plugins/GroupPrivateMessage/Group_privacy_settings.php +++ b/plugins/GroupPrivateMessage/Group_privacy_settings.php @@ -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) diff --git a/plugins/Irc/IrcPlugin.php b/plugins/Irc/IrcPlugin.php index f74324c186..aeefded4b0 100644 --- a/plugins/Irc/IrcPlugin.php +++ b/plugins/Irc/IrcPlugin.php @@ -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; } diff --git a/plugins/Irc/Irc_waiting_message.php b/plugins/Irc/Irc_waiting_message.php index ba8d6bd03d..df7db05b58 100644 --- a/plugins/Irc/Irc_waiting_message.php +++ b/plugins/Irc/Irc_waiting_message.php @@ -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'), + ), + ); } /** diff --git a/plugins/Msn/MsnPlugin.php b/plugins/Msn/MsnPlugin.php index fdef94ce55..38602668b9 100644 --- a/plugins/Msn/MsnPlugin.php +++ b/plugins/Msn/MsnPlugin.php @@ -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; } diff --git a/plugins/Msn/msn_waiting_message.php b/plugins/Msn/msn_waiting_message.php index 03c03f856e..770b1c7df3 100644 --- a/plugins/Msn/msn_waiting_message.php +++ b/plugins/Msn/msn_waiting_message.php @@ -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'), + ), + ); } /** diff --git a/plugins/NoticeTitle/NoticeTitlePlugin.php b/plugins/NoticeTitle/NoticeTitlePlugin.php index b2efe8345b..d73da51d58 100644 --- a/plugins/NoticeTitle/NoticeTitlePlugin.php +++ b/plugins/NoticeTitle/NoticeTitlePlugin.php @@ -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; } diff --git a/plugins/NoticeTitle/Notice_title.php b/plugins/NoticeTitle/Notice_title.php index fff59c43a1..610e32fca7 100644 --- a/plugins/NoticeTitle/Notice_title.php +++ b/plugins/NoticeTitle/Notice_title.php @@ -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')), + ), + ); } /** diff --git a/plugins/OpenID/OpenIDPlugin.php b/plugins/OpenID/OpenIDPlugin.php index 3dfcf6c68a..f233118739 100644 --- a/plugins/OpenID/OpenIDPlugin.php +++ b/plugins/OpenID/OpenIDPlugin.php @@ -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 */ diff --git a/plugins/OpenID/User_openid.php b/plugins/OpenID/User_openid.php index a8ed576114..baff5cd7f9 100644 --- a/plugins/OpenID/User_openid.php +++ b/plugins/OpenID/User_openid.php @@ -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) diff --git a/plugins/OpenID/User_openid_trustroot.php b/plugins/OpenID/User_openid_trustroot.php index 04d06c78f6..ec09e179e4 100644 --- a/plugins/OpenID/User_openid_trustroot.php +++ b/plugins/OpenID/User_openid_trustroot.php @@ -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'), + ); } } diff --git a/plugins/RegisterThrottle/RegisterThrottlePlugin.php b/plugins/RegisterThrottle/RegisterThrottlePlugin.php index 93d990ca77..d6ab7fc0f4 100644 --- a/plugins/RegisterThrottle/RegisterThrottlePlugin.php +++ b/plugins/RegisterThrottle/RegisterThrottlePlugin.php @@ -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; } diff --git a/plugins/RegisterThrottle/Registration_ip.php b/plugins/RegisterThrottle/Registration_ip.php index 02b137f987..431b6c0562 100644 --- a/plugins/RegisterThrottle/Registration_ip.php +++ b/plugins/RegisterThrottle/Registration_ip.php @@ -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'), + ), + ); } /** diff --git a/plugins/Sample/SamplePlugin.php b/plugins/Sample/SamplePlugin.php index 5c34d10bd1..f2d333bbcb 100644 --- a/plugins/Sample/SamplePlugin.php +++ b/plugins/Sample/SamplePlugin.php @@ -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; } diff --git a/plugins/Sample/User_greeting_count.php b/plugins/Sample/User_greeting_count.php index 415f710440..3da00b2d1a 100644 --- a/plugins/Sample/User_greeting_count.php +++ b/plugins/Sample/User_greeting_count.php @@ -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')), + ), + ); } /** diff --git a/plugins/Sitemap/SitemapPlugin.php b/plugins/Sitemap/SitemapPlugin.php index 29b822acd5..ae90134db9 100644 --- a/plugins/Sitemap/SitemapPlugin.php +++ b/plugins/Sitemap/SitemapPlugin.php @@ -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; } diff --git a/plugins/Sitemap/Sitemap_notice_count.php b/plugins/Sitemap/Sitemap_notice_count.php index 46ae65c838..9e523dfbc7 100644 --- a/plugins/Sitemap/Sitemap_notice_count.php +++ b/plugins/Sitemap/Sitemap_notice_count.php @@ -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() diff --git a/plugins/Sitemap/Sitemap_user_count.php b/plugins/Sitemap/Sitemap_user_count.php index c085e4de9e..865cf246e7 100644 --- a/plugins/Sitemap/Sitemap_user_count.php +++ b/plugins/Sitemap/Sitemap_user_count.php @@ -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() diff --git a/plugins/TwitterBridge/Notice_to_status.php b/plugins/TwitterBridge/Notice_to_status.php index 80656ad833..6f75e3c7da 100644 --- a/plugins/TwitterBridge/Notice_to_status.php +++ b/plugins/TwitterBridge/Notice_to_status.php @@ -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')), + ), + ); } /** diff --git a/plugins/TwitterBridge/TwitterBridgePlugin.php b/plugins/TwitterBridge/TwitterBridgePlugin.php index 6dc8ae8b76..1e0f328ad9 100644 --- a/plugins/TwitterBridge/TwitterBridgePlugin.php +++ b/plugins/TwitterBridge/TwitterBridgePlugin.php @@ -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; } diff --git a/plugins/TwitterBridge/Twitter_synch_status.php b/plugins/TwitterBridge/Twitter_synch_status.php index 6f5147cb69..9a20536147 100644 --- a/plugins/TwitterBridge/Twitter_synch_status.php +++ b/plugins/TwitterBridge/Twitter_synch_status.php @@ -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) diff --git a/plugins/UserFlag/UserFlagPlugin.php b/plugins/UserFlag/UserFlagPlugin.php index 42a8948dff..1d8cccd54d 100644 --- a/plugins/UserFlag/UserFlagPlugin.php +++ b/plugins/UserFlag/UserFlagPlugin.php @@ -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; } diff --git a/plugins/UserFlag/User_flag_profile.php b/plugins/UserFlag/User_flag_profile.php index cd641fc53c..d0cdedccb3 100644 --- a/plugins/UserFlag/User_flag_profile.php +++ b/plugins/UserFlag/User_flag_profile.php @@ -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'), + ), + ); } /**