"id" is now post-user-id

This commit is contained in:
Michael 2021-02-14 18:33:15 +00:00
parent 6e1483545e
commit 36357e790e
9 changed files with 76 additions and 63 deletions

View file

@ -1232,7 +1232,7 @@ class DBStructure
} elseif ($verbose) { } elseif ($verbose) {
echo "Zero permissionset already added\n"; echo "Zero permissionset already added\n";
} }
if (!self::existsForeignKeyForField('item', 'psid')) { if (self::existsTable('item') && !self::existsForeignKeyForField('item', 'psid')) {
$sets = DBA::p("SELECT `psid`, `item`.`uid`, `item`.`private` FROM `item` $sets = DBA::p("SELECT `psid`, `item`.`uid`, `item`.`private` FROM `item`
LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid` LEFT JOIN `permissionset` ON `permissionset`.`id` = `item`.`psid`
WHERE `permissionset`.`id` IS NULL AND NOT `psid` IS NULL"); WHERE `permissionset`.`id` IS NULL AND NOT `psid` IS NULL");

View file

@ -179,6 +179,11 @@ class PostUpdate
return true; return true;
} }
if (!DBStructure::existsTable('item')) {
DI::config()->set('system', 'post_update_version', 1329);
return true;
}
$id = DI::config()->get('system', 'post_update_version_1329_id', 0); $id = DI::config()->get('system', 'post_update_version_1329_id', 0);
Logger::info('Start', ['item' => $id]); Logger::info('Start', ['item' => $id]);
@ -514,7 +519,7 @@ class PostUpdate
return true; return true;
} }
if (!DBStructure::existsTable('item-activity')) { if (!DBStructure::existsTable('item-activity') || !DBStructure::existsTable('item')) {
DI::config()->set('system', 'post_update_version', 1347); DI::config()->set('system', 'post_update_version', 1347);
return true; return true;
} }

View file

@ -1031,14 +1031,14 @@ class Item
return 0; return 0;
} }
$id = Post\User::insert($item['uri-id'], $item['uid'], $item); $post_user_id = Post\User::insert($item['uri-id'], $item['uid'], $item);
if (!$id) { if (!$post_user_id) {
Logger::notice('Post-User is already inserted - aborting', ['uid' => $item['uid'], 'uri-id' => $item['uri-id']]); Logger::notice('Post-User is already inserted - aborting', ['uid' => $item['uid'], 'uri-id' => $item['uri-id']]);
return 0; return 0;
} }
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == GRAVITY_PARENT) {
$item['post-user-id'] = $id; $item['post-user-id'] = $post_user_id;
Post\ThreadUser::insert($item['uri-id'], $item['uid'], $item); Post\ThreadUser::insert($item['uri-id'], $item['uid'], $item);
} }
@ -1071,82 +1071,78 @@ class Item
// Set parent id // Set parent id
DBA::update('item', ['parent' => $parent_id], ['id' => $current_post]); DBA::update('item', ['parent' => $parent_id], ['id' => $current_post]);
$item['id'] = $current_post; $posted_item = Post::selectFirst(self::ITEM_FIELDLIST, ['post-user-id' => $post_user_id]);
$item['parent'] = $parent_id; if (!DBA::isResult($posted_item)) {
Logger::warning('new item not found in DB', ['id' => $post_user_id]);
return 0;
}
// update the commented timestamp on the parent // update the commented timestamp on the parent
if (DI::config()->get('system', 'like_no_comment')) { if (DI::config()->get('system', 'like_no_comment')) {
// Update when it is a comment // Update when it is a comment
$update_commented = in_array($item['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT]); $update_commented = in_array($posted_item['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT]);
} else { } else {
// Update when it isn't a follow or tag verb // Update when it isn't a follow or tag verb
$update_commented = !in_array($item['verb'], [Activity::FOLLOW, Activity::TAG]); $update_commented = !in_array($posted_item['verb'], [Activity::FOLLOW, Activity::TAG]);
} }
if ($update_commented) { if ($update_commented) {
Post::update(['commented' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()], ['id' => $parent_id]); Post::update(['commented' => DateTimeFormat::utcNow(), 'changed' => DateTimeFormat::utcNow()], ['id' => $post_user_id]);
} else { } else {
Post::update(['changed' => DateTimeFormat::utcNow()], ['id' => $parent_id]); Post::update(['changed' => DateTimeFormat::utcNow()], ['uri-id' => $posted_item['parent-uri-id'], 'uid' => $posted_item['uid']]);
} }
// In that function we check if this is a forum post. Additionally we delete the item under certain circumstances // In that function we check if this is a forum post. Additionally we delete the item under certain circumstances
if (self::tagDeliver($item['uid'], $current_post)) { if (self::tagDeliver($posted_item['uid'], $post_user_id)) {
// Get the user information for the logging // Get the user information for the logging
$user = User::getById($uid); $user = User::getById($uid);
Logger::notice('Item had been deleted', ['id' => $current_post, 'user' => $uid, 'account-type' => $user['account-type']]); Logger::notice('Item had been deleted', ['id' => $post_user_id, 'user' => $uid, 'account-type' => $user['account-type']]);
return 0; return 0;
} }
if (!$dontcache) { if (!$dontcache) {
$posted_item = Post::selectFirst(self::ITEM_FIELDLIST, ['id' => $current_post]); if ($notify) {
if (DBA::isResult($posted_item)) { Hook::callAll('post_local_end', $posted_item);
if ($notify) {
Hook::callAll('post_local_end', $posted_item);
} else {
Hook::callAll('post_remote_end', $posted_item);
}
} else { } else {
Logger::log('new item not found in DB, id ' . $current_post); Hook::callAll('post_remote_end', $posted_item);
} }
} }
if ($item['gravity'] === GRAVITY_PARENT) { if ($posted_item['gravity'] === GRAVITY_PARENT) {
self::addShadow($current_post); self::addShadow($post_user_id);
} else { } else {
self::addShadowPost($current_post); self::addShadowPost($post_user_id);
} }
self::updateContact($item); self::updateContact($posted_item);
Post\UserNotification::setNotification($item['uri-id'], $item['uid']); Post\UserNotification::setNotification($posted_item['uri-id'], $posted_item['uid']);
check_user_notification($item['uri-id'], $item['uid']); check_user_notification($posted_item['uri-id'], $posted_item['uid']);
//check_user_notification($current_post);
// Distribute items to users who subscribed to their tags // Distribute items to users who subscribed to their tags
self::distributeByTags($item); self::distributeByTags($posted_item);
// Automatically reshare the item if the "remote_self" option is selected // Automatically reshare the item if the "remote_self" option is selected
self::autoReshare($item); self::autoReshare($posted_item);
$transmit = $notify || ($item['visible'] && ($parent_origin || $item['origin'])); $transmit = $notify || ($posted_item['visible'] && ($parent_origin || $posted_item['origin']));
if ($transmit) { if ($transmit) {
$transmit_item = Post::selectFirst(['verb', 'origin'], ['id' => $item['id']]);
// Don't relay participation messages // Don't relay participation messages
if (($transmit_item['verb'] == Activity::FOLLOW) && if (($posted_item['verb'] == Activity::FOLLOW) &&
(!$transmit_item['origin'] || ($item['author-id'] != Contact::getPublicIdByUserId($uid)))) { (!$posted_item['origin'] || ($posted_item['author-id'] != Contact::getPublicIdByUserId($uid)))) {
Logger::info('Participation messages will not be relayed', ['item' => $item['id'], 'uri' => $item['uri'], 'verb' => $transmit_item['verb']]); Logger::info('Participation messages will not be relayed', ['item' => $posted_item['id'], 'uri' => $posted_item['uri'], 'verb' => $posted_item['verb']]);
$transmit = false; $transmit = false;
} }
} }
if ($transmit) { if ($transmit) {
Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $notify_type, (int)$item['uri-id'], (int)$item['uid']); Worker::add(['priority' => $priority, 'dont_fork' => true], 'Notifier', $notify_type, (int)$posted_item['uri-id'], (int)$posted_item['uid']);
} }
return $current_post; return $post_user_id;
} }
/** /**
@ -1235,6 +1231,7 @@ class Item
$condition = ["`id` IN (SELECT `parent` FROM `post-view` WHERE `id` = ?)", $itemid]; $condition = ["`id` IN (SELECT `parent` FROM `post-view` WHERE `id` = ?)", $itemid];
$parent = Post::selectFirst(['owner-id'], $condition); $parent = Post::selectFirst(['owner-id'], $condition);
if (!DBA::isResult($parent)) { if (!DBA::isResult($parent)) {
Logger::warning('Item not found', ['condition' => $condition]);
return; return;
} }
@ -1244,6 +1241,7 @@ class Item
'visible' => true, 'deleted' => false, 'private' => [self::PUBLIC, self::UNLISTED]]; 'visible' => true, 'deleted' => false, 'private' => [self::PUBLIC, self::UNLISTED]];
$item = Post::selectFirst(self::ITEM_FIELDLIST, $condition); $item = Post::selectFirst(self::ITEM_FIELDLIST, $condition);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
Logger::warning('Item not found', ['condition' => $condition]);
return; return;
} }
@ -1421,7 +1419,7 @@ class Item
private static function addShadow($itemid) private static function addShadow($itemid)
{ {
$fields = ['uid', 'private', 'visible', 'deleted', 'network', 'uri-id']; $fields = ['uid', 'private', 'visible', 'deleted', 'network', 'uri-id'];
$condition = ['id' => $itemid, 'parent' => [0, $itemid]]; $condition = ['id' => $itemid, 'gravity' => GRAVITY_PARENT];
$item = Post::selectFirst($fields, $condition); $item = Post::selectFirst($fields, $condition);
if (!DBA::isResult($item)) { if (!DBA::isResult($item)) {
@ -1816,7 +1814,7 @@ class Item
if (!$mention) { if (!$mention) {
if (($community_page || $prvgroup) && if (($community_page || $prvgroup) &&
!$item['wall'] && !$item['origin'] && ($item['gravity'] == GRAVITY_PARENT)) { !$item['wall'] && !$item['origin'] && ($item['gravity'] == GRAVITY_PARENT)) {
Logger::info('Delete private group/communiy top-level item without mention', ['id' => $item_id, 'guid'=> $item['guid']]); Logger::info('Delete private group/communiy top-level item without mention', ['id' => $item['id'], 'guid'=> $item['guid']]);
DBA::delete('item', ['uri-id' => $item['uri-id'], 'uid' => $item['uid']]); DBA::delete('item', ['uri-id' => $item['uri-id'], 'uid' => $item['uid']]);
Post\User::delete(['uri-id' => $item['uri-id'], 'uid' => $item['uid']]); Post\User::delete(['uri-id' => $item['uri-id'], 'uid' => $item['uid']]);
return true; return true;
@ -1865,11 +1863,11 @@ class Item
$fields = ['wall' => true, 'origin' => true, 'forum_mode' => $forum_mode, 'contact-id' => $self['id'], $fields = ['wall' => true, 'origin' => true, 'forum_mode' => $forum_mode, 'contact-id' => $self['id'],
'owner-id' => $owner_id, 'private' => $private, 'psid' => $psid]; 'owner-id' => $owner_id, 'private' => $private, 'psid' => $psid];
self::update($fields, ['id' => $item_id]); self::update($fields, ['id' => $item['id']]);
Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', Delivery::POST, (int)$item['uri-id'], (int)$item['uid']); Worker::add(['priority' => PRIORITY_HIGH, 'dont_fork' => true], 'Notifier', Delivery::POST, (int)$item['uri-id'], (int)$item['uid']);
self::performActivity($item_id, 'announce', $uid); self::performActivity($item['id'], 'announce', $uid);
return false; return false;
} }

View file

@ -55,9 +55,10 @@ class APDelivery
} }
if (empty($uri_id) && !empty($item_id)) { if (empty($uri_id) && !empty($item_id)) {
$item = Post::selectFirst(['uri-id'], ['id' => $item_id]); $item = Post::selectFirst(['uri-id', 'id'], ['item-id' => $item_id]);
if (!empty($item['uri-id'])) { if (!empty($item['uri-id'])) {
$uri_id = $item['uri-id']; $uri_id = $item['uri-id'];
$item_id = $item['id'];
} }
} elseif (!empty($uri_id) && !empty($item_id)) { } elseif (!empty($uri_id) && !empty($item_id)) {
$item = Post::selectFirst(['id'], ['uri-id' => $uri_id, 'uid' => $uid]); $item = Post::selectFirst(['id'], ['uri-id' => $uri_id, 'uid' => $uid]);

View file

@ -62,6 +62,13 @@ class Delivery
return; return;
} }
$target_id = $post['id']; $target_id = $post['id'];
} elseif (!in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION, Delivery::REMOVAL, Delivery::RELOCATION])) {
$post = Post::selectFirst(['id', 'uid', 'uri-id'], ['item-id' => $post_uriid]);
if (DBA::isResult($post)) {
$target_id = $post['id'];
$sender_uid = $post['uid'];
$post_uriid = $post['uri-id'];
}
} else { } else {
$target_id = $post_uriid; $target_id = $post_uriid;
} }

View file

@ -44,10 +44,10 @@ class Expire
Logger::log('Delete expired items', Logger::DEBUG); Logger::log('Delete expired items', Logger::DEBUG);
// physically remove anything that has been deleted for more than two months // physically remove anything that has been deleted for more than two months
$condition = ["`deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY"]; $condition = ["`deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY"];
$rows = Post::select(['id', 'guid', 'uri-id', 'uid'], $condition); $rows = Post::select(['item-id', 'guid', 'uri-id', 'uid'], $condition);
while ($row = Post::fetch($rows)) { while ($row = Post::fetch($rows)) {
Logger::info('Delete expired item', ['id' => $row['id'], 'guid' => $row['guid']]); Logger::info('Delete expired item', ['id' => $row['item-id'], 'guid' => $row['guid']]);
DBA::delete('item', ['id' => $row['id']]); DBA::delete('item', ['id' => $row['item-id']]);
Post\User::delete(['uri-id' => $row['uri-id'], 'uid' => $row['uid']]); Post\User::delete(['uri-id' => $row['uri-id'], 'uid' => $row['uid']]);
Post\ThreadUser::delete(['uri-id' => $row['uri-id'], 'uid' => $row['uid']]); Post\ThreadUser::delete(['uri-id' => $row['uri-id'], 'uid' => $row['uid']]);
} }

View file

@ -66,6 +66,14 @@ class Notifier
return; return;
} }
$target_id = $post['id']; $target_id = $post['id'];
} elseif (!in_array($cmd, [Delivery::MAIL, Delivery::SUGGESTION, Delivery::REMOVAL, Delivery::RELOCATION])) {
$post = Post::selectFirst(['id'], ['item-id' => $post_uriid]);
$post = Post::selectFirst(['id', 'uid', 'uri-id'], ['item-id' => $post_uriid]);
if (DBA::isResult($post)) {
$target_id = $post['id'];
$sender_uid = $post['uid'];
$post_uriid = $post['uri-id'];
}
} else { } else {
$target_id = $post_uriid; $target_id = $post_uriid;
} }

View file

@ -47,10 +47,10 @@ class RemoveContact {
$condition = ['uid' => $contact['uid'], 'contact-id' => $id]; $condition = ['uid' => $contact['uid'], 'contact-id' => $id];
} }
do { do {
$items = Post::select(['id', 'post-user-id', 'uri-id', 'guid'], $condition, ['limit' => 100]); $items = Post::select(['item-id', 'post-user-id', 'uri-id', 'guid'], $condition, ['limit' => 100]);
while ($item = Post::fetch($items)) { while ($item = Post::fetch($items)) {
Logger::info('Delete removed contact item', ['id' => $item['id'], 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]); Logger::info('Delete removed contact item', ['id' => $item['item-id'], 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
DBA::delete('item', ['id' => $item['id']]); DBA::delete('item', ['id' => $item['item-id']]);
Post::delete(['uri-id' => $item['uri-id']]); Post::delete(['uri-id' => $item['uri-id']]);
Post\ThreadUser::delete(['post-user-id' => $item['post-user-id']]); Post\ThreadUser::delete(['post-user-id' => $item['post-user-id']]);
Post\Thread::delete(['uri-id' => $item['uri-id']]); Post\Thread::delete(['uri-id' => $item['uri-id']]);

View file

@ -39,12 +39,11 @@
return [ return [
"post-view" => [ "post-view" => [
"fields" => [ "fields" => [
"id" => ["item", "id"], "id" => ["post-user", "id"],
"item-id" => ["item", "id"], "item-id" => ["item", "id"],
"post-user-id" => ["post-user", "id"], "post-user-id" => ["post-user", "id"],
"uid" => ["post-user", "uid"], "uid" => ["post-user", "uid"],
"parent" => ["item", "parent"], "parent" => ["parent-post", "id"],
"parent-user-id" => ["parent-post", "id"],
"uri" => ["item-uri", "uri"], "uri" => ["item-uri", "uri"],
"uri-id" => ["post-user", "uri-id"], "uri-id" => ["post-user", "uri-id"],
"parent-uri" => ["parent-item-uri", "uri"], "parent-uri" => ["parent-item-uri", "uri"],
@ -196,13 +195,12 @@
], ],
"post-thread-view" => [ "post-thread-view" => [
"fields" => [ "fields" => [
"id" => ["item", "id"], "id" => ["post-user", "id"],
"item-id" => ["item", "id"], "item-id" => ["item", "id"],
"iid" => ["item", "id"], "iid" => ["post-user", "id"],
"post-user-id" => ["post-user", "id"], "post-user-id" => ["post-user", "id"],
"uid" => ["post-thread-user", "uid"], "uid" => ["post-thread-user", "uid"],
"parent" => ["item", "parent"], "parent" => ["parent-post", "id"],
"parent-user-id" => ["parent-post", "id"],
"uri" => ["item-uri", "uri"], "uri" => ["item-uri", "uri"],
"uri-id" => ["post-thread-user", "uri-id"], "uri-id" => ["post-thread-user", "uri-id"],
"parent-uri" => ["parent-item-uri", "uri"], "parent-uri" => ["parent-item-uri", "uri"],
@ -381,8 +379,7 @@
"network-item-view" => [ "network-item-view" => [
"fields" => [ "fields" => [
"uri-id" => ["post-user", "uri-id"], "uri-id" => ["post-user", "uri-id"],
"parent" => ["item", "parent"], "parent" => ["post-user", "parent-uri-id"],
"parent-uri-id" => ["post-user", "parent-uri-id"],
"received" => ["post-user", "received"], "received" => ["post-user", "received"],
"commented" => ["post-thread-user", "commented"], "commented" => ["post-thread-user", "commented"],
"created" => ["post-user", "created"], "created" => ["post-user", "created"],
@ -396,8 +393,7 @@
"contact-type" => ["ownercontact", "contact-type"], "contact-type" => ["ownercontact", "contact-type"],
], ],
"query" => "FROM `post-user` "query" => "FROM `post-user`
STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid` STRAIGHT_JOIN `post-thread-user` ON `post-thread-user`.`uri-id` = `post-user`.`parent-uri-id` AND `post-thread-user`.`uid` = `post-user`.`uid`
LEFT JOIN `item` ON `item`.`uri-id` = `post-user`.`uri-id` AND `item`.`uid` = `post-user`.`uid`
INNER JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id` INNER JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id` LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`
@ -411,8 +407,7 @@
"network-thread-view" => [ "network-thread-view" => [
"fields" => [ "fields" => [
"uri-id" => ["post-thread-user", "uri-id"], "uri-id" => ["post-thread-user", "uri-id"],
"parent-uri-id" => ["post-user", "parent-uri-id"], "parent" => ["post-user", "parent-uri-id"],
"parent" => ["item", "id"],
"received" => ["post-thread-user", "received"], "received" => ["post-thread-user", "received"],
"commented" => ["post-thread-user", "commented"], "commented" => ["post-thread-user", "commented"],
"created" => ["post-thread-user", "created"], "created" => ["post-thread-user", "created"],
@ -425,7 +420,6 @@
], ],
"query" => "FROM `post-thread-user` "query" => "FROM `post-thread-user`
INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id` INNER JOIN `post-user` ON `post-user`.`id` = `post-thread-user`.`post-user-id`
LEFT JOIN `item` ON `item`.`uri-id` = `post-thread-user`.`uri-id` AND `item`.`uid` = `post-thread-user`.`uid`
STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id` STRAIGHT_JOIN `contact` ON `contact`.`id` = `post-thread-user`.`contact-id`
LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id` LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `post-thread-user`.`uid` AND `author`.`cid` = `post-thread-user`.`author-id`
LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id` LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `post-thread-user`.`uid` AND `owner`.`cid` = `post-thread-user`.`owner-id`