OStatus classes now has modern schemaDef

This commit is contained in:
Mikael Nordfeldth 2013-08-21 11:01:31 +02:00
parent 3a7261f70a
commit 66997f2bec
3 changed files with 59 additions and 203 deletions

View File

@ -78,89 +78,27 @@ class FeedSub extends Managed_DataObject
public $created; public $created;
public $modified; public $modified;
/** 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('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL, return array(
'uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL, 'fields' => array(
'huburi' => DB_DATAOBJECT_STR, 'id' => array('type' => 'int', 'not null' => true, 'description' => 'FeedSub local unique id'),
'secret' => DB_DATAOBJECT_STR, 'uri' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'FeedSub uri'),
'verify_token' => DB_DATAOBJECT_STR, 'huburi' => array('type' => 'text', 'description' => 'FeedSub hub-uri'),
'sub_state' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL, 'verify_token' => array('type' => 'text', 'description' => 'FeedSub verify-token'),
'sub_start' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME, 'secret' => array('type' => 'text', 'description' => 'FeedSub stored secret'),
'sub_end' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME, 'sub_state' => array('type' => 'enum("subscribe","active","unsubscribe","inactive")', 'not null' => true, 'description' => 'subscription state'),
'last_update' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME, 'sub_start' => array('type' => 'datetime', 'description' => 'subscription start'),
'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL, 'sub_end' => array('type' => 'datetime', 'description' => 'subscription end'),
'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL); 'last_update' => array('type' => 'datetime', 'not null' => true, 'description' => 'when this record was last updated'),
} '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'),
static function schemaDef() ),
{ 'primary key' => array('id'),
return array(new ColumnDef('id', 'integer', 'unique keys' => array(
/*size*/ null, 'feedsub_uri_key' => array('uri'),
/*nullable*/ false, ),
/*key*/ 'PRI', );
/*default*/ null,
/*extra*/ null,
/*auto_increment*/ true),
new ColumnDef('uri', 'varchar',
255, false, 'UNI'),
new ColumnDef('huburi', 'text',
null, true),
new ColumnDef('verify_token', 'text',
null, true),
new ColumnDef('secret', 'text',
null, true),
new ColumnDef('sub_state', "enum('subscribe','active','unsubscribe','inactive')",
null, false),
new ColumnDef('sub_start', 'datetime',
null, true),
new ColumnDef('sub_end', 'datetime',
null, true),
new ColumnDef('last_update', 'datetime',
null, false),
new ColumnDef('created', 'datetime',
null, false),
new ColumnDef('modified', 'datetime',
null, false));
}
/**
* 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('id' => 'K', 'uri' => 'U');
}
function sequenceKey()
{
return array('id', true, false);
} }
/** /**

View File

@ -45,74 +45,25 @@ class HubSub extends Managed_DataObject
return sha1($topic . '|' . $callback); return sha1($topic . '|' . $callback);
} }
/** 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('hashkey' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL, return array(
'topic' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL, 'fields' => array(
'callback' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL, 'hashkey' => array('type' => 'char', 'not null' => true, 'length' => 40, 'description' => 'HubSub hashkey'),
'secret' => DB_DATAOBJECT_STR, 'topic' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'HubSub topic'),
'lease' => DB_DATAOBJECT_INT, 'callback' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'HubSub callback'),
'sub_start' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME, 'secret' => array('type' => 'text', 'description' => 'HubSub stored secret'),
'sub_end' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME, 'lease' => array('type' => 'int', 'not null' => true, 'description' => 'HubSub leasetime'),
'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL, 'sub_start' => array('type' => 'datetime', 'description' => 'subscription start'),
'modified' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL); 'sub_end' => array('type' => 'datetime', 'description' => 'subscription end'),
} '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'),
static function schemaDef() ),
{ 'primary key' => array('hashkey'),
return array(new ColumnDef('hashkey', 'char', 'indexes' => array(
/*size*/40, 'hubsub_topic_idx' => array('topic'),
/*nullable*/false, ),
/*key*/'PRI'), );
new ColumnDef('topic', 'varchar',
/*size*/255,
/*nullable*/false,
/*key*/'MUL'),
new ColumnDef('callback', 'varchar',
255, false),
new ColumnDef('secret', 'text',
null, true),
new ColumnDef('lease', 'int',
null, true),
new ColumnDef('sub_start', 'datetime',
null, true),
new ColumnDef('sub_end', 'datetime',
null, true),
new ColumnDef('created', 'datetime',
null, false),
new ColumnDef('modified', 'datetime',
null, false));
}
function keys()
{
return array_keys($this->keyTypes());
}
function sequenceKey()
{
return array(false, false, false);
}
/**
* 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 keyTypes()
{
return array('hashkey' => 'K');
} }
/** /**

View File

@ -32,62 +32,29 @@ class Ostatus_source extends Managed_DataObject
public $notice_id; // notice we're referring to public $notice_id; // notice we're referring to
public $profile_uri; // uri of the ostatus_profile this came through -- may be a group feed public $profile_uri; // uri of the ostatus_profile this came through -- may be a group feed
public $method; // push or salmon public $method; // push or salmon
public $created;
public $modified;
/** 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('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL, return array(
'profile_uri' => DB_DATAOBJECT_STR, 'fields' => array(
'method' => DB_DATAOBJECT_STR); 'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'Notice ID relation'),
} 'profile_uri' => array('type' => 'varchar', 'not null' => true, 'length' => 255, 'description' => 'Profile URI'),
'method' => array('type' => 'enum("push","salmon")', 'not null' => true, 'description' => 'source method'),
static function schemaDef() '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'),
return array(new ColumnDef('notice_id', 'integer', ),
null, false, 'PRI'), 'primary key' => array('notice_id'),
new ColumnDef('profile_uri', 'varchar', 'foreign keys' => array(
255, false), 'ostatus_source_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
new ColumnDef('method', "ENUM('push','salmon')", // not in profile table yet 'ostatus_source_profile_uri_fkey' => array('profile', array('profile_uri' => 'uri')),
null, false)); ),
} 'indexes' => array(
'ostatus_source_profile_uri_idx' => array('profile_uri'),
/** ),
* 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('notice_id' => 'K');
}
function sequenceKey()
{
return array(false, false, false);
}
/** /**
* Save a remote notice source record; this helps indicate how trusted we are. * Save a remote notice source record; this helps indicate how trusted we are.