]> git.mxchange.org Git - friendica.git/blobdiff - src/Database/DBStructure.php
Adding multihost - locking
[friendica.git] / src / Database / DBStructure.php
index 45c98f0edd92069fce65929a453f695c6acc04f7..b14f31b11f714f9b81d46a15a206605fd9deac5c 100644 (file)
@@ -4,10 +4,9 @@
  */
 namespace Friendica\Database;
 
+use dba;
 use Friendica\Core\Config;
 use Friendica\Core\L10n;
-use Friendica\Database\DBM;
-use dba;
 
 require_once 'boot.php';
 require_once 'include/dba.php';
@@ -174,7 +173,7 @@ class DBStructure
                        echo "--\n";
                        echo "-- TABLE $name\n";
                        echo "--\n";
-                       self::createTable($name, $structure['fields'], true, false, $structure["indexes"]);
+                       self::createTable($name, $structure, true, false);
 
                        echo "\n";
                }
@@ -251,7 +250,7 @@ class DBStructure
                        $is_unique = false;
                        $temp_name = $name;
                        if (!isset($database[$name])) {
-                               $r = self::createTable($name, $structure["fields"], $verbose, $action, $structure['indexes']);
+                               $r = self::createTable($name, $structure, $verbose, $action);
                                if (!DBM::is_result($r)) {
                                        $errors .= self::printUpdateError($name);
                                }
@@ -322,8 +321,8 @@ class DBStructure
                                                        $parameters['comment'] = "";
                                                }
 
-                                               $current_field_definition = implode(",", $field_definition);
-                                               $new_field_definition = 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 == "") {
@@ -378,6 +377,18 @@ class DBStructure
                                        }
                                }
 
