From 3258216e8d0b012645f56ff0d21e5f3b9e250e28 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 28 May 2020 21:44:55 +0000 Subject: [PATCH 1/3] Add "uri-id" to the "thread" table --- src/Model/Item.php | 4 ++-- static/dbstructure.config.php | 4 +++- update.php | 11 ++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index a6036e6bdb..f014ed096e 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -3110,7 +3110,7 @@ class Item private static function addThread($itemid, $onlyshadow = false) { $fields = ['uid', 'created', 'edited', 'commented', 'received', 'changed', 'wall', 'private', 'pubmail', - 'moderated', 'visible', 'starred', 'contact-id', 'post-type', + 'moderated', 'visible', 'starred', 'contact-id', 'post-type', 'uri-id', 'deleted', 'origin', 'forum_mode', 'mention', 'network', 'author-id', 'owner-id']; $condition = ["`id` = ? AND (`parent` = ? OR `parent` = 0)", $itemid, $itemid]; $item = self::selectFirst($fields, $condition); @@ -3131,7 +3131,7 @@ class Item private static function updateThread($itemid, $setmention = false) { $fields = ['uid', 'guid', 'created', 'edited', 'commented', 'received', 'changed', 'post-type', - 'wall', 'private', 'pubmail', 'moderated', 'visible', 'starred', 'contact-id', + 'wall', 'private', 'pubmail', 'moderated', 'visible', 'starred', 'contact-id', 'uri-id', 'deleted', 'origin', 'forum_mode', 'network', 'author-id', 'owner-id']; $condition = ["`id` = ? AND (`parent` = ? OR `parent` = 0)", $itemid, $itemid]; diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index fc7abded50..9fccdf14b6 100755 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -54,7 +54,7 @@ use Friendica\Database\DBA; if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1350); + define('DB_UPDATE_VERSION', 1351); } return [ @@ -1343,6 +1343,7 @@ return [ "fields" => [ "iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["item" => "id"], "comment" => "sequential ID"], + "uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the item uri"], "uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"], "contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""], "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Item owner"], @@ -1381,6 +1382,7 @@ return [ "uid_commented" => ["uid", "commented"], "uid_wall_received" => ["uid", "wall", "received"], "private_wall_origin_commented" => ["private", "wall", "origin", "commented"], + "uri-id" => ["uri-id"], ] ], "tokens" => [ diff --git a/update.php b/update.php index 48d44813b1..acbb458f7f 100644 --- a/update.php +++ b/update.php @@ -498,4 +498,13 @@ function update_1349() } return Update::SUCCESS; -} \ No newline at end of file +} + +function update_1351() +{ + if (!DBA::e("UPDATE `thread` INNER JOIN `item` ON `thread`.`iid` = `item`.`id` SET `thread`.`uri-id` = `item`.`uri-id`")) { + return Update::FAILED; + } + + return Update::SUCCESS; +} From 64f3dd419c7ed59f9fc8cc0000ff756f781f5e24 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 29 May 2020 02:19:58 +0000 Subject: [PATCH 2/3] Updated database description --- database.sql | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/database.sql b/database.sql index bcd8c9843d..f4bbebf081 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2020.06-dev (Red Hot Poker) --- DB_UPDATE_VERSION 1350 +-- DB_UPDATE_VERSION 1351 -- ------------------------------------------ @@ -1237,6 +1237,7 @@ CREATE TABLE IF NOT EXISTS `storage` ( -- CREATE TABLE IF NOT EXISTS `thread` ( `iid` int unsigned NOT NULL DEFAULT 0 COMMENT 'sequential ID', + `uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the item uri', `uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id', `contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '', `owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Item owner', @@ -1272,7 +1273,9 @@ CREATE TABLE IF NOT EXISTS `thread` ( INDEX `uid_received` (`uid`,`received`), INDEX `uid_commented` (`uid`,`commented`), INDEX `uid_wall_received` (`uid`,`wall`,`received`), - INDEX `private_wall_origin_commented` (`private`,`wall`,`origin`,`commented`) + INDEX `private_wall_origin_commented` (`private`,`wall`,`origin`,`commented`), + INDEX `uri-id` (`uri-id`), + FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Thread related data'; -- From 19f2a998d228c1485219c0e31af3eb35b38eef7f Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 29 May 2020 02:25:17 +0000 Subject: [PATCH 3/3] Added new field to the test data --- tests/datasets/api.fixture.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index 8713b1ff36..54d4f4d3cf 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -268,6 +268,7 @@ return [ 'thread' => [ [ 'iid' => 1, + 'uri-id' => 1, 'visible' => 1, 'contact-id' => 42, 'author-id' => 42, @@ -277,6 +278,7 @@ return [ ], [ 'iid' => 3, + 'uri-id' => 3, 'visible' => 1, 'contact-id' => 43, 'author-id' => 43, @@ -286,6 +288,7 @@ return [ ], [ 'iid' => 6, + 'uri-id' => 6, 'visible' => 1, 'contact-id' => 44, 'author-id' => 44,