Merge pull request #3415 from annando/1704-db-relation

New function to recursively delete data
This commit is contained in:
Tobias Diekershoff 2017-05-02 08:37:06 +02:00 committed by GitHub
commit 5ef44ad71b
5 changed files with 239 additions and 86 deletions

View File

@ -38,7 +38,7 @@ define ( 'FRIENDICA_PLATFORM', 'Friendica');
define ( 'FRIENDICA_CODENAME', 'Asparagus'); define ( 'FRIENDICA_CODENAME', 'Asparagus');
define ( 'FRIENDICA_VERSION', '3.5.2-dev' ); define ( 'FRIENDICA_VERSION', '3.5.2-dev' );
define ( 'DFRN_PROTOCOL_VERSION', '2.23' ); define ( 'DFRN_PROTOCOL_VERSION', '2.23' );
define ( 'DB_UPDATE_VERSION', 1221 ); define ( 'DB_UPDATE_VERSION', 1222 );
/** /**
* @brief Constant with a HTML line break. * @brief Constant with a HTML line break.

View File

@ -23,6 +23,7 @@ class dba {
public $error = false; public $error = false;
private $_server_info = ''; private $_server_info = '';
private static $dbo; private static $dbo;
private static $relation = array();
function __construct($server, $user, $pass, $db, $install = false) { function __construct($server, $user, $pass, $db, $install = false) {
$a = get_app(); $a = get_app();
@ -519,7 +520,7 @@ class dba {
} }
if (!$stmt->execute()) { if (!$stmt->execute()) {
$errorInfo = self::$dbo->db->errorInfo(); $errorInfo = $stmt->errorInfo();
self::$dbo->error = $errorInfo[2]; self::$dbo->error = $errorInfo[2];
self::$dbo->errorno = $errorInfo[1]; self::$dbo->errorno = $errorInfo[1];
$retval = false; $retval = false;
@ -531,8 +532,8 @@ class dba {
$stmt = self::$dbo->db->stmt_init(); $stmt = self::$dbo->db->stmt_init();
if (!$stmt->prepare($sql)) { if (!$stmt->prepare($sql)) {
self::$dbo->error = self::$dbo->db->error; self::$dbo->error = $stmt->error;
self::$dbo->errorno = self::$dbo->db->errno; self::$dbo->errorno = $stmt->errno;
$retval = false; $retval = false;
break; break;
} }
@ -753,6 +754,158 @@ class dba {
return self::e($sql, $param); return self::e($sql, $param);
} }
/**
* @brief Build the array with the table relations
*
* The array is build from the database definitions in dbstructure.php
*
* This process must only be started once, since the value is cached.
*/
static private function build_relation_data() {
$definition = db_definition();
foreach ($definition AS $table => $structure) {
foreach ($structure['fields'] AS $field => $field_struct) {
if (isset($field_struct['relation'])) {
foreach ($field_struct['relation'] AS $rel_table => $rel_field) {
self::$relation[$rel_table][$rel_field][$table][] = $field;
}
}
}
}
}
/**
* @brief Insert a row into a table
*
* @param string $table Table name
* @param array $param parameter array
* @param boolean $in_commit Internal use: Only do a commit after the last delete
* @param array $callstack Internal use: prevent endless loops
*
* @return boolean|array was the delete successfull? When $in_commit is set: deletion data
*/
static public function delete($table, $param, $in_commit = false, &$callstack = array()) {
$commands = array();
// Create a key for the loop prevention
$key = $table.':'.implode(':', array_keys($param)).':'.implode(':', $param);
// We quit when this key already exists in the callstack.
if (isset($callstack[$key])) {
return $commands;
}
$callstack[$key] = true;
$table = self::$dbo->escape($table);
$commands[$key] = array('table' => $table, 'param' => $param);
// To speed up the whole process we cache the table relations
if (count(self::$relation) == 0) {
self::build_relation_data();
}
// Is there a relation entry for the table?
if (isset(self::$relation[$table])) {
// We only allow a simple "one field" relation.
$field = array_keys(self::$relation[$table])[0];
$rel_def = array_values(self::$relation[$table])[0];
// When the search field is the relation field, we don't need to fetch the rows
// This is useful when the leading record is already deleted in the frontend but the rest is done in the backend
if ((count($param) == 1) AND ($field == array_keys($param)[0])) {
foreach ($rel_def AS $rel_table => $rel_fields) {
foreach ($rel_fields AS $rel_field) {
$retval = self::delete($rel_table, array($rel_field => array_values($param)[0]), true, $callstack);
$commands = array_merge($commands, $retval);
}
}
} else {
// Create a key for preventing double queries
$qkey = $field.'-'.$table.':'.implode(':', array_keys($param)).':'.implode(':', $param);
// We quit when this key already exists in the callstack.
if (isset($callstack[$qkey])) {
continue;
}
$callstack[$qkey] = true;
// Fetch all rows that are to be deleted
$sql = "SELECT ".self::$dbo->escape($field)." FROM `".$table."` WHERE `".
implode("` = ? AND `", array_keys($param))."` = ?";
$data = self::p($sql, $param);
while ($row = self::fetch($data)) {
// Now we accumulate the delete commands
$retval = self::delete($table, array($field => $row[$field]), true, $callstack);
$commands = array_merge($commands, $retval);
}
// Since we had split the delete command we don't need the original command anymore
unset($commands[$key]);
}
}
if (!$in_commit) {
// Now we finalize the process
self::p("COMMIT");
self::p("START TRANSACTION");
$compacted = array();
$counter = array();
foreach ($commands AS $command) {
if (count($command['param']) > 1) {
$sql = "DELETE FROM `".$command['table']."` WHERE `".
implode("` = ? AND `", array_keys($command['param']))."` = ?";
logger(dba::replace_parameters($sql, $command['param']), LOGGER_DATA);
if (!self::e($sql, $param)) {
self::p("ROLLBACK");
return false;
}
} else {
$key_table = $command['table'];
$key_param = array_keys($command['param'])[0];
$value = array_values($command['param'])[0];
// Split the SQL queries in chunks of 100 values
// We do the $i stuff here to make the code better readable
$i = $counter[$key_table][$key_param];
if (count($compacted[$key_table][$key_param][$i]) > 100) {
++$i;
}
$compacted[$key_table][$key_param][$i][$value] = $value;
$counter[$key_table][$key_param] = $i;
}
}
foreach ($compacted AS $table => $values) {
foreach ($values AS $field => $field_value_list) {
foreach ($field_value_list AS $field_values) {
$sql = "DELETE FROM `".$table."` WHERE `".$field."` IN (".
substr(str_repeat("?, ", count($field_values)), 0, -2).");";
logger(dba::replace_parameters($sql, $field_values), LOGGER_DATA);
if (!self::e($sql, $param)) {
self::p("ROLLBACK");
return false;
}
}
}
}
self::p("COMMIT");
return true;
}
return $commands;
}
/** /**
* @brief Updates rows * @brief Updates rows
* *

View File

@ -300,6 +300,9 @@ function update_structure($verbose, $action, $tables=null, $definition=null) {
// Compare the field definition // Compare the field definition
$field_definition = $database[$name]["fields"][$fieldname]; $field_definition = $database[$name]["fields"][$fieldname];
// Remove the relation data that is used for the referential integrity
unset($parameters['relation']);
// We change the collation after the indexes had been changed. // We change the collation after the indexes had been changed.
// This is done to avoid index length problems. // This is done to avoid index length problems.
// So here we always ensure that there is no need to change it. // So here we always ensure that there is no need to change it.
@ -627,7 +630,7 @@ function db_definition() {
$database["attach"] = array( $database["attach"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"hash" => array("type" => "varchar(64)", "not null" => "1", "default" => ""), "hash" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
"filename" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "filename" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"filetype" => array("type" => "varchar(64)", "not null" => "1", "default" => ""), "filetype" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
@ -647,7 +650,7 @@ function db_definition() {
$database["auth_codes"] = array( $database["auth_codes"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "varchar(40)", "not null" => "1", "primary" => "1"), "id" => array("type" => "varchar(40)", "not null" => "1", "primary" => "1"),
"client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => ""), "client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => "", "relation" => array("clients" => "client_id")),
"redirect_uri" => array("type" => "varchar(200)", "not null" => "1", "default" => ""), "redirect_uri" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
"expires" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "expires" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"scope" => array("type" => "varchar(250)", "not null" => "1", "default" => ""), "scope" => array("type" => "varchar(250)", "not null" => "1", "default" => ""),
@ -688,7 +691,7 @@ function db_definition() {
"redirect_uri" => array("type" => "varchar(200)", "not null" => "1", "default" => ""), "redirect_uri" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
"name" => array("type" => "text"), "name" => array("type" => "text"),
"icon" => array("type" => "text"), "icon" => array("type" => "text"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
), ),
"indexes" => array( "indexes" => array(
"PRIMARY" => array("client_id"), "PRIMARY" => array("client_id"),
@ -709,7 +712,7 @@ function db_definition() {
$database["contact"] = array( $database["contact"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"self" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "self" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"remote_self" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "remote_self" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
@ -798,7 +801,7 @@ function db_definition() {
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""), "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
"recips" => array("type" => "text"), "recips" => array("type" => "text"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"creator" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "creator" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
@ -828,8 +831,8 @@ function db_definition() {
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
@ -881,9 +884,9 @@ function db_definition() {
$database["ffinder"] = array( $database["ffinder"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"fid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "fid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("fcontact" => "id")),
), ),
"indexes" => array( "indexes" => array(
"PRIMARY" => array("id"), "PRIMARY" => array("id"),
@ -904,8 +907,8 @@ function db_definition() {
$database["fsuggest"] = array( $database["fsuggest"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"request" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "request" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -920,8 +923,8 @@ function db_definition() {
$database["gcign"] = array( $database["gcign"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("gcontact" => "id")),
), ),
"indexes" => array( "indexes" => array(
"PRIMARY" => array("id"), "PRIMARY" => array("id"),
@ -971,10 +974,10 @@ function db_definition() {
$database["glink"] = array( $database["glink"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "gcid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("gcontact" => "id")),
"zcid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "zcid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("gcontact" => "id")),
"updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "updated" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
), ),
"indexes" => array( "indexes" => array(
@ -986,7 +989,7 @@ function db_definition() {
$database["group"] = array( $database["group"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "visible" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "deleted" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -999,9 +1002,9 @@ function db_definition() {
$database["group_member"] = array( $database["group_member"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"gid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "gid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("group" => "id")),
"contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
), ),
"indexes" => array( "indexes" => array(
"PRIMARY" => array("id"), "PRIMARY" => array("id"),
@ -1049,9 +1052,9 @@ function db_definition() {
$database["intro"] = array( $database["intro"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"fid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "fid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("fcontact" => "id")),
"contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"knowyou" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "knowyou" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"duplex" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "duplex" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"note" => array("type" => "text"), "note" => array("type" => "text"),
@ -1066,16 +1069,16 @@ function db_definition() {
); );
$database["item"] = array( $database["item"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => array("thread" => "iid")),
"guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "guid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "contact-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"), "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("gcontact" => "id")),
"type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "type" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "wall" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"gravity" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "gravity" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"parent" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "parent" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
"parent-uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "parent-uri" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"extid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "extid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"thr-parent" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "thr-parent" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -1084,11 +1087,11 @@ function db_definition() {
"commented" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "commented" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"changed" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "changed" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"owner-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "owner-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"owner-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "owner-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"owner-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "owner-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"owner-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "owner-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"author-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "author-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"author-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "author-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"author-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "author-link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"author-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "author-avatar" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -1103,7 +1106,7 @@ function db_definition() {
"postopts" => array("type" => "text"), "postopts" => array("type" => "text"),
"plink" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "plink" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"event-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "event-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("event" => "id")),
"tag" => array("type" => "mediumtext"), "tag" => array("type" => "mediumtext"),
"attach" => array("type" => "mediumtext"), "attach" => array("type" => "mediumtext"),
"inform" => array("type" => "mediumtext"), "inform" => array("type" => "mediumtext"),
@ -1149,6 +1152,7 @@ function db_definition() {
"uid_parenturi" => array("uid","parent-uri(190)"), "uid_parenturi" => array("uid","parent-uri(190)"),
"uid_contactid_created" => array("uid","contact-id","created"), "uid_contactid_created" => array("uid","contact-id","created"),
"authorid_created" => array("author-id","created"), "authorid_created" => array("author-id","created"),
"ownerid" => array("owner-id"),
"uid_uri" => array("uid", "uri(190)"), "uid_uri" => array("uid", "uri(190)"),
"resource-id" => array("resource-id"), "resource-id" => array("resource-id"),
"contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"), // "contactid_allowcid_allowpid_denycid_denygid" => array("contact-id","allow_cid(10)","allow_gid(10)","deny_cid(10)","deny_gid(10)"), //
@ -1164,8 +1168,8 @@ function db_definition() {
$database["item_id"] = array( $database["item_id"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"iid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "iid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"sid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "sid" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"service" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "service" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
), ),
@ -1191,13 +1195,13 @@ function db_definition() {
$database["mail"] = array( $database["mail"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""), "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
"from-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "from-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"from-photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "from-photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"from-url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "from-url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"contact-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "contact-id" => array("type" => "varchar(255)", "not null" => "1", "default" => "", "relation" => array("contact" => "id")),
"convid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"), "convid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("conv" => "id")),
"title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "title" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"body" => array("type" => "mediumtext"), "body" => array("type" => "mediumtext"),
"seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
@ -1219,7 +1223,7 @@ function db_definition() {
$database["mailacct"] = array( $database["mailacct"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "server" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"port" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "port" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"ssltype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""), "ssltype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
@ -1239,8 +1243,8 @@ function db_definition() {
$database["manage"] = array( $database["manage"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"mid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "mid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
), ),
"indexes" => array( "indexes" => array(
"PRIMARY" => array("id"), "PRIMARY" => array("id"),
@ -1257,10 +1261,10 @@ function db_definition() {
"photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "photo" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "date" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"msg" => array("type" => "mediumtext"), "msg" => array("type" => "mediumtext"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "link" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"iid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "iid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
"parent" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "parent" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
"seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "seen" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "verb" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"otype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""), "otype" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
@ -1278,10 +1282,10 @@ function db_definition() {
$database["notify-threads"] = array( $database["notify-threads"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"notify-id" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "notify-id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("notify" => "id")),
"master-parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "master-parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
"parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "parent-item" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"receiver-uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "receiver-uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
), ),
"indexes" => array( "indexes" => array(
"PRIMARY" => array("id"), "PRIMARY" => array("id"),
@ -1314,7 +1318,7 @@ function db_definition() {
$database["pconfig"] = array( $database["pconfig"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"cat" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""), "cat" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
"k" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""), "k" => array("type" => "varbinary(255)", "not null" => "1", "default" => ""),
"v" => array("type" => "mediumtext"), "v" => array("type" => "mediumtext"),
@ -1327,8 +1331,8 @@ function db_definition() {
$database["photo"] = array( $database["photo"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "contact-id" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""), "guid" => array("type" => "varchar(64)", "not null" => "1", "default" => ""),
"resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "resource-id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
@ -1361,7 +1365,7 @@ function db_definition() {
$database["poll"] = array( $database["poll"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"q0" => array("type" => "text"), "q0" => array("type" => "text"),
"q1" => array("type" => "text"), "q1" => array("type" => "text"),
"q2" => array("type" => "text"), "q2" => array("type" => "text"),
@ -1381,7 +1385,7 @@ function db_definition() {
$database["poll_result"] = array( $database["poll_result"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"poll_id" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "poll_id" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("poll" => "id")),
"choice" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "choice" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
), ),
"indexes" => array( "indexes" => array(
@ -1404,7 +1408,7 @@ function db_definition() {
$database["profile"] = array( $database["profile"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"profile-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "profile-name" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"is-default" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "is-default" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"hide-friends" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "hide-friends" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
@ -1454,8 +1458,8 @@ function db_definition() {
$database["profile_check"] = array( $database["profile_check"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "cid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"dfrn_id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "dfrn_id" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"sec" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "sec" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"expire" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "expire" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
@ -1467,7 +1471,7 @@ function db_definition() {
$database["push_subscriber"] = array( $database["push_subscriber"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"callback_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "callback_url" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"topic" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "topic" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"nickname" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "nickname" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -1482,7 +1486,7 @@ function db_definition() {
$database["queue"] = array( $database["queue"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"cid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "cid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""), "network" => array("type" => "varchar(32)", "not null" => "1", "default" => ""),
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"last" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "last" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
@ -1503,7 +1507,7 @@ function db_definition() {
"id" => array("type" => "int(11) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"hash" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "hash" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"uid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"password" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "password" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
"language" => array("type" => "varchar(16)", "not null" => "1", "default" => ""), "language" => array("type" => "varchar(16)", "not null" => "1", "default" => ""),
"note" => array("type" => "text"), "note" => array("type" => "text"),
@ -1515,7 +1519,7 @@ function db_definition() {
$database["search"] = array( $database["search"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
), ),
"indexes" => array( "indexes" => array(
@ -1539,7 +1543,7 @@ function db_definition() {
$database["sign"] = array( $database["sign"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
"signed_text" => array("type" => "mediumtext"), "signed_text" => array("type" => "mediumtext"),
"signature" => array("type" => "text"), "signature" => array("type" => "text"),
"signer" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "signer" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -1552,7 +1556,7 @@ function db_definition() {
$database["spam"] = array( $database["spam"] = array(
"fields" => array( "fields" => array(
"id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "id" => array("type" => "int(11)", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"spam" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "spam" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"ham" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "ham" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -1569,7 +1573,7 @@ function db_definition() {
$database["term"] = array( $database["term"] = array(
"fields" => array( "fields" => array(
"tid" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"), "tid" => array("type" => "int(10) unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1"),
"oid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "oid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("item" => "id")),
"otype" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"), "otype" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
"type" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"), "type" => array("type" => "tinyint(3) unsigned", "not null" => "1", "default" => "0"),
"term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""), "term" => array("type" => "varchar(255)", "not null" => "1", "default" => ""),
@ -1579,7 +1583,7 @@ function db_definition() {
"received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"), "global" => array("type" => "tinyint(1)", "not null" => "1", "default" => "0"),
"aid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "aid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
), ),
"indexes" => array( "indexes" => array(
"PRIMARY" => array("tid"), "PRIMARY" => array("tid"),
@ -1591,12 +1595,12 @@ function db_definition() {
); );
$database["thread"] = array( $database["thread"] = array(
"fields" => array( "fields" => array(
"iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "primary" => "1"), "iid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => array("item" => "id")),
"uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(10) unsigned", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
"contact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"), "contact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"), "gcontact-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("gcontact" => "id")),
"owner-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"), "owner-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"author-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0"), "author-id" => array("type" => "int(11) unsigned", "not null" => "1", "default" => "0", "relation" => array("contact" => "id")),
"created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "created" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "edited" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
"commented" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE), "commented" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
@ -1624,6 +1628,9 @@ function db_definition() {
"uid_network_created" => array("uid","network","created"), "uid_network_created" => array("uid","network","created"),
"uid_contactid_commented" => array("uid","contact-id","commented"), "uid_contactid_commented" => array("uid","contact-id","commented"),
"uid_contactid_created" => array("uid","contact-id","created"), "uid_contactid_created" => array("uid","contact-id","created"),
"contactid" => array("contact-id"),
"ownerid" => array("owner-id"),
"authorid" => array("author-id"),
"uid_created" => array("uid","created"), "uid_created" => array("uid","created"),
"uid_commented" => array("uid","commented"), "uid_commented" => array("uid","commented"),
"uid_wall_created" => array("uid","wall","created"), "uid_wall_created" => array("uid","wall","created"),
@ -1633,10 +1640,10 @@ function db_definition() {
"fields" => array( "fields" => array(
"id" => array("type" => "varchar(40)", "not null" => "1", "primary" => "1"), "id" => array("type" => "varchar(40)", "not null" => "1", "primary" => "1"),
"secret" => array("type" => "text"), "secret" => array("type" => "text"),
"client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => ""), "client_id" => array("type" => "varchar(20)", "not null" => "1", "default" => "", "relation" => array("clients" => "client_id")),
"expires" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "expires" => array("type" => "int(11)", "not null" => "1", "default" => "0"),
"scope" => array("type" => "varchar(200)", "not null" => "1", "default" => ""), "scope" => array("type" => "varchar(200)", "not null" => "1", "default" => ""),
"uid" => array("type" => "int(11)", "not null" => "1", "default" => "0"), "uid" => array("type" => "int(11)", "not null" => "1", "default" => "0", "relation" => array("user" => "uid")),
), ),
"indexes" => array( "indexes" => array(
"PRIMARY" => array("id"), "PRIMARY" => array("id"),
@ -1780,7 +1787,7 @@ function dbstructure_run(&$argv, &$argc) {
echo "dryrun show database update schema queries without running them\n"; echo "dryrun show database update schema queries without running them\n";
echo "update update database schema\n"; echo "update update database schema\n";
echo "dumpsql dump database schema\n"; echo "dumpsql dump database schema\n";
echo "toinnodb convert all tables from MyISAM to InnoDB\n"; echo "toinnodb convert all tables from MyISAM to InnoDB\n";
return; return;
} }

View File

@ -19,14 +19,7 @@ function remove_contact_run($argv, $argc) {
return; return;
} }
q("DELETE FROM `item` WHERE `contact-id` = %d", intval($id)); // Now we delete all the depending table entries
dba::delete('contact', array('id' => $id));
q("DELETE FROM `photo` WHERE `contact-id` = %d", intval($id));
q("DELETE FROM `mail` WHERE `contact-id` = %d", intval($id));
q("DELETE FROM `event` WHERE `cid` = %d", intval($id));
q("DELETE FROM `queue` WHERE `cid` = %d", intval($id));
} }
?> ?>

View File

@ -1,6 +1,6 @@
<?php <?php
define('UPDATE_VERSION' , 1221); define('UPDATE_VERSION' , 1222);
/** /**
* *