*/
namespace Friendica\Database;
-use dba;
+use Exception;
+use Friendica\Core\Addon;
use Friendica\Core\Config;
use Friendica\Core\L10n;
*/
public static function convertToInnoDB() {
$r = q("SELECT `TABLE_NAME` FROM `information_schema`.`tables` WHERE `engine` = 'MyISAM' AND `table_schema` = '%s'",
- dbesc(dba::database_name()));
+ dbesc(DBA::database_name()));
if (!DBM::is_result($r)) {
echo L10n::t('There are no tables on MyISAM.')."\n";
$sql = sprintf("ALTER TABLE `%s` engine=InnoDB;", dbesc($table['TABLE_NAME']));
echo $sql."\n";
- $result = dba::e($sql);
+ $result = DBA::e($sql);
if (!DBM::is_result($result)) {
self::printUpdateError($sql);
}
*/
private static function printUpdateError($message) {
echo L10n::t("\nError %d occurred during database update:\n%s\n",
- dba::errorNo(), dba::errorMessage());
+ DBA::errorNo(), DBA::errorMessage());
return L10n::t('Errors encountered performing database changes: ').$message.EOL;
}
}
// MySQL >= 5.7.4 doesn't support the IGNORE keyword in ALTER TABLE statements
- if ((version_compare(dba::server_info(), '5.7.4') >= 0) &&
- !(strpos(dba::server_info(), 'MariaDB') !== false)) {
+ if ((version_compare(DBA::server_info(), '5.7.4') >= 0) &&
+ !(strpos(DBA::server_info(), 'MariaDB') !== false)) {
$ignore = '';
} else {
$ignore = ' IGNORE';
$parameters['comment'] = "";
}
- $current_field_definition = dba::clean_query(implode(",", $field_definition));
- $new_field_definition = dba::clean_query(implode(",", $parameters));
+ $current_field_definition = DBA::clean_query(implode(",", $field_definition));
+ $new_field_definition = DBA::clean_query(implode(",", $parameters));
if ($current_field_definition != $new_field_definition) {
$sql2 = self::modifyTableField($fieldname, $parameters);
if ($sql3 == "") {
if ($ignore != "") {
echo "SET session old_alter_table=0;\n";
} else {
- echo "INSERT INTO `".$temp_name."` SELECT ".dba::any_value_fallback($field_list)." FROM `".$name."`".$group_by.";\n";
+ echo "INSERT INTO `".$temp_name."` SELECT ".DBA::any_value_fallback($field_list)." FROM `".$name."`".$group_by.";\n";
echo "DROP TABLE `".$name."`;\n";
echo "RENAME TABLE `".$temp_name."` TO `".$name."`;\n";
}
// Ensure index conversion to unique removes duplicates
if ($is_unique && ($temp_name != $name)) {
if ($ignore != "") {
- dba::e("SET session old_alter_table=1;");
+ DBA::e("SET session old_alter_table=1;");
} else {
- $r = dba::e("DROP TABLE IF EXISTS `".$temp_name."`;");
+ $r = DBA::e("DROP TABLE IF EXISTS `".$temp_name."`;");
if (!DBM::is_result($r)) {
$errors .= self::printUpdateError($sql3);
return $errors;
}
- $r = dba::e("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
+ $r = DBA::e("CREATE TABLE `".$temp_name."` LIKE `".$name."`;");
if (!DBM::is_result($r)) {
$errors .= self::printUpdateError($sql3);
return $errors;
}
}
- $r = dba::e($sql3);
+ $r = DBA::e($sql3);
if (!DBM::is_result($r)) {
$errors .= self::printUpdateError($sql3);
}
if ($is_unique && ($temp_name != $name)) {
if ($ignore != "") {
- dba::e("SET session old_alter_table=0;");
+ DBA::e("SET session old_alter_table=0;");
} else {
- $r = dba::e("INSERT INTO `".$temp_name."` SELECT ".$field_list." FROM `".$name."`".$group_by.";");
+ $r = DBA::e("INSERT INTO `".$temp_name."` SELECT ".$field_list." FROM `".$name."`".$group_by.";");
if (!DBM::is_result($r)) {
$errors .= self::printUpdateError($sql3);
return $errors;
}
- $r = dba::e("DROP TABLE `".$name."`;");
+ $r = DBA::e("DROP TABLE `".$name."`;");
if (!DBM::is_result($r)) {
$errors .= self::printUpdateError($sql3);
return $errors;
}
- $r = dba::e("RENAME TABLE `".$temp_name."` TO `".$name."`;");
+ $r = DBA::e("RENAME TABLE `".$temp_name."` TO `".$name."`;");
if (!DBM::is_result($r)) {
$errors .= self::printUpdateError($sql3);
return $errors;
}
if ($action) {
- $r = dba::e($sql);
+ $r = DBA::e($sql);
}
return $r;
private static function createIndex($indexname, $fieldnames, $method = "ADD") {
$method = strtoupper(trim($method));
if ($method!="" && $method!="ADD") {
- throw new \Exception("Invalid parameter 'method' in self::createIndex(): '$method'");
+ throw new Exception("Invalid parameter 'method' in self::createIndex(): '$method'");
}
if ($fieldnames[0] == "UNIQUE") {
"icid" => ["type" => "int unsigned", "relation" => ["item-content" => "id"], "comment" => "Id of the item-content table entry that contains the whole item content"],
"iaid" => ["type" => "int unsigned", "relation" => ["item-activity" => "id"], "comment" => "Id of the item-activity table entry that contains the activity data"],
"extid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+ "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
"global" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"private" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "distribution is restricted"],
- "bookmark" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been bookmarked"],
"visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been deleted"],
"unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "item has not been seen"],
"mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "The owner of this item was mentioned in it"],
"forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
- // User specific fields. Should possible be replaced with something different
+ "psid" => ["type" => "int unsigned", "relation" => ["permissionset" => "id"], "comment" => "ID of the permission set of this post"],
+ // These fields will be replaced by the "psid" from above
"allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
"allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
"deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
"deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
- "postopts" => ["type" => "text", "comment" => "External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery"],
- "inform" => ["type" => "mediumtext", "comment" => "Additional receivers of this post"],
// It is to be decided whether these fields belong to the user or the structure
"resource-id" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type"],
"event-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"],
- // Will be replaced by the "attach" table
+ // Could possibly be replaced by the "attach" table?
"attach" => ["type" => "mediumtext", "comment" => "JSON structure representing attachments to this item"],
- // Seems to be only used for notes, but is filled at many places.
- // Will be replaced with some general field that contain the values of "origin" and "wall" as well.
- "type" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "comment" => ""],
// Deprecated fields. Will be removed in upcoming versions
+ "postopts" => ["type" => "text", "comment" => "Deprecated"],
+ "inform" => ["type" => "mediumtext", "comment" => "Deprecated"],
+ "type" => ["type" => "varchar(20)", "comment" => "Deprecated"],
+ "bookmark" => ["type" => "boolean", "comment" => "Deprecated"],
"file" => ["type" => "mediumtext", "comment" => "Deprecated"],
"location" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"coord" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"uid_eventid" => ["uid","event-id"],
"icid" => ["icid"],
"iaid" => ["iaid"],
+ "psid" => ["psid"],
]
];
$database["item-activity"] = [
"uri" => ["uri(191)"],
]
];
+ $database["item-delivery-data"] = [
+ "comment" => "Delivery data for items",
+ "fields" => [
+ "iid" => ["type" => "int unsigned", "not null" => "1", "primary" => "1", "relation" => ["item" => "id"], "comment" => "Item id"],
+ "postopts" => ["type" => "text", "comment" => "External post connectors add their network name to this comma-separated string to identify that they should be delivered to these networks during delivery"],
+ "inform" => ["type" => "mediumtext", "comment" => "Additional receivers of the linked item"],
+ ],
+ "indexes" => [
+ "PRIMARY" => ["iid"],
+ ]
+ ];
$database["locks"] = [
"comment" => "",
"fields" => [
"uid_cat_k" => ["UNIQUE", "uid", "cat", "k"],
]
];
+ $database["permissionset"] = [
+ "comment" => "",
+ "fields" => [
+ "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
+ "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "Owner id of this permission set"],
+ "allow_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed contact.id '<19><78>'"],
+ "allow_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of allowed groups"],
+ "deny_cid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied contact.id"],
+ "deny_gid" => ["type" => "mediumtext", "comment" => "Access Control - list of denied groups"],
+ ],
+ "indexes" => [
+ "PRIMARY" => ["id"],
+ "uid_allow_cid_allow_gid_deny_cid_deny_gid" => ["allow_cid(50)", "allow_gid(30)", "deny_cid(50)", "deny_gid(30)"],
+ ]
+ ];
$database["photo"] = [
"comment" => "photo storage",
"fields" => [
"visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"ignored" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
- "bookmark" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
+ "post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
"unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => ""],
"deleted" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"origin" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
"mention" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
+ "bookmark" => ["type" => "boolean", "comment" => ""],
],
"indexes" => [
"PRIMARY" => ["iid"],
]
];
- \Friendica\Core\Addon::callHooks('dbstructure_definition', $database);
+ Addon::callHooks('dbstructure_definition', $database);
return $database;
}