+                               if (isset($database[$name]["table_status"]["Engine"]) && isset($structure['engine'])) {
+                                       if ($database[$name]["table_status"]["Engine"] != $structure['engine']) {
+                                               $sql2 = "ENGINE = '".dbesc($structure['engine'])."'";
+
+                                               if ($sql3 == "") {
+                                                       $sql3 = "ALTER" . $ignore . " TABLE `".$temp_name."` ".$sql2;
+                                               } else {
+                                                       $sql3 .= ", ".$sql2;
+                                               }
+                                       }
+                               }
+
                                if (isset($database[$name]["table_status"]["Collation"])) {
                                        if ($database[$name]["table_status"]["Collation"] != 'utf8mb4_general_ci') {
                                                $sql2 = "DEFAULT COLLATE utf8mb4_general_ci";
@@ -554,20 +565,22 @@ class DBStructure
                return($fieldstruct);
        }
 
-       private static function createTable($name, $fields, $verbose, $action, $indexes=null) {
+       private static function createTable($name, $structure, $verbose, $action) {
                $r = true;
 
+               $engine = "";
+               $comment = "";
                $sql_rows = [];
                $primary_keys = [];
-               foreach ($fields AS $fieldname => $field) {
+               foreach ($structure["fields"] AS $fieldname => $field) {
                        $sql_rows[] = "`".dbesc($fieldname)."` ".self::FieldCommand($field);
                        if (x($field,'primary') && $field['primary']!='') {
                                $primary_keys[] = $fieldname;
                        }
                }
 
-               if (!is_null($indexes)) {
-                       foreach ($indexes AS $indexname => $fieldnames) {
+               if (!is_null($structure["indexes"])) {
+                       foreach ($structure["indexes"] AS $indexname => $fieldnames) {
                                $sql_index = self::createIndex($indexname, $fieldnames, "");
                                if (!is_null($sql_index)) {
                                        $sql_rows[] = $sql_index;
@@ -575,9 +588,18 @@ class DBStructure
                        }
                }
 
+               if (!is_null($structure["engine"])) {
+                       $engine = " ENGINE=" . $structure["engine"];
+               }
+
+               if (!is_null($structure["comment"])) {
+                       $comment = " COMMENT='" . dbesc($structure["comment"]) . "'";
+               }
+
                $sql = implode(",\n\t", $sql_rows);
 
-               $sql = sprintf("CREATE TABLE IF NOT EXISTS `%s` (\n\t", dbesc($name)).$sql."\n) DEFAULT COLLATE utf8mb4_general_ci";
+               $sql = sprintf("CREATE TABLE IF NOT EXISTS `%s` (\n\t", dbesc($name)).$sql.
+                               "\n)" . $engine . " DEFAULT COLLATE utf8mb4_general_ci" . $comment;
                if ($verbose) {
                        echo $sql.";\n";
                }
@@ -1051,7 +1073,7 @@ class DBStructure
                                "fields" => [
                                                "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
                                                "gid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["group" => "id"], "comment" => "groups.id of the associated group"],
-                                               "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id  of the member assigned to the associated group"],
+                                               "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "contact.id of the member assigned to the associated group"],
                                                ],
                                "indexes" => [
                                                "PRIMARY" => ["id"],
@@ -1131,7 +1153,7 @@ class DBStructure
                                                ]
                                ];
                $database["item"] = [
-                               "comment" => "All posts",
+                               "comment" => "Structure for all posts",
                                "fields" => [
                                                "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => ["thread" => "iid"]],
                                                "guid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A unique identifier for this item"],
@@ -1158,6 +1180,7 @@ class DBStructure
                                                "author-name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Name of the author of this item"],
                                                "author-link" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the profile page of the author of this item"],
                                                "author-avatar" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Link to the avatar picture of the author of this item"],
+                                               "icid" => ["type" => "int unsigned", "relation" => ["item-content" => "id"], "comment" => "Id of the item-content table entry that contains the whole item content"],
                                                "title" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "item title"],
                                                "content-warning" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
                                                "body" => ["type" => "mediumtext", "comment" => "item body content"],
@@ -1185,7 +1208,6 @@ class DBStructure
                                                "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
-                                               "spam" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "starred" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been favourited"],
                                                "bookmark" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "item has been bookmarked"],
                                                "unseen" => ["type" => "boolean", "not null" => "1", "default" => "1", "comment" => "item has not been seen"],
@@ -1225,8 +1247,34 @@ class DBStructure
                                                "deleted_changed" => ["deleted","changed"],
                                                "uid_wall_changed" => ["uid","wall","changed"],
                                                "uid_eventid" => ["uid","event-id"],
-                                               "uid_authorlink" => ["uid","author-link(190)"],
-                                               "uid_ownerlink" => ["uid","owner-link(190)"],
+                                               "icid" => ["icid"],
+                                               ]
+                               ];
+               $database["item-content"] = [
+                               "comment" => "Content for all posts",
+                               "fields" => [
+                                               "id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "relation" => ["thread" => "iid"]],
+                                               "uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                                               "uri-plink-hash" => ["type" => "char(80)", "not null" => "1", "default" => "", "comment" => "SHA-1 hash from uri and plink"],
+                                               "title" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "item title"],
+                                               "content-warning" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                                               "body" => ["type" => "mediumtext", "comment" => "item body content"],
+                                               "location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "text location where this item originated"],
+                                               "coord" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "longitude/latitude pair representing location where this item originated"],
+                                               "app" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "application which generated this item"],
+                                               "rendered-hash" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => ""],
+                                               "rendered-html" => ["type" => "mediumtext", "comment" => "item.body converted to html"],
+                                               "object-type" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams object type"],
+                                               "object" => ["type" => "text", "comment" => "JSON encoded object structure unless it is an implied object (normal post)"],
+                                               "target-type" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams target type if applicable (URI)"],
+                                               "target" => ["type" => "text", "comment" => "JSON encoded target structure if used"],
+                                               "plink" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "permalink or URL to a displayable copy of the message at its source"],
+                                               "verb" => ["type" => "varchar(100)", "not null" => "1", "default" => "", "comment" => "ActivityStreams verb"],
+                                               ],
+                               "indexes" => [
+                                               "PRIMARY" => ["id"],
+                                               "uri-plink-hash" => ["UNIQUE", "uri-plink-hash"],
+                                               "uri" => ["uri(191)"],
                                                ]
                                ];
                $database["locks"] = [
@@ -1236,9 +1284,11 @@ class DBStructure
                                                "name" => ["type" => "varchar(128)", "not null" => "1", "default" => "", "comment" => ""],
                                                "locked" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "pid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "comment" => "Process ID"],
-                                               ],
+                                               "expires" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of cache expiration"],
+                               ],
                                "indexes" => [
                                                "PRIMARY" => ["id"],
+                                               "name_expires" => ["name", "expires"]
                                                ]
                                ];
                $database["mail"] = [
@@ -1359,6 +1409,20 @@ class DBStructure
                                                "created" => ["created"],
                                                ]
                                ];
+               $database["openwebauth-token"] = [
+                               "comment" => "Store OpenWebAuth token to verify contacts",
+                               "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" => "User id"],
+                                               "type" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Verify type"],
+                                               "token" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "A generated token"],
+                                               "meta" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
+                                               "created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => "datetime of creation"],
+                                       ],
+                               "indexes" => [
+                                               "PRIMARY" => ["id"],
+                                               ]
+                               ];
                $database["parsed_url"] = [
                                "comment" => "cache for 'parse_url' queries",
                                "fields" => [
@@ -1681,7 +1745,6 @@ class DBStructure
                                                "pubmail" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "moderated" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                                                "visible" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
-                                               "spam" => ["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" => ""],
@@ -1797,6 +1860,18 @@ class DBStructure
                                                "PRIMARY" => ["uid", "iid"],
                                                ]
                                ];
+               $database["worker-ipc"] = [
+                               "comment" => "Inter process communication between the frontend and the worker",
+                               "fields" => [
+                                               "key" => ["type" => "int", "not null" => "1", "primary" => "1", "comment" => ""],
+                                               "jobs" => ["type" => "boolean", "comment" => "Flag for outstanding jobs"],
+                                               ],
+                               "indexes" => [
+                                               "PRIMARY" => ["key"],
+                                               ],
+                               "engine" => "MEMORY",
+                               ];
+
                $database["workerqueue"] = [
                                "comment" => "Background tasks queue entries",
                                "fields" => [