diff --git a/database.sql b/database.sql index 499ac3b033..f598ab9ccb 100644 --- a/database.sql +++ b/database.sql @@ -740,9 +740,11 @@ CREATE TABLE IF NOT EXISTS `item` ( INDEX `uri-id` (`uri-id`), INDEX `parent-uri-id` (`parent-uri-id`), INDEX `thr-parent-id` (`thr-parent-id`), + INDEX `causer-id` (`causer-id`), FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE, FOREIGN KEY (`parent-uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE, FOREIGN KEY (`thr-parent-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE, + FOREIGN KEY (`causer-id`) REFERENCES `contact` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT, FOREIGN KEY (`psid`) REFERENCES `permissionset` (`id`) ON UPDATE RESTRICT ON DELETE RESTRICT ) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Structure for all posts'; diff --git a/src/Model/Item.php b/src/Model/Item.php index 970c5f4a56..d03e9ec354 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -775,7 +775,7 @@ class Item } } if (strpos($sql_commands, "`causer`.") !== false) { - $joins .= " LEFT JOIN `contact` AS `causer` ON `causer`.`id` = $master_table.`causer-id`"; + $joins .= " LEFT JOIN `contact` AS `causer` ON `causer`.`id` = `item`.`causer-id`"; } if (strpos($sql_commands, "`group_member`.") !== false) { diff --git a/src/Worker/MergeContact.php b/src/Worker/MergeContact.php index 3bb4e7e689..e04dfb6ac8 100644 --- a/src/Worker/MergeContact.php +++ b/src/Worker/MergeContact.php @@ -55,6 +55,7 @@ class MergeContact DBA::delete('post-tag', ['cid' => $old_cid]); DBA::update('item', ['author-id' => $new_cid], ['author-id' => $old_cid]); DBA::update('item', ['owner-id' => $new_cid], ['owner-id' => $old_cid]); + DBA::update('item', ['causer-id' => $new_cid], ['causer-id' => $old_cid]); DBA::update('thread', ['author-id' => $new_cid], ['author-id' => $old_cid]); DBA::update('thread', ['owner-id' => $new_cid], ['owner-id' => $old_cid]); } else { diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 2e53649b97..7e69ec034c 100755 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -722,7 +722,7 @@ return [ "network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => "Network from where the item comes from"], "owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Link to the contact table with uid=0 of the owner of this item"], "author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Link to the contact table with uid=0 of the author of this item"], - "causer-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"], + "causer-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id", "on delete" => "restrict"], "comment" => "Link to the contact table with uid=0 of the contact that caused the item creation"], "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"], "vid" => ["type" => "smallint unsigned", "relation" => ["verb" => "id"], "comment" => "Id of the verb table entry that contains the activity verbs"], @@ -814,6 +814,7 @@ return [ "uri-id" => ["uri-id"], "parent-uri-id" => ["parent-uri-id"], "thr-parent-id" => ["thr-parent-id"], + "causer-id" => ["causer-id"], ] ], "item-activity" => [