The "icid" field is deprecated

This commit is contained in:
Michael 2021-01-19 23:26:24 +00:00
parent 4908afad8f
commit a773a72eaa
5 changed files with 25 additions and 45 deletions

View File

@ -1,6 +1,6 @@
-- ------------------------------------------
-- Friendica 2021.03-dev (Red Hot Poker)
-- DB_UPDATE_VERSION 1392
-- DB_UPDATE_VERSION 1393
-- ------------------------------------------
@ -686,7 +686,6 @@ CREATE TABLE IF NOT EXISTS `item` (
`owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the owner of this item',
`author-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the author of this item',
`causer-id` int unsigned NOT NULL DEFAULT 0 COMMENT 'Link to the contact table with uid=0 of the contact that caused the item creation',
`icid` int unsigned COMMENT 'Id of the item-content table entry that contains the whole item content',
`vid` smallint unsigned COMMENT 'Id of the verb table entry that contains the activity verbs',
`extid` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`post-type` tinyint unsigned NOT NULL DEFAULT 0 COMMENT 'Post type (personal note, bookmark, ...)',
@ -708,6 +707,7 @@ CREATE TABLE IF NOT EXISTS `item` (
`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',
`iaid` int unsigned COMMENT 'Deprecated',
`icid` int unsigned COMMENT 'Deprecated',
`attach` mediumtext COMMENT 'Deprecated',
`allow_cid` mediumtext COMMENT 'Deprecated',
`allow_gid` mediumtext COMMENT 'Deprecated',
@ -765,8 +765,6 @@ CREATE TABLE IF NOT EXISTS `item` (
INDEX `uid_unseen_wall` (`uid`,`unseen`,`wall`),
INDEX `mention_uid_id` (`mention`,`uid`,`id`),
INDEX `uid_eventid` (`uid`,`event-id`),
INDEX `icid` (`icid`),
INDEX `iaid` (`iaid`),
INDEX `vid` (`vid`),
INDEX `psid_wall` (`psid`,`wall`),
INDEX `uri-id` (`uri-id`),
@ -1530,7 +1528,6 @@ CREATE VIEW `post-view` AS SELECT
`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`,
@ -1691,7 +1688,6 @@ CREATE VIEW `post-thread-view` AS SELECT
`thread`.`mention` AS `mention`,
`item`.`global` AS `global`,
`thread`.`network` AS `network`,
`item`.`icid` AS `icid`,
`item`.`vid` AS `vid`,
`item`.`psid` AS `psid`,
`item`.`attach` AS `attach`,

View File

@ -31,6 +31,7 @@ use Friendica\Core\Session;
use Friendica\Core\System;
use Friendica\Model\Tag;
use Friendica\Core\Worker;
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\DI;
@ -108,7 +109,7 @@ class Item
// All fields in the item table
const ITEM_FIELDLIST = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent',
'guid', 'uri-id', 'parent-uri-id', 'thr-parent-id', 'vid',
'contact-id', 'type', 'wall', 'gravity', 'extid', 'icid', 'psid',
'contact-id', 'type', 'wall', 'gravity', 'extid', 'psid',
'created', 'edited', 'commented', 'received', 'changed', 'verb',
'postopts', 'plink', 'resource-id', 'event-id', 'inform',
'file', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type',
@ -202,7 +203,7 @@ class Item
// We cannot simply expand the condition to check for origin entries
// The condition needn't to be a simple array but could be a complex condition.
// And we have to execute this query before the update to ensure to fetch the same data.
$items = DBA::select('item', ['id', 'origin', 'uri', 'uri-id', 'icid', 'uid', 'file'], $condition);
$items = DBA::select('item', ['id', 'origin', 'uri', 'uri-id', 'uid', 'file'], $condition);
$content_fields = [];
foreach (array_merge(self::CONTENT_FIELDLIST, self::MIXED_CONTENT_FIELDLIST) as $field) {
@ -264,14 +265,6 @@ class Item
}
self::updateContent($content_fields, ['uri-id' => $item['uri-id']]);
if (empty($item['icid'])) {
$item_content = DBA::selectFirst('item-content', [], ['uri-id' => $item['uri-id']]);
if (DBA::isResult($item_content)) {
$item_fields = ['icid' => $item_content['id']];
DBA::update('item', $item_fields, ['id' => $item['id']]);
}
}
}
if (!is_null($files)) {
@ -366,8 +359,7 @@ class Item
// locate item to be deleted
$fields = ['id', 'uri', 'uri-id', 'uid', 'parent', 'parent-uri', 'origin',
'deleted', 'file', 'resource-id', 'event-id',
'verb', 'object-type', 'object', 'target', 'contact-id',
'icid', 'psid', 'gravity'];
'verb', 'object-type', 'object', 'target', 'contact-id', 'psid', 'gravity'];
$item = Post::selectFirst($fields, ['id' => $item_id]);
if (!DBA::isResult($item)) {
Logger::info('Item not found.', ['id' => $item_id]);
@ -1123,13 +1115,10 @@ class Item
$notify_type = Delivery::POST;
}
if (!in_array($item['verb'], self::ACTIVITIES)) {
$item['icid'] = self::insertContent($item);
if (empty($item['icid'])) {
// This shouldn't happen
Logger::warning('No content stored, quitting', ['guid' => $item['guid'], 'uri-id' => $item['uri-id'], 'causer-id' => ($item['causer-id'] ?? 0), 'post-type' => $item['post-type'], 'network' => $item['network']]);
return 0;
}
if (!in_array($item['verb'], self::ACTIVITIES) && !self::insertContent($item)) {
// This shouldn't happen
Logger::warning('No content stored, quitting', ['guid' => $item['guid'], 'uri-id' => $item['uri-id'], 'causer-id' => ($item['causer-id'] ?? 0), 'post-type' => $item['post-type'], 'network' => $item['network']]);
return 0;
}
$body = $item['body'];
@ -1372,6 +1361,7 @@ class Item
* Insert a new item content entry
*
* @param array $item The item fields that are to be inserted
* @return bool "true" if content was inserted or already existed
* @throws \Exception
*/
private static function insertContent(array $item)
@ -1384,25 +1374,23 @@ class Item
}
}
$item_content = DBA::selectFirst('item-content', ['id'], ['uri-id' => $item['uri-id']]);
if (DBA::isResult($item_content)) {
$icid = $item_content['id'];
Logger::info('Existing content found', ['icid' => $icid, 'uri' => $item['uri']]);
return $icid;
$found = DBA::exists('item-content', ['uri-id' => $item['uri-id']]);
if ($found) {
Logger::info('Existing content found', ['uri-id' => $item['uri-id'], 'uri' => $item['uri']]);
return true;
}
DBA::replace('item-content', $fields);
DBA::insert('item-content', $fields, Database::INSERT_IGNORE);
$item_content = DBA::selectFirst('item-content', ['id'], ['uri-id' => $item['uri-id']]);
if (DBA::isResult($item_content)) {
$icid = $item_content['id'];
Logger::notice('Content inserted', ['icid' => $icid, 'uri' => $item['uri']]);
return $icid;
$found = DBA::exists('item-content', ['uri-id' => $item['uri-id']]);
if ($found) {
Logger::notice('Content inserted', ['uri-id' => $item['uri-id'], 'uri' => $item['uri']]);
return true;
}
// This shouldn't happen.
Logger::error("Content wasn't inserted", $item);
return null;
return false;
}
/**
@ -1439,7 +1427,7 @@ class Item
*/
public static function distribute($itemid, $signed_text = '')
{
$condition = ["`id` IN (SELECT `parent` FROM `item` WHERE `id` = ?)", $itemid];
$condition = ["`id` IN (SELECT `parent` FROM `post-view` WHERE `id` = ?)", $itemid];
$parent = Post::selectFirst(['owner-id'], $condition);
if (!DBA::isResult($parent)) {
return;

View File

@ -53,7 +53,7 @@ class Expire
// Normally we shouldn't have orphaned data at all.
// If we do have some, then we have to check why.
Logger::log('Deleting orphaned item content - start', Logger::DEBUG);
$condition = ["NOT EXISTS (SELECT `icid` FROM `item` WHERE `item`.`icid` = `item-content`.`id`)"];
$condition = ["NOT EXISTS (SELECT `uri-id` FROM `item` WHERE `item`.`uri-id` = `item-content`.`uri-id`)"];
DBA::delete('item-content', $condition);
Logger::log('Orphaned item content deleted: ' . DBA::affectedRows(), Logger::DEBUG);

View File

@ -55,7 +55,7 @@
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1392);
define('DB_UPDATE_VERSION', 1393);
}
return [
@ -752,7 +752,6 @@ return [
"owner-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 owner of this item"],
"author-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 author of this item"],
"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"],
"vid" => ["type" => "smallint unsigned", "foreign" => ["verb" => "id", "on delete" => "restrict"], "comment" => "Id of the verb table entry that contains the activity verbs"],
"extid" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"post-type" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => "Post type (personal note, bookmark, ...)"],
@ -777,6 +776,7 @@ return [
"event-id" => ["type" => "int unsigned", "relation" => ["event" => "id"], "comment" => "Used to link to the event.id"],
// Deprecated fields. Will be removed in upcoming versions
"iaid" => ["type" => "int unsigned", "comment" => "Deprecated"],
"icid" => ["type" => "int unsigned", "comment" => "Deprecated"],
"attach" => ["type" => "mediumtext", "comment" => "Deprecated"],
"allow_cid" => ["type" => "mediumtext", "comment" => "Deprecated"],
"allow_gid" => ["type" => "mediumtext", "comment" => "Deprecated"],
@ -836,8 +836,6 @@ return [
"uid_unseen_wall" => ["uid", "unseen", "wall"],
"mention_uid_id" => ["mention", "uid", "id"],
"uid_eventid" => ["uid", "event-id"],
"icid" => ["icid"],
"iaid" => ["iaid"],
"vid" => ["vid"],
"psid_wall" => ["psid", "wall"],
"uri-id" => ["uri-id"],

View File

@ -76,7 +76,6 @@
"mention" => ["item", "mention"],
"global" => ["item", "global"],
"network" => ["item", "network"],
"icid" => ["item", "icid"],
"vid" => ["item", "vid"],
"psid" => ["item", "psid"],
"attach" => ["item", "attach"],
@ -235,7 +234,6 @@
"mention" => ["thread", "mention"],
"global" => ["item", "global"],
"network" => ["thread", "network"],
"icid" => ["item", "icid"],
"vid" => ["item", "vid"],
"psid" => ["item", "psid"],
"attach" => ["item", "attach"],