From 1912729b907fa2b7c6cd1104379b789d3a3ad585 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 4 May 2020 14:33:41 +0000 Subject: [PATCH 01/10] Tests with item views --- static/dbview.config.php | 90 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/static/dbview.config.php b/static/dbview.config.php index fa302b8669..70c6cfeb13 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -37,6 +37,96 @@ */ return [ + "item-view" => [ + "fields" => [ +/* +"uid" => ["item", ""], +"parent" => ["item", ""], +"uri" => ["item", ""], +"parent-uri" => ["item", ""], +"thr-parent" => ["item", ""], +"guid" => ["item", ""], +"uri-id" => ["item", ""], +"parent-uri-id" => ["item", ""], +"thr-parent-id" => ["item", ""], +"contact-id" => ["item", ""], +"type" => ["item", ""], +"wall" => ["item", ""], +"gravity" => ["item", ""], +"extid" => ["item", ""], +"psid" => ["item", ""], +"created" => ["item", ""], +"edited" => ["item", ""], +"commented" => ["item", ""], +"received" => ["item", ""], +"changed" => ["item", ""], +"verb" => ["", ""], +"postopts" => ["", ""], +"plink" => ["", ""], +"resource-id" => ["item", ""], +"event-id" => ["item", ""], +"attach" => ["item", ""], +"inform" => ["", ""], +"file" => ["", ""], +"allow_cid" => ["", ""], +"allow_gid" => ["", ""], +"deny_cid" => ["", ""], +"deny_gid" => ["", ""], +"post-type" => ["item", ""], +"private" => ["item", ""], +"pubmail" => ["item", ""], +"moderated" => ["item", ""], +"visible" => ["item", ""], +"starred" => ["item", ""], +"bookmark" => ["", ""], +"unseen" => ["item", ""], +"deleted" => ["item", ""], +"origin" => ["item", ""], +"forum_mode" => ["item", ""], +"mention" => ["item", ""], +"global" => ["item", ""], +"network" => ["item", ""], +"title" => ["", ""], +"content-warning" => ["", ""], +"body" => ["", ""], +"location" => ["", ""], +"coord" => ["", ""], +"app" => ["", ""], +"rendered-hash" => ["", ""], +"rendered-html" => ["", ""], +"object-type" => ["", ""], +"object" => ["", ""], +"target-type" => ["", ""], +"target" => ["", ""], +"author-id" => ["item", ""], +"author-link" => ["author", ""], +"author-name" => ["author", ""], +"author-avatar" => ["author", ""], +"author-network" => ["author", ""], +"owner-id" => ["item", ""], +"owner-link" => ["owner", ""], +"owner-name" => ["owner", ""], +"owner-avatar" => ["owner", ""] +*/ + "uri-id" => ["post-category", "uri-id"], + "uid" => ["post-category", "uid"], + "uri" => ["item-uri", "uri"], + "guid" => ["item-uri", "guid"], + "type" => ["post-category", "type"], + "tid" => ["post-category", "tid"], + "name" => ["tag", "name"], + "url" => ["tag", "url"], + ], + "query" => "FROM `item` + LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + LEFT JOIN `contact` AS `author` ON `author`.`id` = `item`.`author-id` + LEFT JOIN `contact` AS `owner` ON `owner`.`id` = `item`.`owner-id` + LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `item`.`uri-id` + LEFT JOIN `item-activity` ON `item-activity`.`uri-id` = `item`.`uri-id` + LEFT JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id` + LEFT JOIN `item-delivery-data` ON `item-delivery-data`.`iid` = `item`.`id` + LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid`" + ], "category-view" => [ "fields" => [ "uri-id" => ["post-category", "uri-id"], From 1dd48791978f195ddcc5934c994fd035a8a45143 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 6 May 2020 15:19:06 +0000 Subject: [PATCH 02/10] Item view is working --- static/dbview.config.php | 164 ++++++++++++++++++++------------------- 1 file changed, 85 insertions(+), 79 deletions(-) diff --git a/static/dbview.config.php b/static/dbview.config.php index 6c75ac037d..cb41d06376 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -39,83 +39,87 @@ return [ "item-view" => [ "fields" => [ -/* -"uid" => ["item", ""], -"parent" => ["item", ""], -"uri" => ["item", ""], -"parent-uri" => ["item", ""], -"thr-parent" => ["item", ""], -"guid" => ["item", ""], -"uri-id" => ["item", ""], -"parent-uri-id" => ["item", ""], -"thr-parent-id" => ["item", ""], -"contact-id" => ["item", ""], -"type" => ["item", ""], -"wall" => ["item", ""], -"gravity" => ["item", ""], -"extid" => ["item", ""], -"psid" => ["item", ""], -"created" => ["item", ""], -"edited" => ["item", ""], -"commented" => ["item", ""], -"received" => ["item", ""], -"changed" => ["item", ""], -"verb" => ["", ""], -"postopts" => ["", ""], -"plink" => ["", ""], -"resource-id" => ["item", ""], -"event-id" => ["item", ""], -"attach" => ["item", ""], -"inform" => ["", ""], -"file" => ["", ""], -"allow_cid" => ["", ""], -"allow_gid" => ["", ""], -"deny_cid" => ["", ""], -"deny_gid" => ["", ""], -"post-type" => ["item", ""], -"private" => ["item", ""], -"pubmail" => ["item", ""], -"moderated" => ["item", ""], -"visible" => ["item", ""], -"starred" => ["item", ""], -"bookmark" => ["", ""], -"unseen" => ["item", ""], -"deleted" => ["item", ""], -"origin" => ["item", ""], -"forum_mode" => ["item", ""], -"mention" => ["item", ""], -"global" => ["item", ""], -"network" => ["item", ""], -"title" => ["", ""], -"content-warning" => ["", ""], -"body" => ["", ""], -"location" => ["", ""], -"coord" => ["", ""], -"app" => ["", ""], -"rendered-hash" => ["", ""], -"rendered-html" => ["", ""], -"object-type" => ["", ""], -"object" => ["", ""], -"target-type" => ["", ""], -"target" => ["", ""], -"author-id" => ["item", ""], -"author-link" => ["author", ""], -"author-name" => ["author", ""], -"author-avatar" => ["author", ""], -"author-network" => ["author", ""], -"owner-id" => ["item", ""], -"owner-link" => ["owner", ""], -"owner-name" => ["owner", ""], -"owner-avatar" => ["owner", ""] -*/ - "uri-id" => ["post-category", "uri-id"], - "uid" => ["post-category", "uid"], - "uri" => ["item-uri", "uri"], - "guid" => ["item-uri", "guid"], - "type" => ["post-category", "type"], - "tid" => ["post-category", "tid"], - "name" => ["tag", "name"], - "url" => ["tag", "url"], + "id" => ["item", "id"], + "item_id" => ["item", "id"], + "uid" => ["item", "uid"], + "parent" => ["item", "parent"], + "uri" => ["item", "uri"], + "parent-uri" => ["item", "parent-uri"], + "thr-parent" => ["item", "thr-parent"], + "guid" => ["item", "guid"], + "uri-id" => ["item", "uri-id"], + "parent-uri-id" => ["item", "parent-uri-id"], + "thr-parent-id" => ["item", "thr-parent-id"], + "contact-id" => ["item", "contact-id"], + "type" => ["item", "type"], + "wall" => ["item", "wall"], + "gravity" => ["item", "gravity"], + "extid" => ["item", "extid"], + "iaid" => ["item", "iaid"], + "icid" => ["item", "icid"], + "psid" => ["item", "psid"], + "created" => ["item", "created"], + "edited" => ["item", "edited"], + "commented" => ["item", "commented"], + "received" => ["item", "received"], + "changed" => ["item", "changed"], + "verb" => ["item-content", "verb"], + "plink" => ["item-content", "plink"], + "language" => ["item-content", "language"], + "resource-id" => ["item", "resource-id"], + "event-id" => ["item", "event-id"], + "attach" => ["item", "attach"], + "postopts" => ["post-delivery-data", "postopts"], + "inform" => ["post-delivery-data", "inform"], + "file" => "NULL", + "allow_cid" => ["permissionset", "allow_cid"], + "allow_gid" => ["permissionset", "allow_gid"], + "deny_cid" => ["permissionset", "deny_cid"], + "deny_gid" => ["permissionset", "deny_gid"], + "post-type" => ["item", "post-type"], + "private" => ["item", "private"], + "pubmail" => ["item", "pubmail"], + "moderated" => ["item", "moderated"], + "visible" => ["item", "visible"], + "starred" => ["item", "starred"], + "bookmark" => ["thread", "bookmark"], + "unseen" => ["item", "unseen"], + "deleted" => ["item", "deleted"], + "origin" => ["item", "origin"], + "forum_mode" => ["item", "forum_mode"], + "mention" => ["item", "mention"], + "global" => ["item", "global"], + "network" => ["item", "network"], + "title" => ["item-content", "title"], + "content-warning" => ["item-content", "content-warning"], + "body" => ["item-content", "body"], + "location" => ["item-content", "location"], + "coord" => ["item-content", "coord"], + "app" => ["item-content", "app"], + "rendered-hash" => ["item-content", "rendered-hash"], + "rendered-html" => ["item-content", "rendered-html"], + "object-type" => ["item-content", "object-type"], + "object" => ["item-content", "object"], + "target-type" => ["item-content", "target-type"], + "target" => ["item-content", "target"], + "author-id" => ["item", "author-id"], + "author-link" => ["author", "url"], + "author-name" => ["author", "name"], + "author-avatar" => ["author", "thumb"], + "author-network" => ["author", "network"], + "owner-id" => ["item", "owner-id"], + "owner-link" => ["owner", "url"], + "owner-addr" => ["owner", "addr"], + "owner-avatar" => ["owner", "thumb"], + "owner-nick" => ["owner", "nick"], + "owner-name" => ["owner", "name"], + "owner-network" => ["owner", "network"], + "contact-uid" => ["contact", "uid"], + "parent-guid" => ["parent-item", "guid"], + "parent-network" => ["parent-item", "network"], + "signed_text" => ["diaspora-interaction", "interaction"], + "signature" => "NULL", + "signer" => "NULL" ], "query" => "FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` @@ -124,8 +128,10 @@ return [ LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `item`.`uri-id` LEFT JOIN `item-activity` ON `item-activity`.`uri-id` = `item`.`uri-id` LEFT JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id` - LEFT JOIN `item-delivery-data` ON `item-delivery-data`.`iid` = `item`.`id` - LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid`" + LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `item`.`uri-id` AND `item`.`origin` + LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid` + LEFT JOIN `thread` ON `thread`.`iid` = `item`.`parent` + STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent`" ], "category-view" => [ "fields" => [ From ca16a4892bd81f55627b3f277921835d30d34156 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 13 Jan 2021 07:23:57 +0000 Subject: [PATCH 03/10] The item view is completed, unneeded fields removed --- src/Model/Item.php | 2 +- src/Protocol/Diaspora.php | 45 --------- static/dbview.config.php | 203 +++++++++++++++++++++++--------------- 3 files changed, 125 insertions(+), 125 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index e4266b41ee..ee30f41ca0 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -96,7 +96,7 @@ class Item 'deleted', 'extid', 'post-type', 'gravity', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'author-id', 'author-link', 'owner-link', 'contact-uid', - 'signed_text', 'signature', 'signer', 'network']; + 'signed_text', 'network']; // Field list for "item-content" table that is mixed with the item table const MIXED_CONTENT_FIELDLIST = ['title', 'content-warning', 'body', 'location', diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 269d623868..90c6e12edd 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -3700,51 +3700,6 @@ class Diaspora return self::buildAndTransmit($owner, $contact, $type, $message, $public_batch, $item["guid"]); } - /** - * Creates a message from a signature record entry - * - * @param array $item The item that will be exported - * @return array The message - */ - private static function messageFromSignature(array $item) - { - // Split the signed text - $signed_parts = explode(";", $item['signed_text']); - - if ($item["deleted"]) { - $message = ["author" => $item['signer'], - "target_guid" => $signed_parts[0], - "target_type" => $signed_parts[1]]; - } elseif (in_array($item["verb"], [Activity::LIKE, Activity::DISLIKE])) { - $message = ["author" => $signed_parts[4], - "guid" => $signed_parts[1], - "parent_guid" => $signed_parts[3], - "parent_type" => $signed_parts[2], - "positive" => $signed_parts[0], - "author_signature" => $item['signature'], - "parent_author_signature" => ""]; - } else { - // Remove the comment guid - $guid = array_shift($signed_parts); - - // Remove the parent guid - $parent_guid = array_shift($signed_parts); - - // Remove the handle - $handle = array_pop($signed_parts); - - $message = [ - "author" => $handle, - "guid" => $guid, - "parent_guid" => $parent_guid, - "text" => implode(";", $signed_parts), - "author_signature" => $item['signature'], - "parent_author_signature" => "" - ]; - } - return $message; - } - /** * Relays messages (like, comment, retraction) to other servers if we are the thread owner * diff --git a/static/dbview.config.php b/static/dbview.config.php index cd835ddfae..ff8769a196 100644 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -37,101 +37,146 @@ */ return [ - "item-view" => [ + "post-view" => [ "fields" => [ - "id" => ["item", "id"], - "item_id" => ["item", "id"], - "uid" => ["item", "uid"], - "parent" => ["item", "parent"], - "uri" => ["item", "uri"], - "parent-uri" => ["item", "parent-uri"], + "id" => ["item", "id"], + "item_id" => ["item", "id"], + "uid" => ["item", "uid"], + "parent" => ["item", "parent"], + "uri" => ["item", "uri"], + "parent-uri" => ["item", "parent-uri"], "thr-parent" => ["item", "thr-parent"], - "guid" => ["item", "guid"], - "uri-id" => ["item", "uri-id"], - "parent-uri-id" => ["item", "parent-uri-id"], + "guid" => ["item", "guid"], + "uri-id" => ["item", "uri-id"], + "parent-uri-id" => ["item", "parent-uri-id"], "thr-parent-id" => ["item", "thr-parent-id"], - "contact-id" => ["item", "contact-id"], - "type" => ["item", "type"], - "wall" => ["item", "wall"], - "gravity" => ["item", "gravity"], - "extid" => ["item", "extid"], - "iaid" => ["item", "iaid"], - "icid" => ["item", "icid"], - "psid" => ["item", "psid"], - "created" => ["item", "created"], - "edited" => ["item", "edited"], - "commented" => ["item", "commented"], - "received" => ["item", "received"], - "changed" => ["item", "changed"], - "verb" => ["item-content", "verb"], - "plink" => ["item-content", "plink"], - "language" => ["item-content", "language"], - "resource-id" => ["item", "resource-id"], - "event-id" => ["item", "event-id"], - "attach" => ["item", "attach"], - "postopts" => ["post-delivery-data", "postopts"], - "inform" => ["post-delivery-data", "inform"], - "file" => "NULL", - "allow_cid" => ["permissionset", "allow_cid"], - "allow_gid" => ["permissionset", "allow_gid"], - "deny_cid" => ["permissionset", "deny_cid"], - "deny_gid" => ["permissionset", "deny_gid"], - "post-type" => ["item", "post-type"], - "private" => ["item", "private"], - "pubmail" => ["item", "pubmail"], - "moderated" => ["item", "moderated"], - "visible" => ["item", "visible"], - "starred" => ["item", "starred"], - "bookmark" => ["thread", "bookmark"], - "unseen" => ["item", "unseen"], - "deleted" => ["item", "deleted"], - "origin" => ["item", "origin"], - "forum_mode" => ["item", "forum_mode"], - "mention" => ["item", "mention"], - "global" => ["item", "global"], - "network" => ["item", "network"], - "title" => ["item-content", "title"], - "content-warning" => ["item-content", "content-warning"], - "body" => ["item-content", "body"], - "location" => ["item-content", "location"], - "coord" => ["item-content", "coord"], - "app" => ["item-content", "app"], - "rendered-hash" => ["item-content", "rendered-hash"], - "rendered-html" => ["item-content", "rendered-html"], - "object-type" => ["item-content", "object-type"], - "object" => ["item-content", "object"], - "target-type" => ["item-content", "target-type"], - "target" => ["item-content", "target"], - "author-id" => ["item", "author-id"], - "author-link" => ["author", "url"], - "author-name" => ["author", "name"], - "author-avatar" => ["author", "thumb"], - "author-network" => ["author", "network"], - "owner-id" => ["item", "owner-id"], - "owner-link" => ["owner", "url"], - "owner-addr" => ["owner", "addr"], - "owner-avatar" => ["owner", "thumb"], - "owner-nick" => ["owner", "nick"], - "owner-name" => ["owner", "name"], - "owner-network" => ["owner", "network"], + "contact-id" => ["item", "contact-id"], "contact-uid" => ["contact", "uid"], + "contact-link" => ["contact", "url"], + "contact-name" => ["contact", "name"], + "contact-avatar" => ["contact", "thumb"], + "writable" => ["contact", "writable"], + "self" => ["contact", "self"], + "cid" => ["contact", "id"], + "alias" => ["contact", "alias"], + "photo" => ["contact", "photo"], + "name-date" => ["contact", "name-date"], + "uri-date" => ["contact", "uri-date"], + "avatar-date" => ["contact", "avatar-date"], + "thumb" => ["contact", "thumb"], + "dfrn-id" => ["contact", "dfrn-id"], + "type" => ["item", "type"], + "wall" => ["item", "wall"], + "gravity" => ["item", "gravity"], + "extid" => ["item", "extid"], + "icid" => ["item", "icid"], + "vid" => ["item", "vid"], + "psid" => ["item", "psid"], + "created" => ["item", "created"], + "edited" => ["item", "edited"], + "commented" => ["item", "commented"], + "received" => ["item", "received"], + "changed" => ["item", "changed"], + "verb" => ["verb", "name"], + "plink" => ["item-content", "plink"], + "language" => ["item-content", "language"], + "raw-body" => ["item-content", "raw-body"], + "resource-id" => ["item", "resource-id"], + "event-id" => ["item", "event-id"], + "attach" => ["item", "attach"], + "postopts" => ["post-delivery-data", "postopts"], + "inform" => ["post-delivery-data", "inform"], + "file" => "NULL", + "allow_cid" => ["permissionset", "allow_cid"], + "allow_gid" => ["permissionset", "allow_gid"], + "deny_cid" => ["permissionset", "deny_cid"], + "deny_gid" => ["permissionset", "deny_gid"], + "post-type" => ["item", "post-type"], + "private" => ["item", "private"], + "pubmail" => ["item", "pubmail"], + "moderated" => ["item", "moderated"], + "visible" => ["item", "visible"], + "starred" => ["item", "starred"], + "bookmark" => ["item", "bookmark"], + "unseen" => ["item", "unseen"], + "deleted" => ["item", "deleted"], + "origin" => ["item", "origin"], + "forum_mode" => ["item", "forum_mode"], + "mention" => ["item", "mention"], + "global" => ["item", "global"], + "network" => ["item", "network"], + "title" => ["item-content", "title"], + "content-warning" => ["item-content", "content-warning"], + "body" => ["item-content", "body"], + "location" => ["item-content", "location"], + "coord" => ["item-content", "coord"], + "app" => ["item-content", "app"], + "rendered-hash" => ["item-content", "rendered-hash"], + "rendered-html" => ["item-content", "rendered-html"], + "object-type" => ["item-content", "object-type"], + "object" => ["item-content", "object"], + "target-type" => ["item-content", "target-type"], + "target" => ["item-content", "target"], + "author-id" => ["item", "author-id"], + "author-link" => ["author", "url"], + "author-addr" => ["author", "addr"], + "author-name" => ["author", "name"], + "author-nick" => ["author", "nick"], + "author-avatar" => ["author", "thumb"], + "author-network" => ["author", "network"], + "owner-id" => ["item", "owner-id"], + "owner-link" => ["owner", "url"], + "owner-addr" => ["owner", "addr"], + "owner-avatar" => ["owner", "thumb"], + "owner-nick" => ["owner", "nick"], + "owner-name" => ["owner", "name"], + "owner-network" => ["owner", "network"], + "causer-id" => ["item", "causer-id"], + "causer-link" => ["causer", "url"], + "causer-addr" => ["causer", "addr"], + "causer-name" => ["causer", "name"], + "causer-nick" => ["causer", "nick"], + "causer-avatar" => ["causer", "thumb"], + "causer-network" => ["causer", "network"], + "causer-contact-type" => ["causer", "contact-type"], + "event-id" => ["event"."id"], + "event-created" => ["event"."created"], + "event-edited" => ["event"."edited"], + "event-start" => ["event"."start"], + "event-finish" => ["event"."finish"], + "event-summary" => ["event"."summary"], + "event-desc" => ["event"."id"], + "event-location" => ["event"."location"], + "event-type" => ["event"."type"], + "event-nofinish" => ["event"."nofinish"], + "event-adjust" => ["event"."adjust"], + "event-ignore" => ["event"."ignore"], + "delivery_queue_count" => ["post-delivery-data"."queue_count"], + "delivery_queue_done" => ["post-delivery-data"."queue_done"], + "delivery_queue_failed" => ["post-delivery-data"."queue_failed"], "parent-guid" => ["parent-item", "guid"], "parent-network" => ["parent-item", "network"], + "parent-author-id" => ["parent-item", "author-id"], + "parent-author-link" => ["parent-item-author", "url"], + "parent-author-name" => ["parent-item-author", "name"], + "parent-author-network" => ["parent-item-author", "network"], "signed_text" => ["diaspora-interaction", "interaction"], - "signature" => "NULL", - "signer" => "NULL" ], "query" => "FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` LEFT JOIN `contact` AS `author` ON `author`.`id` = `item`.`author-id` LEFT JOIN `contact` AS `owner` ON `owner`.`id` = `item`.`owner-id` + LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `item`.`causer-id` + STRAIGHT_JOIN `group_member` ON `group_member`.`contact-id` = `item`.`contact-id` + STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid` + LEFT JOIN `event` ON `event-id` = `event`.`id` LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `item`.`uri-id` - LEFT JOIN `item-activity` ON `item-activity`.`uri-id` = `item`.`uri-id` LEFT JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id` LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `item`.`uri-id` AND `item`.`origin` + LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid` LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid` - LEFT JOIN `thread` ON `thread`.`iid` = `item`.`parent` - STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent`" + STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent` + STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`" ], "category-view" => [ "fields" => [ From 8e12dd1658ff33acc2783c85bd05ac5044384332 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 14 Jan 2021 14:45:40 +0000 Subject: [PATCH 04/10] Post view works now, "file" handling improved --- src/Model/Item.php | 6 +- src/Model/Post.php | 204 +++++++++++++++++++++++++++++++++++++++ static/dbview.config.php | 74 +++++++------- 3 files changed, 244 insertions(+), 40 deletions(-) create mode 100644 src/Model/Post.php diff --git a/src/Model/Item.php b/src/Model/Item.php index ee30f41ca0..60976363a6 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -262,7 +262,7 @@ class Item // We can always comment on posts from these networks if (array_key_exists('writable', $row) && in_array($row['internal-network'], Protocol::FEDERATED)) { - $row['writable'] = true; + $row['writable'] = 1; } // ---------------------- Transform item content data ---------------------- @@ -663,7 +663,7 @@ class Item 'resource-id', 'event-id', 'post-type', 'file', 'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark', 'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', - 'id' => 'item_id', 'network', 'icid', + 'id' => 'item_id', 'network', 'icid', 'event-id', 'uri-id' => 'internal-uri-id', 'uid' => 'internal-uid', 'network' => 'internal-network', 'psid' => 'internal-psid']; @@ -703,7 +703,7 @@ class Item 'summary' => 'event-summary','desc' => 'event-desc', 'location' => 'event-location', 'type' => 'event-type', 'nofinish' => 'event-nofinish','adjust' => 'event-adjust', - 'ignore' => 'event-ignore', 'id' => 'event-id']; + 'ignore' => 'event-ignore']; $fields['diaspora-interaction'] = ['interaction', 'interaction' => 'signed_text']; diff --git a/src/Model/Post.php b/src/Model/Post.php new file mode 100644 index 0000000000..d29728e490 --- /dev/null +++ b/src/Model/Post.php @@ -0,0 +1,204 @@ +. + * + */ + +namespace Friendica\Model; + +use Friendica\Core\Protocol; +use Friendica\Database\DBA; +use Friendica\Protocol\Activity; +use Friendica\Repository\PermissionSet; + +class Post +{ + /** + * Fetch a single post row + * + * @param mixed $stmt statement object + * @return array|false current row or false + * @throws \Exception + */ + public static function fetch($stmt) + { + $row = DBA::fetch($stmt); + + if (!is_array($row)) { + return $row; + } + + if (array_key_exists('verb', $row)) { + if (in_array($row['verb'], Item::ACTIVITIES)) { + if (array_key_exists('title', $row)) { + $row['title'] = ''; + } + if (array_key_exists('body', $row)) { + $row['body'] = $row['verb']; + } + if (array_key_exists('object', $row)) { + $row['object'] = ''; + } + if (array_key_exists('object-type', $row)) { + $row['object-type'] = Activity\ObjectType::NOTE; + } + } elseif (in_array($row['verb'], ['', Activity::POST, Activity::SHARE])) { + // Posts don't have a target - but having tags or files. + if (array_key_exists('target', $row)) { + $row['target'] = ''; + } + } + } + + if (!array_key_exists('verb', $row) || in_array($row['verb'], ['', Activity::POST, Activity::SHARE])) { + // Build the file string out of the term entries + if (array_key_exists('file', $row)) { + if ($row['internal-file-count'] > 0) { + $row['file'] = Post\Category::getTextByURIId($row['internal-uri-id'], $row['internal-uid']); + } else { + $row['file'] = ''; + } + } + } + + // Remove internal fields + unset($row['internal-file-count']); + unset($row['internal-uri-id']); + unset($row['internal-uid']); + + return $row; + } + + /** + * Fills an array with data from an post query + * + * @param object $stmt statement object + * @param bool $do_close + * @return array Data array + */ + public static function inArray($stmt, $do_close = true) { + if (is_bool($stmt)) { + return $stmt; + } + + $data = []; + while ($row = self::fetch($stmt)) { + $data[] = $row; + } + if ($do_close) { + DBA::close($stmt); + } + return $data; + } + + /** + * Check if post data exists + * + * @param array $condition array of fields for condition + * + * @return boolean Are there rows for that condition? + * @throws \Exception + */ + public static function exists($condition) { + $stmt = self::select(['id'], $condition, ['limit' => 1]); + + if (is_bool($stmt)) { + $retval = $stmt; + } else { + $retval = (DBA::numRows($stmt) > 0); + } + + DBA::close($stmt); + + return $retval; + } + + /** + * Retrieve a single record from the post table and returns it in an associative array + * + * @param array $fields + * @param array $condition + * @param array $params + * @return bool|array + * @throws \Exception + * @see DBA::select + */ + public static function selectFirst(array $fields = [], array $condition = [], $params = []) + { + $params['limit'] = 1; + + $result = self::select($fields, $condition, $params); + + if (is_bool($result)) { + return $result; + } else { + $row = self::fetch($result); + DBA::close($result); + return $row; + } + } + + /** + * Select rows from the post table and returns them as an array + * + * @param array $selected Array of selected fields, empty for all + * @param array $condition Array of fields for condition + * @param array $params Array of several parameters + * + * @return array + * @throws \Exception + */ + public static function selectToArray(array $fields = [], array $condition = [], $params = []) + { + $result = self::select($fields, $condition, $params); + + if (is_bool($result)) { + return []; + } + + $data = []; + while ($row = self::fetch($result)) { + $data[] = $row; + } + DBA::close($result); + + return $data; + } + + /** + * Select rows from the post table + * + * @param array $selected Array of selected fields, empty for all + * @param array $condition Array of fields for condition + * @param array $params Array of several parameters + * + * @return boolean|object + * @throws \Exception + */ + public static function select(array $selected = [], array $condition = [], $params = []) + { + if (empty($selected)) { + $selected = Item::DISPLAY_FIELDLIST; + } + + $selected = array_merge($selected, ['internal-uri-id', 'internal-uid', 'internal-file-count']); + $selected = array_unique($selected); + + return DBA::select('post-view', $selected, $condition, $params); + } +} diff --git a/static/dbview.config.php b/static/dbview.config.php index ff8769a196..111aa67a9d 100644 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -42,12 +42,14 @@ return [ "id" => ["item", "id"], "item_id" => ["item", "id"], "uid" => ["item", "uid"], + "internal-uid" => ["item", "uid"], "parent" => ["item", "parent"], "uri" => ["item", "uri"], "parent-uri" => ["item", "parent-uri"], "thr-parent" => ["item", "thr-parent"], "guid" => ["item", "guid"], "uri-id" => ["item", "uri-id"], + "internal-uri-id" => ["item", "uri-id"], "parent-uri-id" => ["item", "parent-uri-id"], "thr-parent-id" => ["item", "thr-parent-id"], "contact-id" => ["item", "contact-id"], @@ -55,7 +57,7 @@ return [ "contact-link" => ["contact", "url"], "contact-name" => ["contact", "name"], "contact-avatar" => ["contact", "thumb"], - "writable" => ["contact", "writable"], + "writable" => "IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`)", "self" => ["contact", "self"], "cid" => ["contact", "id"], "alias" => ["contact", "alias"], @@ -82,15 +84,15 @@ return [ "language" => ["item-content", "language"], "raw-body" => ["item-content", "raw-body"], "resource-id" => ["item", "resource-id"], - "event-id" => ["item", "event-id"], "attach" => ["item", "attach"], "postopts" => ["post-delivery-data", "postopts"], "inform" => ["post-delivery-data", "inform"], + "internal-file-count" => "(SELECT COUNT(*) FROM `post-category` WHERE `post-category`.`uri-id` = `item`.`uri-id`)", "file" => "NULL", - "allow_cid" => ["permissionset", "allow_cid"], - "allow_gid" => ["permissionset", "allow_gid"], - "deny_cid" => ["permissionset", "deny_cid"], - "deny_gid" => ["permissionset", "deny_gid"], + "allow_cid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_cid`)", + "allow_gid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_gid`)", + "deny_cid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_cid`)", + "deny_gid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_gid`)", "post-type" => ["item", "post-type"], "private" => ["item", "private"], "pubmail" => ["item", "pubmail"], @@ -120,16 +122,16 @@ return [ "author-id" => ["item", "author-id"], "author-link" => ["author", "url"], "author-addr" => ["author", "addr"], - "author-name" => ["author", "name"], + "author-name" => "IF (`contact`.`url` = `author`.`url`, `contact`.`name`, `author`.`name`)", "author-nick" => ["author", "nick"], - "author-avatar" => ["author", "thumb"], + "author-avatar" => "IF (`contact`.`url` = `author`.`url`, `contact`.`thumb`, `author`.`thumb`)", "author-network" => ["author", "network"], "owner-id" => ["item", "owner-id"], "owner-link" => ["owner", "url"], "owner-addr" => ["owner", "addr"], - "owner-avatar" => ["owner", "thumb"], + "owner-name" => "IF (`contact`.`url` = `owner`.`url`, `contact`.`name`, `owner`.`name`)", "owner-nick" => ["owner", "nick"], - "owner-name" => ["owner", "name"], + "owner-avatar" => "IF (`contact`.`url` = `owner`.`url`, `contact`.`thumb`, `owner`.`thumb`)", "owner-network" => ["owner", "network"], "causer-id" => ["item", "causer-id"], "causer-link" => ["causer", "url"], @@ -139,44 +141,42 @@ return [ "causer-avatar" => ["causer", "thumb"], "causer-network" => ["causer", "network"], "causer-contact-type" => ["causer", "contact-type"], - "event-id" => ["event"."id"], - "event-created" => ["event"."created"], - "event-edited" => ["event"."edited"], - "event-start" => ["event"."start"], - "event-finish" => ["event"."finish"], - "event-summary" => ["event"."summary"], - "event-desc" => ["event"."id"], - "event-location" => ["event"."location"], - "event-type" => ["event"."type"], - "event-nofinish" => ["event"."nofinish"], - "event-adjust" => ["event"."adjust"], - "event-ignore" => ["event"."ignore"], - "delivery_queue_count" => ["post-delivery-data"."queue_count"], - "delivery_queue_done" => ["post-delivery-data"."queue_done"], - "delivery_queue_failed" => ["post-delivery-data"."queue_failed"], + "event-id" => ["item", "event-id"], + "event-created" => ["event", "created"], + "event-edited" => ["event", "edited"], + "event-start" => ["event", "start"], + "event-finish" => ["event", "finish"], + "event-summary" => ["event", "summary"], + "event-desc" => ["event", "desc"], + "event-location" => ["event", "location"], + "event-type" => ["event", "type"], + "event-nofinish" => ["event", "nofinish"], + "event-adjust" => ["event", "adjust"], + "event-ignore" => ["event", "ignore"], + "delivery_queue_count" => ["post-delivery-data", "queue_count"], + "delivery_queue_done" => ["post-delivery-data", "queue_done"], + "delivery_queue_failed" => ["post-delivery-data", "queue_failed"], + "signed_text" => ["diaspora-interaction", "interaction"], "parent-guid" => ["parent-item", "guid"], "parent-network" => ["parent-item", "network"], "parent-author-id" => ["parent-item", "author-id"], "parent-author-link" => ["parent-item-author", "url"], "parent-author-name" => ["parent-item-author", "name"], "parent-author-network" => ["parent-item-author", "network"], - "signed_text" => ["diaspora-interaction", "interaction"], ], "query" => "FROM `item` - LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` - LEFT JOIN `contact` AS `author` ON `author`.`id` = `item`.`author-id` - LEFT JOIN `contact` AS `owner` ON `owner`.`id` = `item`.`owner-id` - LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `item`.`causer-id` - STRAIGHT_JOIN `group_member` ON `group_member`.`contact-id` = `item`.`contact-id` - STRAIGHT_JOIN `user` ON `user`.`uid` = `item`.`uid` - LEFT JOIN `event` ON `event-id` = `event`.`id` + STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `item`.`author-id` + STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `item`.`owner-id` + STRAIGHT_JOIN `contact` AS `causer` ON `causer`.`id` = `item`.`causer-id` + LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid` + STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent` + STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id` + LEFT JOIN `event` ON `event`.`id` = `item`.`event-id` LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `item`.`uri-id` LEFT JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id` LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `item`.`uri-id` AND `item`.`origin` - LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid` - LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid` - STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent` - STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`" + LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid`" ], "category-view" => [ "fields" => [ From 55204d26b1a2f7a9f263277aa7802604eb744546 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 14 Jan 2021 14:51:04 +0000 Subject: [PATCH 05/10] Added function to count posts --- src/Model/Post.php | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Model/Post.php b/src/Model/Post.php index d29728e490..85f69826c4 100644 --- a/src/Model/Post.php +++ b/src/Model/Post.php @@ -115,17 +115,28 @@ class Post * @throws \Exception */ public static function exists($condition) { - $stmt = self::select(['id'], $condition, ['limit' => 1]); + return DBA::exists('post-view', $condition); + } - if (is_bool($stmt)) { - $retval = $stmt; - } else { - $retval = (DBA::numRows($stmt) > 0); - } - - DBA::close($stmt); - - return $retval; + /** + * Counts the posts satisfying the provided condition + * + * @param array $condition array of fields for condition + * @param array $params Array of several parameters + * + * @return int + * + * Example: + * $condition = ["uid" => 1, "network" => 'dspr']; + * or: + * $condition = ["`uid` = ? AND `network` IN (?, ?)", 1, 'dfrn', 'dspr']; + * + * $count = Post::count($condition); + * @throws \Exception + */ + public static function count(array $condition = [], array $params = []) + { + return DBA::count('post-view', $condition, $params); } /** From 49d9cbb627de22e08a4f52a328d47e15ac4cb962 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 14 Jan 2021 21:32:59 +0000 Subject: [PATCH 06/10] Rearrangements, adding user-item --- static/dbview.config.php | 92 ++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 42 deletions(-) diff --git a/static/dbview.config.php b/static/dbview.config.php index 111aa67a9d..b9b373a8bc 100644 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -45,54 +45,23 @@ return [ "internal-uid" => ["item", "uid"], "parent" => ["item", "parent"], "uri" => ["item", "uri"], - "parent-uri" => ["item", "parent-uri"], - "thr-parent" => ["item", "thr-parent"], - "guid" => ["item", "guid"], "uri-id" => ["item", "uri-id"], "internal-uri-id" => ["item", "uri-id"], + "parent-uri" => ["item", "parent-uri"], "parent-uri-id" => ["item", "parent-uri-id"], + "thr-parent" => ["item", "thr-parent"], "thr-parent-id" => ["item", "thr-parent-id"], - "contact-id" => ["item", "contact-id"], - "contact-uid" => ["contact", "uid"], - "contact-link" => ["contact", "url"], - "contact-name" => ["contact", "name"], - "contact-avatar" => ["contact", "thumb"], - "writable" => "IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`)", - "self" => ["contact", "self"], - "cid" => ["contact", "id"], - "alias" => ["contact", "alias"], - "photo" => ["contact", "photo"], - "name-date" => ["contact", "name-date"], - "uri-date" => ["contact", "uri-date"], - "avatar-date" => ["contact", "avatar-date"], - "thumb" => ["contact", "thumb"], - "dfrn-id" => ["contact", "dfrn-id"], + "guid" => ["item", "guid"], "type" => ["item", "type"], "wall" => ["item", "wall"], "gravity" => ["item", "gravity"], "extid" => ["item", "extid"], - "icid" => ["item", "icid"], - "vid" => ["item", "vid"], - "psid" => ["item", "psid"], "created" => ["item", "created"], "edited" => ["item", "edited"], "commented" => ["item", "commented"], "received" => ["item", "received"], "changed" => ["item", "changed"], - "verb" => ["verb", "name"], - "plink" => ["item-content", "plink"], - "language" => ["item-content", "language"], - "raw-body" => ["item-content", "raw-body"], "resource-id" => ["item", "resource-id"], - "attach" => ["item", "attach"], - "postopts" => ["post-delivery-data", "postopts"], - "inform" => ["post-delivery-data", "inform"], - "internal-file-count" => "(SELECT COUNT(*) FROM `post-category` WHERE `post-category`.`uri-id` = `item`.`uri-id`)", - "file" => "NULL", - "allow_cid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_cid`)", - "allow_gid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_gid`)", - "deny_cid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_cid`)", - "deny_gid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_gid`)", "post-type" => ["item", "post-type"], "private" => ["item", "private"], "pubmail" => ["item", "pubmail"], @@ -107,18 +76,46 @@ return [ "mention" => ["item", "mention"], "global" => ["item", "global"], "network" => ["item", "network"], + "icid" => ["item", "icid"], + "vid" => ["item", "vid"], + "psid" => ["item", "psid"], + "attach" => ["item", "attach"], + "internal-file-count" => "(SELECT COUNT(*) FROM `post-category` WHERE `post-category`.`uri-id` = `item`.`uri-id`)", + "file" => "NULL", + "verb" => "IF (`item`.`vid` IS NULL, '', `verb`.`name`)", "title" => ["item-content", "title"], "content-warning" => ["item-content", "content-warning"], + "raw-body" => ["item-content", "raw-body"], "body" => ["item-content", "body"], + "rendered-hash" => ["item-content", "rendered-hash"], + "rendered-html" => ["item-content", "rendered-html"], + "language" => ["item-content", "language"], + "plink" => ["item-content", "plink"], "location" => ["item-content", "location"], "coord" => ["item-content", "coord"], "app" => ["item-content", "app"], - "rendered-hash" => ["item-content", "rendered-hash"], - "rendered-html" => ["item-content", "rendered-html"], "object-type" => ["item-content", "object-type"], "object" => ["item-content", "object"], "target-type" => ["item-content", "target-type"], "target" => ["item-content", "target"], + "contact-id" => ["item", "contact-id"], + "contact-link" => ["contact", "url"], + "contact-addr" => ["contact", "addr"], + "contact-name" => ["contact", "name"], + "contact-nick" => ["contact", "nick"], + "contact-avatar" => ["contact", "thumb"], + "contact-network" => ["contact", "network"], + "contact-uid" => ["contact", "uid"], + "writable" => "IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`)", + "self" => ["contact", "self"], + "cid" => ["contact", "id"], + "alias" => ["contact", "alias"], + "photo" => ["contact", "photo"], + "name-date" => ["contact", "name-date"], + "uri-date" => ["contact", "uri-date"], + "avatar-date" => ["contact", "avatar-date"], + "thumb" => ["contact", "thumb"], + "dfrn-id" => ["contact", "dfrn-id"], "author-id" => ["item", "author-id"], "author-link" => ["author", "url"], "author-addr" => ["author", "addr"], @@ -141,6 +138,19 @@ return [ "causer-avatar" => ["causer", "thumb"], "causer-network" => ["causer", "network"], "causer-contact-type" => ["causer", "contact-type"], + "postopts" => ["post-delivery-data", "postopts"], + "inform" => ["post-delivery-data", "inform"], + "delivery_queue_count" => ["post-delivery-data", "queue_count"], + "delivery_queue_done" => ["post-delivery-data", "queue_done"], + "delivery_queue_failed" => ["post-delivery-data", "queue_failed"], + "allow_cid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_cid`)", + "allow_gid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_gid`)", + "deny_cid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_cid`)", + "deny_gid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_gid`)", + "pinned" => ["user-item", "pinned"], + "hidden" => ["user-item", "hidden"], + "ignored" => ["user-item", "ignored"], + "notification-type" => ["user-item", "notification-type"], "event-id" => ["item", "event-id"], "event-created" => ["event", "created"], "event-edited" => ["event", "edited"], @@ -153,9 +163,6 @@ return [ "event-nofinish" => ["event", "nofinish"], "event-adjust" => ["event", "adjust"], "event-ignore" => ["event", "ignore"], - "delivery_queue_count" => ["post-delivery-data", "queue_count"], - "delivery_queue_done" => ["post-delivery-data", "queue_done"], - "delivery_queue_failed" => ["post-delivery-data", "queue_failed"], "signed_text" => ["diaspora-interaction", "interaction"], "parent-guid" => ["parent-item", "guid"], "parent-network" => ["parent-item", "network"], @@ -170,13 +177,14 @@ return [ STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `item`.`owner-id` STRAIGHT_JOIN `contact` AS `causer` ON `causer`.`id` = `item`.`causer-id` LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid` - STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent` - STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id` LEFT JOIN `event` ON `event`.`id` = `item`.`event-id` LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `item`.`uri-id` LEFT JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id` LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `item`.`uri-id` AND `item`.`origin` - LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid`" + LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid` + LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` + STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent` + STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`" ], "category-view" => [ "fields" => [ From f4addd337dee38a84c9d5c9011c14e47e735cc52 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 14 Jan 2021 22:51:44 +0000 Subject: [PATCH 07/10] New database version, fixes to empty field list --- database.sql | 153 +++++++++++++++++++++++++++++++++- src/Model/Post.php | 5 +- static/dbstructure.config.php | 2 +- 3 files changed, 157 insertions(+), 3 deletions(-) diff --git a/database.sql b/database.sql index 1d4f335e4a..fdcc1ffe14 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2021.03-dev (Red Hot Poker) --- DB_UPDATE_VERSION 1385 +-- DB_UPDATE_VERSION 1386 -- ------------------------------------------ @@ -1488,6 +1488,157 @@ CREATE TABLE IF NOT EXISTS `workerqueue` ( INDEX `done_pid_priority_created` (`done`,`pid`,`priority`,`created`) ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Background tasks queue entries'; +-- +-- VIEW post-view +-- +DROP VIEW IF EXISTS `post-view`; +CREATE VIEW `post-view` AS SELECT + `item`.`id` AS `id`, + `item`.`id` AS `item_id`, + `item`.`uid` AS `uid`, + `item`.`uid` AS `internal-uid`, + `item`.`parent` AS `parent`, + `item`.`uri` AS `uri`, + `item`.`uri-id` AS `uri-id`, + `item`.`uri-id` AS `internal-uri-id`, + `item`.`parent-uri` AS `parent-uri`, + `item`.`parent-uri-id` AS `parent-uri-id`, + `item`.`thr-parent` AS `thr-parent`, + `item`.`thr-parent-id` AS `thr-parent-id`, + `item`.`guid` AS `guid`, + `item`.`type` AS `type`, + `item`.`wall` AS `wall`, + `item`.`gravity` AS `gravity`, + `item`.`extid` AS `extid`, + `item`.`created` AS `created`, + `item`.`edited` AS `edited`, + `item`.`commented` AS `commented`, + `item`.`received` AS `received`, + `item`.`changed` AS `changed`, + `item`.`resource-id` AS `resource-id`, + `item`.`post-type` AS `post-type`, + `item`.`private` AS `private`, + `item`.`pubmail` AS `pubmail`, + `item`.`moderated` AS `moderated`, + `item`.`visible` AS `visible`, + `item`.`starred` AS `starred`, + `item`.`bookmark` AS `bookmark`, + `item`.`unseen` AS `unseen`, + `item`.`deleted` AS `deleted`, + `item`.`origin` AS `origin`, + `item`.`forum_mode` AS `forum_mode`, + `item`.`mention` AS `mention`, + `item`.`global` AS `global`, + `item`.`network` AS `network`, + `item`.`icid` AS `icid`, + `item`.`vid` AS `vid`, + `item`.`psid` AS `psid`, + `item`.`attach` AS `attach`, + (SELECT COUNT(*) FROM `post-category` WHERE `post-category`.`uri-id` = `item`.`uri-id`) AS `internal-file-count`, + NULL AS `file`, + IF (`item`.`vid` IS NULL, '', `verb`.`name`) AS `verb`, + `item-content`.`title` AS `title`, + `item-content`.`content-warning` AS `content-warning`, + `item-content`.`raw-body` AS `raw-body`, + `item-content`.`body` AS `body`, + `item-content`.`rendered-hash` AS `rendered-hash`, + `item-content`.`rendered-html` AS `rendered-html`, + `item-content`.`language` AS `language`, + `item-content`.`plink` AS `plink`, + `item-content`.`location` AS `location`, + `item-content`.`coord` AS `coord`, + `item-content`.`app` AS `app`, + `item-content`.`object-type` AS `object-type`, + `item-content`.`object` AS `object`, + `item-content`.`target-type` AS `target-type`, + `item-content`.`target` AS `target`, + `item`.`contact-id` AS `contact-id`, + `contact`.`url` AS `contact-link`, + `contact`.`addr` AS `contact-addr`, + `contact`.`name` AS `contact-name`, + `contact`.`nick` AS `contact-nick`, + `contact`.`thumb` AS `contact-avatar`, + `contact`.`network` AS `contact-network`, + `contact`.`uid` AS `contact-uid`, + IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`, + `contact`.`self` AS `self`, + `contact`.`id` AS `cid`, + `contact`.`alias` AS `alias`, + `contact`.`photo` AS `photo`, + `contact`.`name-date` AS `name-date`, + `contact`.`uri-date` AS `uri-date`, + `contact`.`avatar-date` AS `avatar-date`, + `contact`.`thumb` AS `thumb`, + `contact`.`dfrn-id` AS `dfrn-id`, + `item`.`author-id` AS `author-id`, + `author`.`url` AS `author-link`, + `author`.`addr` AS `author-addr`, + IF (`contact`.`url` = `author`.`url`, `contact`.`name`, `author`.`name`) AS `author-name`, + `author`.`nick` AS `author-nick`, + IF (`contact`.`url` = `author`.`url`, `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`, + `author`.`network` AS `author-network`, + `item`.`owner-id` AS `owner-id`, + `owner`.`url` AS `owner-link`, + `owner`.`addr` AS `owner-addr`, + IF (`contact`.`url` = `owner`.`url`, `contact`.`name`, `owner`.`name`) AS `owner-name`, + `owner`.`nick` AS `owner-nick`, + IF (`contact`.`url` = `owner`.`url`, `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`, + `owner`.`network` AS `owner-network`, + `item`.`causer-id` AS `causer-id`, + `causer`.`url` AS `causer-link`, + `causer`.`addr` AS `causer-addr`, + `causer`.`name` AS `causer-name`, + `causer`.`nick` AS `causer-nick`, + `causer`.`thumb` AS `causer-avatar`, + `causer`.`network` AS `causer-network`, + `causer`.`contact-type` AS `causer-contact-type`, + `post-delivery-data`.`postopts` AS `postopts`, + `post-delivery-data`.`inform` AS `inform`, + `post-delivery-data`.`queue_count` AS `delivery_queue_count`, + `post-delivery-data`.`queue_done` AS `delivery_queue_done`, + `post-delivery-data`.`queue_failed` AS `delivery_queue_failed`, + IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_cid`) AS `allow_cid`, + IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`, + IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`, + IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`, + `user-item`.`pinned` AS `pinned`, + `user-item`.`hidden` AS `hidden`, + `user-item`.`ignored` AS `ignored`, + `user-item`.`notification-type` AS `notification-type`, + `item`.`event-id` AS `event-id`, + `event`.`created` AS `event-created`, + `event`.`edited` AS `event-edited`, + `event`.`start` AS `event-start`, + `event`.`finish` AS `event-finish`, + `event`.`summary` AS `event-summary`, + `event`.`desc` AS `event-desc`, + `event`.`location` AS `event-location`, + `event`.`type` AS `event-type`, + `event`.`nofinish` AS `event-nofinish`, + `event`.`adjust` AS `event-adjust`, + `event`.`ignore` AS `event-ignore`, + `diaspora-interaction`.`interaction` AS `signed_text`, + `parent-item`.`guid` AS `parent-guid`, + `parent-item`.`network` AS `parent-network`, + `parent-item`.`author-id` AS `parent-author-id`, + `parent-item-author`.`url` AS `parent-author-link`, + `parent-item-author`.`name` AS `parent-author-name`, + `parent-item-author`.`network` AS `parent-author-network` + FROM `item` + STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id` + STRAIGHT_JOIN `contact` AS `author` ON `author`.`id` = `item`.`author-id` + STRAIGHT_JOIN `contact` AS `owner` ON `owner`.`id` = `item`.`owner-id` + STRAIGHT_JOIN `contact` AS `causer` ON `causer`.`id` = `item`.`causer-id` + LEFT JOIN `verb` ON `verb`.`id` = `item`.`vid` + LEFT JOIN `event` ON `event`.`id` = `item`.`event-id` + LEFT JOIN `diaspora-interaction` ON `diaspora-interaction`.`uri-id` = `item`.`uri-id` + LEFT JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id` + LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `item`.`uri-id` AND `item`.`origin` + LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid` + LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` + STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent` + STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`; + -- -- VIEW category-view -- diff --git a/src/Model/Post.php b/src/Model/Post.php index 85f69826c4..981c7071dc 100644 --- a/src/Model/Post.php +++ b/src/Model/Post.php @@ -204,7 +204,10 @@ class Post public static function select(array $selected = [], array $condition = [], $params = []) { if (empty($selected)) { - $selected = Item::DISPLAY_FIELDLIST; + $selected = array_merge(['author-addr', 'author-nick', 'owner-addr', 'owner-nick', 'causer-addr', 'causer-nick', + 'causer-network', 'photo', 'name-date', 'uri-date', 'avatar-date', 'thumb', 'dfrn-id', + 'parent-guid', 'parent-network', 'parent-author-id', 'parent-author-link', 'parent-author-name', + 'parent-author-network', 'signed_text'], Item::DISPLAY_FIELDLIST, Item::ITEM_FIELDLIST, Item::CONTENT_FIELDLIST); } $selected = array_merge($selected, ['internal-uri-id', 'internal-uid', 'internal-file-count']); diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index b12ac56b28..27752fb721 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -55,7 +55,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1385); + define('DB_UPDATE_VERSION', 1386); } return [ From a19e41100034ee80fb7c5b955227b8741c0626fe Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 15 Jan 2021 09:13:18 +0000 Subject: [PATCH 08/10] User-Item is not needed --- database.sql | 5 ----- static/dbview.config.php | 5 ----- 2 files changed, 10 deletions(-) diff --git a/database.sql b/database.sql index fdcc1ffe14..47d76fdf6d 100644 --- a/database.sql +++ b/database.sql @@ -1601,10 +1601,6 @@ CREATE VIEW `post-view` AS SELECT IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_gid`) AS `allow_gid`, IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_cid`) AS `deny_cid`, IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_gid`) AS `deny_gid`, - `user-item`.`pinned` AS `pinned`, - `user-item`.`hidden` AS `hidden`, - `user-item`.`ignored` AS `ignored`, - `user-item`.`notification-type` AS `notification-type`, `item`.`event-id` AS `event-id`, `event`.`created` AS `event-created`, `event`.`edited` AS `event-edited`, @@ -1635,7 +1631,6 @@ CREATE VIEW `post-view` AS SELECT LEFT JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id` LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `item`.`uri-id` AND `item`.`origin` LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid` - LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent` STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`; diff --git a/static/dbview.config.php b/static/dbview.config.php index b9b373a8bc..63f5de8222 100644 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -147,10 +147,6 @@ return [ "allow_gid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`allow_gid`)", "deny_cid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_cid`)", "deny_gid" => "IF (`item`.`psid` IS NULL, '', `permissionset`.`deny_gid`)", - "pinned" => ["user-item", "pinned"], - "hidden" => ["user-item", "hidden"], - "ignored" => ["user-item", "ignored"], - "notification-type" => ["user-item", "notification-type"], "event-id" => ["item", "event-id"], "event-created" => ["event", "created"], "event-edited" => ["event", "edited"], @@ -182,7 +178,6 @@ return [ LEFT JOIN `item-content` ON `item-content`.`uri-id` = `item`.`uri-id` LEFT JOIN `post-delivery-data` ON `post-delivery-data`.`uri-id` = `item`.`uri-id` AND `item`.`origin` LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid` - LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent` STRAIGHT_JOIN `contact` AS `parent-item-author` ON `parent-item-author`.`id` = `parent-item`.`author-id`" ], From 4cc52cef6b84e02687be5e306ef333060dcc8f53 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 15 Jan 2021 11:31:24 +0000 Subject: [PATCH 09/10] Added "blocked" fields --- database.sql | 4 ++++ static/dbview.config.php | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/database.sql b/database.sql index 47d76fdf6d..65da2f7cff 100644 --- a/database.sql +++ b/database.sql @@ -1559,6 +1559,7 @@ CREATE VIEW `post-view` AS SELECT `contact`.`nick` AS `contact-nick`, `contact`.`thumb` AS `contact-avatar`, `contact`.`network` AS `contact-network`, + `contact`.`blocked` AS `contact-blocked`, `contact`.`uid` AS `contact-uid`, IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`, `contact`.`self` AS `self`, @@ -1577,6 +1578,7 @@ CREATE VIEW `post-view` AS SELECT `author`.`nick` AS `author-nick`, IF (`contact`.`url` = `author`.`url`, `contact`.`thumb`, `author`.`thumb`) AS `author-avatar`, `author`.`network` AS `author-network`, + `author`.`blocked` AS `author-blocked`, `item`.`owner-id` AS `owner-id`, `owner`.`url` AS `owner-link`, `owner`.`addr` AS `owner-addr`, @@ -1584,6 +1586,7 @@ CREATE VIEW `post-view` AS SELECT `owner`.`nick` AS `owner-nick`, IF (`contact`.`url` = `owner`.`url`, `contact`.`thumb`, `owner`.`thumb`) AS `owner-avatar`, `owner`.`network` AS `owner-network`, + `owner`.`blocked` AS `owner-blocked`, `item`.`causer-id` AS `causer-id`, `causer`.`url` AS `causer-link`, `causer`.`addr` AS `causer-addr`, @@ -1591,6 +1594,7 @@ CREATE VIEW `post-view` AS SELECT `causer`.`nick` AS `causer-nick`, `causer`.`thumb` AS `causer-avatar`, `causer`.`network` AS `causer-network`, + `causer`.`blocked` AS `causer-blocked`, `causer`.`contact-type` AS `causer-contact-type`, `post-delivery-data`.`postopts` AS `postopts`, `post-delivery-data`.`inform` AS `inform`, diff --git a/static/dbview.config.php b/static/dbview.config.php index 63f5de8222..9dc7791f73 100644 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -105,6 +105,7 @@ return [ "contact-nick" => ["contact", "nick"], "contact-avatar" => ["contact", "thumb"], "contact-network" => ["contact", "network"], + "contact-blocked" => ["contact", "blocked"], "contact-uid" => ["contact", "uid"], "writable" => "IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`)", "self" => ["contact", "self"], @@ -123,6 +124,7 @@ return [ "author-nick" => ["author", "nick"], "author-avatar" => "IF (`contact`.`url` = `author`.`url`, `contact`.`thumb`, `author`.`thumb`)", "author-network" => ["author", "network"], + "author-blocked" => ["author", "blocked"], "owner-id" => ["item", "owner-id"], "owner-link" => ["owner", "url"], "owner-addr" => ["owner", "addr"], @@ -130,6 +132,7 @@ return [ "owner-nick" => ["owner", "nick"], "owner-avatar" => "IF (`contact`.`url` = `owner`.`url`, `contact`.`thumb`, `owner`.`thumb`)", "owner-network" => ["owner", "network"], + "owner-blocked" => ["owner", "blocked"], "causer-id" => ["item", "causer-id"], "causer-link" => ["causer", "url"], "causer-addr" => ["causer", "addr"], @@ -137,6 +140,7 @@ return [ "causer-nick" => ["causer", "nick"], "causer-avatar" => ["causer", "thumb"], "causer-network" => ["causer", "network"], + "causer-blocked" => ["causer", "blocked"], "causer-contact-type" => ["causer", "contact-type"], "postopts" => ["post-delivery-data", "postopts"], "inform" => ["post-delivery-data", "inform"], From 3ab4e20fe6050ac72201310fdc049dc023d64d24 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 15 Jan 2021 11:46:57 +0000 Subject: [PATCH 10/10] Some more fields that will be needed for the user query --- database.sql | 3 +++ static/dbview.config.php | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/database.sql b/database.sql index 65da2f7cff..226c151335 100644 --- a/database.sql +++ b/database.sql @@ -1560,6 +1560,9 @@ CREATE VIEW `post-view` AS SELECT `contact`.`thumb` AS `contact-avatar`, `contact`.`network` AS `contact-network`, `contact`.`blocked` AS `contact-blocked`, + `contact`.`readonly` AS `contact-readonly`, + `contact`.`pending` AS `contact-pending`, + `contact`.`rel` AS `contact-rel`, `contact`.`uid` AS `contact-uid`, IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`) AS `writable`, `contact`.`self` AS `self`, diff --git a/static/dbview.config.php b/static/dbview.config.php index 9dc7791f73..b0bf7ed615 100644 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -36,7 +36,7 @@ * */ -return [ + return [ "post-view" => [ "fields" => [ "id" => ["item", "id"], @@ -106,6 +106,9 @@ return [ "contact-avatar" => ["contact", "thumb"], "contact-network" => ["contact", "network"], "contact-blocked" => ["contact", "blocked"], + "contact-readonly" => ["contact", "readonly"], + "contact-pending" => ["contact", "pending"], + "contact-rel" => ["contact", "rel"], "contact-uid" => ["contact", "uid"], "writable" => "IF (`item`.`network` IN ('apub', 'dfrn', 'dspr', 'stat'), true, `contact`.`writable`)", "self" => ["contact", "self"],