List of deprecated fields is checked

This commit is contained in:
Michael 2021-02-01 07:06:01 +00:00
parent c1d99d6c4c
commit 08317036e7
4 changed files with 56 additions and 92 deletions

View file

@ -717,8 +717,10 @@ CREATE TABLE IF NOT EXISTS `item` (
`mention` boolean NOT NULL DEFAULT '0' COMMENT 'The owner of this item was mentioned in it', `mention` boolean NOT NULL DEFAULT '0' COMMENT 'The owner of this item was mentioned in it',
`forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '', `forum_mode` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
`psid` int unsigned COMMENT 'ID of the permission set of this post', `psid` int unsigned COMMENT 'ID of the permission set of this post',
`resource-id` varchar(32) NOT NULL DEFAULT '' COMMENT 'Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type',
`event-id` int unsigned COMMENT 'Used to link to the event.id', `event-id` int unsigned COMMENT 'Used to link to the event.id',
`type` varchar(20) COMMENT '',
`bookmark` boolean COMMENT '',
`resource-id` varchar(32) COMMENT 'Deprecated',
`uri-hash` varchar(80) COMMENT 'Deprecated', `uri-hash` varchar(80) COMMENT 'Deprecated',
`iaid` int unsigned COMMENT 'Deprecated', `iaid` int unsigned COMMENT 'Deprecated',
`icid` int unsigned COMMENT 'Deprecated', `icid` int unsigned COMMENT 'Deprecated',
@ -729,8 +731,6 @@ CREATE TABLE IF NOT EXISTS `item` (
`deny_gid` mediumtext COMMENT 'Deprecated', `deny_gid` mediumtext COMMENT 'Deprecated',
`postopts` text COMMENT 'Deprecated', `postopts` text COMMENT 'Deprecated',
`inform` mediumtext COMMENT 'Deprecated', `inform` mediumtext COMMENT 'Deprecated',
`type` varchar(20) COMMENT 'Deprecated',
`bookmark` boolean COMMENT 'Deprecated',
`file` mediumtext COMMENT 'Deprecated', `file` mediumtext COMMENT 'Deprecated',
`location` varchar(255) COMMENT 'Deprecated', `location` varchar(255) COMMENT 'Deprecated',
`coord` varchar(255) COMMENT 'Deprecated', `coord` varchar(255) COMMENT 'Deprecated',

View file

@ -98,14 +98,6 @@ class Item
'author-id', 'author-link', 'owner-link', 'contact-uid', 'author-id', 'author-link', 'owner-link', 'contact-uid',
'signed_text', 'network']; 'signed_text', 'network'];
// Field list for "post-content" table that is mixed with the item table
const MIXED_CONTENT_FIELDLIST = ['title', 'content-warning', 'body', 'location',
'coord', 'app', 'rendered-hash', 'rendered-html', 'verb',
'object-type', 'object', 'target-type', 'target', 'plink'];
// Field list for "post-content" table that is not present in the "item" table
const CONTENT_FIELDLIST = ['language', 'raw-body'];
// All fields in the item table // All fields in the item table
const ITEM_FIELDLIST = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent', const ITEM_FIELDLIST = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent',
'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'vid', 'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'vid',
@ -120,6 +112,22 @@ class Item
'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network', 'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'causer-id']; 'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'causer-id'];
// Item fiels that still are in use
const USED_FIELDLIST = ['id', 'parent', 'guid', 'uri', 'uri-id', 'parent-uri', 'parent-uri-id',
'thr-parent', 'thr-parent-id', 'created', 'edited', 'commented', 'received', 'changed',
'gravity', 'network', 'owner-id', 'author-id', 'causer-id', 'vid', 'extid', 'post-type',
'global', 'private', 'visible', 'moderated', 'deleted', 'uid', 'contact-id',
'wall', 'origin', 'pubmail', 'starred', 'unseen', 'mention', 'forum_mode', 'psid',
'event-id', 'type', 'bookmark'];
// Legacy item fields that aren't stored any more in the item table
const LEGACY_FIELDLIST = ['uri-hash', 'iaid', 'icid', 'attach',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'postopts',
'resource-id', 'inform', 'file', 'location', 'coord', 'tag', 'plink',
'title', 'content-warning', 'body', 'app', 'verb', 'object-type', 'object',
'target-type', 'target', 'author-name', 'author-link', 'author-avatar',
'owner-name', 'owner-link', 'owner-avatar', 'rendered-hash', 'rendered-html'];
// List of all verbs that don't need additional content data. // List of all verbs that don't need additional content data.
// Never reorder or remove entries from this list. Just add new ones at the end, if needed. // Never reorder or remove entries from this list. Just add new ones at the end, if needed.
const ACTIVITIES = [ const ACTIVITIES = [
@ -897,26 +905,11 @@ class Item
// Update the contact relations // Update the contact relations
Contact\Relation::store($toplevel_parent['author-id'], $item['author-id'], $item['created']); Contact\Relation::store($toplevel_parent['author-id'], $item['author-id'], $item['created']);
unset($item['parent_origin']);
} else { } else {
$parent_id = 0; $parent_id = 0;
$parent_origin = $item['origin']; $parent_origin = $item['origin'];
} }
// We don't store the causer link, only the id
unset($item['causer-link']);
// We don't store these fields anymore in the item table
unset($item['author-link']);
unset($item['author-name']);
unset($item['author-avatar']);
unset($item['author-network']);
unset($item['owner-link']);
unset($item['owner-name']);
unset($item['owner-avatar']);
$item['parent-uri-id'] = ItemURI::getIdByURI($item['parent-uri']); $item['parent-uri-id'] = ItemURI::getIdByURI($item['parent-uri']);
$item['thr-parent-id'] = ItemURI::getIdByURI($item['thr-parent']); $item['thr-parent-id'] = ItemURI::getIdByURI($item['thr-parent']);
@ -939,14 +932,10 @@ class Item
$item['edit'] = false; $item['edit'] = false;
$item['parent'] = $parent_id; $item['parent'] = $parent_id;
Hook::callAll('post_local', $item); Hook::callAll('post_local', $item);
unset($item['edit']);
} else { } else {
Hook::callAll('post_remote', $item); Hook::callAll('post_remote', $item);
} }
// Set after the insert because top-level posts are self-referencing
unset($item['parent']);
if (!empty($item['cancel'])) { if (!empty($item['cancel'])) {
Logger::log('post cancelled by addon.'); Logger::log('post cancelled by addon.');
return 0; return 0;
@ -965,15 +954,6 @@ class Item
$item['deny_gid'] $item['deny_gid']
); );
unset($item['allow_cid']);
unset($item['allow_gid']);
unset($item['deny_cid']);
unset($item['deny_gid']);
// This array field is used to trigger some automatic reactions
// It is mainly used in the "post_local" hook.
unset($item['api_source']);
if ($item['verb'] == Activity::ANNOUNCE) { if ($item['verb'] == Activity::ANNOUNCE) {
self::setOwnerforResharedItem($item); self::setOwnerforResharedItem($item);
} }
@ -985,10 +965,6 @@ class Item
// Check for hashtags in the body and repair or add hashtag links // Check for hashtags in the body and repair or add hashtag links
$item['body'] = self::setHashtags($item['body']); $item['body'] = self::setHashtags($item['body']);
if (!empty($item['attach'])) {
Post\Media::insertFromAttachment($item['uri-id'], $item['attach']);
}
// Fill the cache field // Fill the cache field
self::putInCache($item); self::putInCache($item);
@ -998,40 +974,27 @@ class Item
$notify_type = Delivery::POST; $notify_type = Delivery::POST;
} }
// Filling item related side tables
if (!empty($item['attach'])) {
Post\Media::insertFromAttachment($item['uri-id'], $item['attach']);
}
if (!in_array($item['verb'], self::ACTIVITIES)) { if (!in_array($item['verb'], self::ACTIVITIES)) {
Post\Content::insert($item['uri-id'], $item); Post\Content::insert($item['uri-id'], $item);
} }
$body = $item['body'];
$verb = $item['verb'];
// We just remove everything that is content
foreach (array_merge(self::CONTENT_FIELDLIST, self::MIXED_CONTENT_FIELDLIST) as $field) {
unset($item[$field]);
}
unset($item['activity']);
// Filling item related side tables
// Diaspora signature // Diaspora signature
if (!empty($item['diaspora_signed_text'])) { if (!empty($item['diaspora_signed_text'])) {
DBA::replace('diaspora-interaction', ['uri-id' => $item['uri-id'], 'interaction' => $item['diaspora_signed_text']]); DBA::replace('diaspora-interaction', ['uri-id' => $item['uri-id'], 'interaction' => $item['diaspora_signed_text']]);
} }
unset($item['diaspora_signed_text']);
// Attached file links // Attached file links
if (!empty($item['file'])) { if (!empty($item['file'])) {
Post\Category::storeTextByURIId($item['uri-id'], $item['uid'], $item['file']); Post\Category::storeTextByURIId($item['uri-id'], $item['uid'], $item['file']);
} }
unset($item['file']);
// Delivery relevant data // Delivery relevant data
$delivery_data = Post\DeliveryData::extractFields($item); $delivery_data = Post\DeliveryData::extractFields($item);
unset($item['postopts']);
unset($item['inform']);
if (!empty($item['origin']) || !empty($item['wall']) || !empty($delivery_data['postopts']) || !empty($delivery_data['inform'])) { if (!empty($item['origin']) || !empty($item['wall']) || !empty($delivery_data['postopts']) || !empty($delivery_data['inform'])) {
Post\DeliveryData::insert($item['uri-id'], $delivery_data); Post\DeliveryData::insert($item['uri-id'], $delivery_data);
@ -1039,11 +1002,15 @@ class Item
// Store tags from the body if this hadn't been handled previously in the protocol classes // Store tags from the body if this hadn't been handled previously in the protocol classes
if (!Tag::existsForPost($item['uri-id'])) { if (!Tag::existsForPost($item['uri-id'])) {
Tag::storeFromBody($item['uri-id'], $body); Tag::storeFromBody($item['uri-id'], $item['body']);
} }
$id = Post\User::insert($item['uri-id'], $item['uid'], $item); $id = Post\User::insert($item['uri-id'], $item['uid'], $item);
if ($id) { if (!$id) {
Logger::notice('Post-User is already inserted - aborting', ['uid' => $item['uid'], 'uri-id' => $item['uri-id']]);
return 0;
}
if ($item['gravity'] == GRAVITY_PARENT) { if ($item['gravity'] == GRAVITY_PARENT) {
Post\ThreadUser::insert($item['uri-id'], $item['uid'], $item); Post\ThreadUser::insert($item['uri-id'], $item['uid'], $item);
} }
@ -1057,14 +1024,15 @@ class Item
// Remove all fields that aren't part of the item table // Remove all fields that aren't part of the item table
$item = DBStructure::getFieldsForTable('item', $item); $item = DBStructure::getFieldsForTable('item', $item);
// We remove all legacy fields that now are stored in other tables
foreach (self::LEGACY_FIELDLIST as $field) {
unset($item[$field]);
}
$result = DBA::insert('item', $item); $result = DBA::insert('item', $item);
// When the item was successfully stored we fetch the ID of the item. // When the item was successfully stored we fetch the ID of the item.
$current_post = DBA::lastInsertId(); $current_post = DBA::lastInsertId();
} else {
Logger::notice('Post-User is already inserted - aborting', ['uid' => $item['uid'], 'uri-id' => $item['uri-id']]);
return 0;
}
if (empty($current_post) || !DBA::isResult($result)) { if (empty($current_post) || !DBA::isResult($result)) {
// On failure store the data into a spool file so that the "SpoolPost" worker can try again later. // On failure store the data into a spool file so that the "SpoolPost" worker can try again later.
@ -1091,7 +1059,7 @@ class Item
$update_commented = in_array($item['gravity'], [GRAVITY_PARENT, GRAVITY_COMMENT]); $update_commented = in_array($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($verb, [Activity::FOLLOW, Activity::TAG]); $update_commented = !in_array($item['verb'], [Activity::FOLLOW, Activity::TAG]);
} }
if ($update_commented) { if ($update_commented) {

View file

@ -192,7 +192,7 @@ class Post
$selected = array_merge(['author-addr', 'author-nick', 'owner-addr', 'owner-nick', 'causer-addr', 'causer-nick', $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', '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-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); 'parent-author-network', 'signed_text', 'language', 'raw-body'], Item::DISPLAY_FIELDLIST, Item::ITEM_FIELDLIST);
if ($view == 'post-thread-view') { if ($view == 'post-thread-view') {
$selected = array_merge($selected, ['ignored', 'iid']); $selected = array_merge($selected, ['ignored', 'iid']);
@ -479,13 +479,8 @@ class Post
$affected = max($affected, DBA::affectedRows()); $affected = max($affected, DBA::affectedRows());
} }
$item_fields = ['guid', 'type', 'wall', 'gravity', 'extid', 'created', 'edited', 'commented', 'received', 'changed',
'resource-id', 'post-type', 'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark',
'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', 'network', 'vid', 'psid',
'contact-id', 'author-id', 'owner-id', 'causer-id', 'event-id'];
$update_fields = []; $update_fields = [];
foreach ($item_fields as $field) { foreach (Item::USED_FIELDLIST as $field) {
if (array_key_exists($field, $fields)) { if (array_key_exists($field, $fields)) {
$update_fields[$field] = $fields[$field]; $update_fields[$field] = $fields[$field];
} }

View file

@ -785,9 +785,12 @@ return [
"forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""], "forum_mode" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
"psid" => ["type" => "int unsigned", "foreign" => ["permissionset" => "id", "on delete" => "restrict"], "comment" => "ID of the permission set of this post"], "psid" => ["type" => "int unsigned", "foreign" => ["permissionset" => "id", "on delete" => "restrict"], "comment" => "ID of the permission set of this post"],
// It has to be decided whether these fields belong to the user or the structure // It has to be decided whether these fields belong to the user or the structure
"resource-id" => ["type" => "varchar(32)", "not null" => "1", "default" => "", "comment" => "Used to link other tables to items, it identifies the linked resource (e.g. photo) and if set must also set resource_type"],
"event-id" => ["type" => "int unsigned", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"], "event-id" => ["type" => "int unsigned", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"],
// Check deprecation status
"type" => ["type" => "varchar(20)", "comment" => ""],
"bookmark" => ["type" => "boolean", "comment" => ""],
// Deprecated fields. Will be removed in upcoming versions // Deprecated fields. Will be removed in upcoming versions
"resource-id" => ["type" => "varchar(32)", "comment" => "Deprecated"],
"uri-hash" => ["type" => "varchar(80)", "comment" => "Deprecated"], "uri-hash" => ["type" => "varchar(80)", "comment" => "Deprecated"],
"iaid" => ["type" => "int unsigned", "comment" => "Deprecated"], "iaid" => ["type" => "int unsigned", "comment" => "Deprecated"],
"icid" => ["type" => "int unsigned", "comment" => "Deprecated"], "icid" => ["type" => "int unsigned", "comment" => "Deprecated"],
@ -798,8 +801,6 @@ return [
"deny_gid" => ["type" => "mediumtext", "comment" => "Deprecated"], "deny_gid" => ["type" => "mediumtext", "comment" => "Deprecated"],
"postopts" => ["type" => "text", "comment" => "Deprecated"], "postopts" => ["type" => "text", "comment" => "Deprecated"],
"inform" => ["type" => "mediumtext", "comment" => "Deprecated"], "inform" => ["type" => "mediumtext", "comment" => "Deprecated"],
"type" => ["type" => "varchar(20)", "comment" => "Deprecated"],
"bookmark" => ["type" => "boolean", "comment" => "Deprecated"],
"file" => ["type" => "mediumtext", "comment" => "Deprecated"], "file" => ["type" => "mediumtext", "comment" => "Deprecated"],
"location" => ["type" => "varchar(255)", "comment" => "Deprecated"], "location" => ["type" => "varchar(255)", "comment" => "Deprecated"],
"coord" => ["type" => "varchar(255)", "comment" => "Deprecated"], "coord" => ["type" => "varchar(255)", "comment" => "Deprecated"],