-- ------------------------------------------
-- Friendica 2021.03-dev (Red Hot Poker)
--- DB_UPDATE_VERSION 1392
+-- DB_UPDATE_VERSION 1393
-- ------------------------------------------
`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, ...)',
`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',
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`),
`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`,
`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`,
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;
// 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',
// 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) {
}
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)) {
// 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]);
$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'];
* 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)
}
}
- $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;
}
/**
*/
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;
// 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);
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
- define('DB_UPDATE_VERSION', 1392);
+ define('DB_UPDATE_VERSION', 1393);
}
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, ...)"],
"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"],
"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"],
"mention" => ["item", "mention"],
"global" => ["item", "global"],
"network" => ["item", "network"],
- "icid" => ["item", "icid"],
"vid" => ["item", "vid"],
"psid" => ["item", "psid"],
"attach" => ["item", "attach"],
"mention" => ["thread", "mention"],
"global" => ["item", "global"],
"network" => ["thread", "network"],
- "icid" => ["item", "icid"],
"vid" => ["item", "vid"],
"psid" => ["item", "psid"],
"attach" => ["item", "attach"],