GitHost.io will be shut down on June 1, 2019. At that point this instance will be unreachable and all data will be irrevocably deleted. More details at https://about.gitlab.com/gitlab-hosted/#githost-is-shutting-down-on-june-1st-2019

Commit 3a7261f7 authored by mmn's avatar mmn

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...)
parent b1465a75
......@@ -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');
}
}
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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
*
......
......@@ -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;
}
......
......@@ -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()
{
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()
public static function schemaDef()
{
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'),
);
}
/**
......
......@@ -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()
{
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()
public static function schemaDef()
{
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'),
);
}
/**
......
......@@ -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;
}
......
......@@ -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()
{
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()
public static function schemaDef()
{
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')),
),
);
}
/**
......
......@@ -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;
}
......
......@@ -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)
......
......@@ -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)
......
......@@ -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()
{
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()
public static function schemaDef()
{
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)
......
......@@ -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()
......
......@@ -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());
}
......
......@@ -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