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 ...@@ -19,6 +19,23 @@ class User_username extends Managed_DataObject
/* the code above is auto generated do not remove the tag below */ /* the code above is auto generated do not remove the tag below */
###END_AUTOCODE ###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 * Register a user with a username on a given provider
* @param User User object * @param User User object
...@@ -40,18 +57,4 @@ class User_username extends Managed_DataObject ...@@ -40,18 +57,4 @@ class User_username extends Managed_DataObject
return false; 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 ...@@ -250,16 +250,7 @@ abstract class AuthenticationPlugin extends Plugin
function onCheckSchema() { function onCheckSchema() {
$schema = Schema::get(); $schema = Schema::get();
$schema->ensureTable('user_username', $schema->ensureTable('user_username', User_username::schemaDef());
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')));
return true; return true;
} }
......
...@@ -80,22 +80,7 @@ class AnonymousFavePlugin extends Plugin ...@@ -80,22 +80,7 @@ class AnonymousFavePlugin extends Plugin
$schema = Schema::get(); $schema = Schema::get();
// For storing total number of times a notice has been faved // For storing total number of times a notice has been faved
$schema->ensureTable('fave_tally', Fave_tally::schemaDef());
$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'
)
)
);
return true; return true;
} }
......
...@@ -52,72 +52,28 @@ class Fave_tally extends Managed_DataObject ...@@ -52,72 +52,28 @@ class Fave_tally extends Managed_DataObject
public $__table = 'fave_tally'; // table name public $__table = 'fave_tally'; // table name
public $notice_id; // int(4) primary_key not_null public $notice_id; // int(4) primary_key not_null
public $count; // int(4) 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 public $modified; // datetime not_null default_0000-00-00%2000%3A00%3A00
/* the code above is auto generated do not remove the tag below */ /* the code above is auto generated do not remove the tag below */
###END_AUTOCODE ###END_AUTOCODE
/** public static function schemaDef()
* return table definition for DB_DataObject
*
* @return array array of column definitions
*/
function table()
{ {
return array( return array(
'notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL, 'fields' => array(
'count' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL, 'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'notice id'),
'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL '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 * Increment a notice's tally
* *
......
...@@ -80,27 +80,8 @@ class BlacklistPlugin extends Plugin ...@@ -80,27 +80,8 @@ class BlacklistPlugin extends Plugin
$schema = Schema::get(); $schema = Schema::get();
// For storing blacklist patterns for nicknames // For storing blacklist patterns for nicknames
$schema->ensureTable('nickname_blacklist', $schema->ensureTable('nickname_blacklist', Nickname_blacklist::schemaDef());
array(new ColumnDef('pattern', $schema->ensureTable('homepage_blacklist', Homepage_blacklist::schemaDef());
'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)));
return true; return true;
} }
......
...@@ -47,47 +47,20 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php'; ...@@ -47,47 +47,20 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
class Homepage_blacklist extends Managed_DataObject class Homepage_blacklist extends Managed_DataObject
{ {
public $__table = 'homepage_blacklist'; // table name public $__table = 'homepage_blacklist'; // table name
public $pattern; // string pattern public $pattern; // varchar(255) pattern
public $created; // datetime public $created; // datetime not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/** public static function schemaDef()
* 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()
{ {
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'; ...@@ -47,38 +47,20 @@ require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
class Nickname_blacklist extends Managed_DataObject class Nickname_blacklist extends Managed_DataObject
{ {
public $__table = 'nickname_blacklist'; // table name public $__table = 'nickname_blacklist'; // table name
public $pattern; // string pattern public $pattern; // varchar(255) pattern
public $created; // datetime public $created; // datetime not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/** public static function schemaDef()
* 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()
{ {
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 ...@@ -55,19 +55,7 @@ class EmailSummaryPlugin extends Plugin
$schema = Schema::get(); $schema = Schema::get();
// For storing user-submitted flags on profiles // For storing user-submitted flags on profiles
$schema->ensureTable('email_summary_status', $schema->ensureTable('email_summary_status', Email_summary_status::schemaDef());
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),
)
);
return true; return true;
} }
......
...@@ -55,58 +55,21 @@ class Email_summary_status extends Managed_DataObject ...@@ -55,58 +55,21 @@ class Email_summary_status extends Managed_DataObject
public $created; // datetime not_null public $created; // datetime not_null
public $modified; // datetime not_null public $modified; // datetime not_null
/** public static function schemaDef()
* 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()
{ {
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 ...@@ -114,11 +114,7 @@ class FollowEveryonePlugin extends Plugin
$schema = Schema::get(); $schema = Schema::get();
// For storing user-submitted flags on profiles // For storing user-submitted flags on profiles
$schema->ensureTable('user_followeveryone_prefs', $schema->ensureTable('user_followeveryone_prefs', User_followeveryone_prefs::schemaDef());
array(new ColumnDef('user_id', 'integer', null,
true, 'PRI'),
new ColumnDef('followeveryone', 'tinyint', null,
false, null, 1)));
return true; return true;
} }
......
...@@ -57,65 +57,23 @@ class User_followeveryone_prefs extends Managed_DataObject ...@@ -57,65 +57,23 @@ class User_followeveryone_prefs extends Managed_DataObject
public $__table = 'user_followeveryone_prefs'; // table name public $__table = 'user_followeveryone_prefs'; // table name
public $user_id; // int(4) primary_key not_null public $user_id; // int(4) primary_key not_null
public $followeveryone; // tinyint(1) public $followeveryone; // tinyint(1)
public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/** public static function schemaDef()
* 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, return array(
'followeveryone' => DB_DATAOBJECT_INT + DB_DATAOBJECT_BOOL); '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'),
* return key definitions for DB_DataObject 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
* ),
* DB_DataObject needs to know about keys that the table has, since it 'primary key' => array('user_id'),
* won't appear in StatusNet's own keys list. In most cases, this will 'foreign keys' => array(
* simply reference your keyTypes() function. 'user_followeveryone_prefs_user_id_fkey' => array('user', array('user_id' => 'id')),
* ),
* @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);
} }
static function followEveryone($user_id) static function followEveryone($user_id)
......
...@@ -71,20 +71,8 @@ class GNUsocialPhotosPlugin extends Plugin ...@@ -71,20 +71,8 @@ class GNUsocialPhotosPlugin extends Plugin
function onCheckSchema() function onCheckSchema()
{ {
$schema = Schema::get(); $schema = Schema::get();
$schema->ensureTable('GNUsocialPhoto', $schema->ensureTable('GNUsocialPhoto', GNUsocialPhoto::schemaDef());
array(new ColumnDef('id', 'int(11)', null, false, 'PRI', null, null, true), $schema->ensureTable('GNUsocialPhotoAlbum', GNUsocialPhotoAlbum::schemaDef());
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)));
} }
function onRouterInitialized($m) function onRouterInitialized($m)
......
...@@ -38,10 +38,12 @@ class GNUsocialPhoto extends Managed_DataObject ...@@ -38,10 +38,12 @@ class GNUsocialPhoto extends Managed_DataObject
public $id; // int(11) public $id; // int(11)
public $notice_id; // int(11) public $notice_id; // int(11)
public $album_id; // int(11) public $album_id; // int(11)
public $uri; // varchar(512) public $uri; // varchar(255)
public $thumb_uri; // varchar(512) public $thumb_uri; // varchar(255)
public $title; // varchar(512) public $title; // varchar(255)
public $photo_description; // text public $photo_description; // text
public $created; // datetime() not_null
public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
/* function delete() /* function delete()
{ {
...@@ -54,34 +56,32 @@ class GNUsocialPhoto extends Managed_DataObject ...@@ -54,34 +56,32 @@ class GNUsocialPhoto extends Managed_DataObject
return parent::delete(); return parent::delete();
} */ } */
public static function schemaDef()
/*
* 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()
{ {
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) 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 ...@@ -38,33 +38,31 @@ class GNUsocialPhotoAlbum extends Managed_DataObject
public $__table = 'GNUsocialPhotoAlbum'; public $__table = 'GNUsocialPhotoAlbum';
public $album_id; // int(11) -- Unique identifier for the album public $album_id; // int(11) -- Unique identifier for the album
public $profile_id; // int(11) -- Profile ID for the owner of 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 $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 */ /* 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, return array(
'profile_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL, 'fields' => array(