Get rid of the "item" table, enhanced "post" tables
This commit is contained in:
@@ -104,7 +104,7 @@ class TagCloud
|
||||
$tag_stmt = DBA::p("SELECT `name`, COUNT(`name`) AS `total` FROM `tag-search-view`
|
||||
LEFT JOIN `post-view` ON `tag-search-view`.`uri-id` = `post-view`.`uri-id`
|
||||
WHERE `tag-search-view`.`uid` = ?
|
||||
AND `post-view`.`visible` AND NOT `post-view`.`deleted` AND NOT `post-view`.`moderated`
|
||||
AND `post-view`.`visible` AND NOT `post-view`.`deleted`
|
||||
$sql_options
|
||||
GROUP BY `name` ORDER BY `total` DESC $limit",
|
||||
$uid
|
||||
|
||||
@@ -61,7 +61,9 @@ class Status extends BaseFactory
|
||||
*/
|
||||
public function createFromUriId(int $uriId, $uid = 0)
|
||||
{
|
||||
$item = Post::selectFirst([], ['uri-id' => $uriId, 'uid' => $uid]);
|
||||
$fields = ['uri-id', 'uid', 'author-id', 'starred', 'app', 'title', 'body', 'raw-body', 'created',
|
||||
'thr-parent-id', 'parent-author-id', 'language', 'uri', 'plink', 'private', 'vid', 'gravity'];
|
||||
$item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => $uid]);
|
||||
if (!$item) {
|
||||
throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . 'not found' . ($uid ? ' for user ' . $uid : '.'));
|
||||
}
|
||||
|
||||
@@ -1343,7 +1343,7 @@ class Contact
|
||||
|
||||
$o .= conversation($a, $items, 'contacts', $update, false, 'commented', local_user());
|
||||
} else {
|
||||
$items = Post::toArray(Post::selectForUser(local_user(), [], $condition, $params));
|
||||
$items = Post::toArray(Post::selectForUser(local_user(), Item::DISPLAY_FIELDLIST, $condition, $params));
|
||||
|
||||
$o .= conversation($a, $items, 'contact-posts', $update);
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ class Item
|
||||
'causer-id', 'causer-link', 'causer-name', 'causer-avatar', 'causer-contact-type',
|
||||
'contact-id', 'contact-uid', 'contact-link', 'contact-name', 'contact-avatar',
|
||||
'writable', 'self', 'cid', 'alias',
|
||||
'event-id', 'event-created', 'event-edited', 'event-start', 'event-finish',
|
||||
'event-created', 'event-edited', 'event-start', 'event-finish',
|
||||
'event-summary', 'event-desc', 'event-location', 'event-type',
|
||||
'event-nofinish', 'event-adjust', 'event-ignore', 'event-id',
|
||||
'delivery_queue_count', 'delivery_queue_done', 'delivery_queue_failed'
|
||||
@@ -91,34 +91,38 @@ class Item
|
||||
|
||||
// Field list that is used to deliver items via the protocols
|
||||
const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri-id', 'uri', 'thr-parent', 'parent-uri', 'guid',
|
||||
'parent-guid', 'created', 'edited', 'verb', 'object-type', 'object', 'target',
|
||||
'private', 'title', 'body', 'location', 'coord', 'app',
|
||||
'deleted', 'extid', 'post-type', 'gravity',
|
||||
'parent-guid', 'received', 'created', 'edited', 'verb', 'object-type', 'object', 'target',
|
||||
'private', 'title', 'body', 'raw-body', 'location', 'coord', 'app',
|
||||
'inform', 'deleted', 'extid', 'post-type', 'gravity',
|
||||
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
|
||||
'author-id', 'author-link', 'owner-link', 'contact-uid',
|
||||
'signed_text', 'network'];
|
||||
'author-id', 'author-link', 'owner-id', 'owner-link', 'contact-uid',
|
||||
'signed_text', 'network', 'wall', 'contact-id', 'plink', 'forum_mode', 'origin',
|
||||
'thr-parent-id', 'parent-uri-id', 'postopts', 'pubmail',
|
||||
'event-created', 'event-edited', 'event-start', 'event-finish',
|
||||
'event-summary', 'event-desc', 'event-location', 'event-type',
|
||||
'event-nofinish', 'event-adjust', 'event-ignore', 'event-id'];
|
||||
|
||||
// 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', 'psid',
|
||||
'contact-id', 'wall', 'gravity', 'extid', 'psid',
|
||||
'created', 'edited', 'commented', 'received', 'changed', 'verb',
|
||||
'postopts', 'plink', 'resource-id', 'event-id', 'inform',
|
||||
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'post-type',
|
||||
'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark',
|
||||
'private', 'pubmail', 'visible', 'starred',
|
||||
'unseen', 'deleted', 'origin', 'forum_mode', 'mention', 'global', 'network',
|
||||
'title', 'content-warning', 'body', 'location', 'coord', 'app',
|
||||
'rendered-hash', 'rendered-html', 'object-type', 'object', 'target-type', 'target',
|
||||
'author-id', 'author-link', 'author-name', 'author-avatar', 'author-network',
|
||||
'owner-id', 'owner-link', 'owner-name', 'owner-avatar', 'causer-id'];
|
||||
|
||||
// Item fiels that still are in use
|
||||
// Item fields 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',
|
||||
'global', 'private', 'visible', 'deleted', 'uid', 'contact-id',
|
||||
'wall', 'origin', 'pubmail', 'starred', 'unseen', 'mention', 'forum_mode', 'psid',
|
||||
'event-id', 'type', 'bookmark'];
|
||||
'event-id'];
|
||||
|
||||
// Legacy item fields that aren't stored any more in the item table
|
||||
const LEGACY_FIELDLIST = ['uri-hash', 'iaid', 'icid', 'attach',
|
||||
@@ -980,6 +984,12 @@ class Item
|
||||
Post\Media::insertFromAttachment($item['uri-id'], $item['attach']);
|
||||
}
|
||||
|
||||
if (empty($item['event-id'])) {
|
||||
unset($item['event-id']);
|
||||
}
|
||||
|
||||
Post::insert($item['uri-id'], $item);
|
||||
|
||||
if ($item['gravity'] == GRAVITY_PARENT) {
|
||||
Post\Thread::insert($item['uri-id'], $item);
|
||||
}
|
||||
@@ -1010,6 +1020,12 @@ class Item
|
||||
Tag::storeFromBody($item['uri-id'], $item['body']);
|
||||
}
|
||||
|
||||
$condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid']];
|
||||
if (Post::exists($condition)) {
|
||||
Logger::notice('Item is already inserted - aborting', $condition);
|
||||
return 0;
|
||||
}
|
||||
|
||||
$id = Post\User::insert($item['uri-id'], $item['uid'], $item);
|
||||
if (!$id) {
|
||||
Logger::notice('Post-User is already inserted - aborting', ['uid' => $item['uid'], 'uri-id' => $item['uri-id']]);
|
||||
@@ -1021,12 +1037,6 @@ class Item
|
||||
Post\ThreadUser::insert($item['uri-id'], $item['uid'], $item);
|
||||
}
|
||||
|
||||
$condition = ['uri-id' => $item['uri-id'], 'uid' => $item['uid'], 'network' => $item['network']];
|
||||
if (Post::exists($condition)) {
|
||||
Logger::notice('Item is already inserted - aborting', $condition);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Remove all fields that aren't part of the item table
|
||||
$table_fields = DBStructure::getFieldsForTable('item', $item);
|
||||
|
||||
@@ -1226,7 +1236,7 @@ class Item
|
||||
// Only distribute public items from native networks
|
||||
$condition = ['id' => $itemid, 'uid' => 0,
|
||||
'network' => array_merge(Protocol::FEDERATED ,['']),
|
||||
'visible' => true, 'deleted' => false, 'moderated' => false, 'private' => [self::PUBLIC, self::UNLISTED]];
|
||||
'visible' => true, 'deleted' => false, 'private' => [self::PUBLIC, self::UNLISTED]];
|
||||
$item = Post::selectFirst(self::ITEM_FIELDLIST, $condition);
|
||||
if (!DBA::isResult($item)) {
|
||||
return;
|
||||
@@ -1405,7 +1415,7 @@ class Item
|
||||
*/
|
||||
private static function addShadow($itemid)
|
||||
{
|
||||
$fields = ['uid', 'private', 'moderated', 'visible', 'deleted', 'network', 'uri-id'];
|
||||
$fields = ['uid', 'private', 'visible', 'deleted', 'network', 'uri-id'];
|
||||
$condition = ['id' => $itemid, 'parent' => [0, $itemid]];
|
||||
$item = Post::selectFirst($fields, $condition);
|
||||
|
||||
@@ -1419,7 +1429,7 @@ class Item
|
||||
}
|
||||
|
||||
// Is it a visible public post?
|
||||
if (!$item["visible"] || $item["deleted"] || $item["moderated"] || ($item["private"] == self::PRIVATE)) {
|
||||
if (!$item["visible"] || $item["deleted"] || ($item["private"] == self::PRIVATE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2154,7 +2164,7 @@ class Item
|
||||
$condition[0] .= " AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY";
|
||||
$condition[] = $days;
|
||||
|
||||
$items = Post::select(['resource-id', 'starred', 'type', 'id', 'post-type', 'uid', 'uri-id'], $condition);
|
||||
$items = Post::select(['resource-id', 'starred', 'id', 'post-type', 'uid', 'uri-id'], $condition);
|
||||
|
||||
if (!DBA::isResult($items)) {
|
||||
return;
|
||||
@@ -2187,9 +2197,9 @@ class Item
|
||||
continue;
|
||||
} elseif (!$expire_starred && intval($item['starred'])) {
|
||||
continue;
|
||||
} elseif (!$expire_notes && (($item['type'] == 'note') || ($item['post-type'] == self::PT_PERSONAL_NOTE))) {
|
||||
} elseif (!$expire_notes && ($item['post-type'] == self::PT_PERSONAL_NOTE)) {
|
||||
continue;
|
||||
} elseif (!$expire_items && ($item['type'] != 'note') && ($item['post-type'] != self::PT_PERSONAL_NOTE)) {
|
||||
} elseif (!$expire_items && ($item['post-type'] != self::PT_PERSONAL_NOTE)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2203,7 +2213,7 @@ class Item
|
||||
|
||||
public static function firstPostDate($uid, $wall = false)
|
||||
{
|
||||
$condition = ['gravity' => GRAVITY_PARENT, 'uid' => $uid, 'wall' => $wall, 'deleted' => false, 'visible' => true, 'moderated' => false];
|
||||
$condition = ['gravity' => GRAVITY_PARENT, 'uid' => $uid, 'wall' => $wall, 'deleted' => false, 'visible' => true];
|
||||
$params = ['order' => ['received' => false]];
|
||||
$thread = Post::selectFirst(['received'], $condition, $params);
|
||||
if (DBA::isResult($thread)) {
|
||||
|
||||
@@ -21,13 +21,42 @@
|
||||
|
||||
namespace Friendica\Model;
|
||||
|
||||
use BadMethodCallException;
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\Protocol\Activity;
|
||||
|
||||
class Post
|
||||
{
|
||||
/**
|
||||
* Insert a new post entry
|
||||
*
|
||||
* @param integer $uri_id
|
||||
* @param array $fields
|
||||
* @return int ID of inserted post
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function insert(int $uri_id, array $data = [])
|
||||
{
|
||||
if (empty($uri_id)) {
|
||||
throw new BadMethodCallException('Empty URI_id');
|
||||
}
|
||||
|
||||
$fields = DBStructure::getFieldsForTable('post', $data);
|
||||
|
||||
// Additionally assign the key fields
|
||||
$fields['uri-id'] = $uri_id;
|
||||
|
||||
if (!DBA::insert('post', $fields, Database::INSERT_IGNORE)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DBA::lastInsertId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch a single post row
|
||||
*
|
||||
@@ -189,12 +218,9 @@ class Post
|
||||
private static function selectView(string $view, array $selected = [], array $condition = [], $params = [])
|
||||
{
|
||||
if (empty($selected)) {
|
||||
$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',
|
||||
'parent-guid', 'parent-network', 'parent-author-id', 'parent-author-link', 'parent-author-name',
|
||||
'parent-author-network', 'signed_text', 'language', 'raw-body'], Item::DISPLAY_FIELDLIST, Item::ITEM_FIELDLIST);
|
||||
|
||||
if ($view != 'post-view') {
|
||||
$selected = array_merge(Item::DISPLAY_FIELDLIST, Item::ITEM_FIELDLIST);
|
||||
|
||||
if ($view == 'post-thread-view') {
|
||||
$selected = array_merge($selected, ['ignored', 'iid']);
|
||||
}
|
||||
}
|
||||
@@ -216,7 +242,13 @@ class Post
|
||||
*/
|
||||
public static function select(array $selected = [], array $condition = [], $params = [])
|
||||
{
|
||||
return self::selectView('post-view', $selected, $condition, $params);
|
||||
$timestamp = microtime(true);
|
||||
$data = self::selectView('post-view', $selected, $condition, $params);
|
||||
|
||||
$duration = microtime(true) - $timestamp;;
|
||||
if ($duration > 0.1)
|
||||
Logger::info('Blubb', ['duration' => $duration, 'selected' => $selected, 'condition' => $condition, 'params' => $params, 'callstack' => System::callstack(20)]);
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,7 +285,7 @@ class Post
|
||||
}
|
||||
|
||||
$condition = DBA::mergeConditions($condition,
|
||||
["`visible` AND NOT `deleted` AND NOT `moderated`
|
||||
["`visible` AND NOT `deleted`
|
||||
AND NOT `author-blocked` AND NOT `owner-blocked`
|
||||
AND (NOT `causer-blocked` OR `causer-id` = ?) AND NOT `contact-blocked`
|
||||
AND ((NOT `contact-readonly` AND NOT `contact-pending` AND (`contact-rel` IN (?, ?)))
|
||||
@@ -299,6 +331,7 @@ class Post
|
||||
*/
|
||||
public static function selectForUser($uid, array $selected = [], array $condition = [], $params = [])
|
||||
{
|
||||
//Logger::info('Blubb', ['uid' => $uid, 'selected' => $selected, 'condition' => $condition, 'params' => $params]);
|
||||
return self::selectViewForUser('post-view', $uid, $selected, $condition, $params);
|
||||
}
|
||||
|
||||
@@ -434,6 +467,20 @@ class Post
|
||||
$affected = max($affected, DBA::affectedRows());
|
||||
}
|
||||
|
||||
$update_fields = DBStructure::getFieldsForTable('post', $fields);
|
||||
if (!empty($update_fields)) {
|
||||
if (empty($uriids)) {
|
||||
$rows = DBA::selectToArray('post-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]);
|
||||
$uriids = array_column($rows, 'uri-id');
|
||||
}
|
||||
if (!DBA::update('post', $update_fields, ['uri-id' => $uriids])) {
|
||||
DBA::rollback();
|
||||
Logger::notice('Updating post failed', ['fields' => $update_fields, 'condition' => $condition]);
|
||||
return false;
|
||||
}
|
||||
$affected = max($affected, DBA::affectedRows());
|
||||
}
|
||||
|
||||
$update_fields = Post\DeliveryData::extractFields($fields);
|
||||
if (!empty($update_fields)) {
|
||||
if (empty($uriids)) {
|
||||
@@ -450,7 +497,7 @@ class Post
|
||||
|
||||
$update_fields = DBStructure::getFieldsForTable('post-thread', $fields);
|
||||
if (!empty($update_fields)) {
|
||||
$rows = DBA::selectToArray('post-view', ['uri-id'], $condition, ['group_by' => ['uri-id']]);
|
||||
$rows = DBA::selectToArray('post-view', ['uri-id'], $thread_condition, ['group_by' => ['uri-id']]);
|
||||
$uriids = array_column($rows, 'uri-id');
|
||||
if (!DBA::update('post-thread', $update_fields, ['uri-id' => $uriids])) {
|
||||
DBA::rollback();
|
||||
@@ -494,4 +541,20 @@ class Post
|
||||
Logger::info('Updated posts', ['rows' => $affected]);
|
||||
return $affected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a row from the post table
|
||||
*
|
||||
* @param array $conditions Field condition(s)
|
||||
* @param array $options
|
||||
* - cascade: If true we delete records in other tables that depend on the one we're deleting through
|
||||
* relations (default: true)
|
||||
*
|
||||
* @return boolean was the delete successful?
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function delete(array $conditions, array $options = [])
|
||||
{
|
||||
return DBA::delete('post', $conditions, $options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,7 +434,7 @@ class Network extends BaseModule
|
||||
}
|
||||
|
||||
if (DBA::isResult($items)) {
|
||||
$parents = array_column($items, 'parent');
|
||||
$parents = array_column($items, 'parent-uri-id');
|
||||
} else {
|
||||
$parents = [];
|
||||
}
|
||||
@@ -446,7 +446,7 @@ class Network extends BaseModule
|
||||
$condition = ['unseen' => true, 'uid' => local_user()];
|
||||
self::setItemsSeenByCondition($condition);
|
||||
} elseif (!empty($parents)) {
|
||||
$condition = ['unseen' => true, 'uid' => local_user(), 'parent' => $parents];
|
||||
$condition = ['unseen' => true, 'uid' => local_user(), 'parent-uri-id' => $parents];
|
||||
self::setItemsSeenByCondition($condition);
|
||||
}
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ class Status extends BaseProfile
|
||||
0, $a->profile['uid']]);
|
||||
|
||||
$condition = DBA::mergeConditions($condition, ['uid' => $a->profile['uid'], 'network' => Protocol::FEDERATED,
|
||||
'visible' => true, 'deleted' => false, 'moderated' => false]);
|
||||
'visible' => true, 'deleted' => false]);
|
||||
|
||||
$pager = new Pager(DI::l10n(), $args->getQueryString(), $itemspage_network);
|
||||
$params = ['limit' => [$pager->getStart(), $pager->getItemsPerPage()], 'order' => ['received' => true]];
|
||||
|
||||
@@ -9,6 +9,7 @@ use Friendica\Content\Widget;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\Post;
|
||||
use Friendica\Model\Post\Category;
|
||||
use Friendica\Module\BaseSearch;
|
||||
@@ -69,7 +70,7 @@ class Filed extends BaseSearch
|
||||
$item_condition = ['uid' => local_user(), 'uri-id' => $posts];
|
||||
$item_params = ['order' => ['uri-id' => true]];
|
||||
|
||||
$items = Post::toArray(Post::selectForUser(local_user(), [], $item_condition, $item_params));
|
||||
$items = Post::toArray(Post::selectForUser(local_user(), Item::DISPLAY_FIELDLIST, $item_condition, $item_params));
|
||||
|
||||
$o .= conversation(DI::app(), $items, 'filed', false, false, '', local_user());
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ class Index extends BaseSearch
|
||||
|
||||
if (!empty($uriids)) {
|
||||
$params = ['order' => ['id' => true], 'group_by' => ['uri-id']];
|
||||
$items = Post::toArray(Post::selectForUser(local_user(), [], ['uri-id' => $uriids], $params));
|
||||
$items = Post::toArray(Post::selectForUser(local_user(), Item::DISPLAY_FIELDLIST, ['uri-id' => $uriids], $params));
|
||||
}
|
||||
|
||||
if (empty($items)) {
|
||||
|
||||
@@ -81,7 +81,7 @@ class Profile extends BaseModule
|
||||
"SELECT DISTINCT(`parent-uri-id`) AS `uri-id`, `created` FROM `post-view`
|
||||
WHERE `uid` = ? AND NOT `contact-blocked` AND NOT `contact-pending`
|
||||
AND `visible` AND (NOT `deleted` OR `gravity` = ?)
|
||||
AND NOT `moderated` AND `wall` $sql_extra4 $sql_extra
|
||||
AND `wall` $sql_extra4 $sql_extra
|
||||
ORDER BY `received` DESC",
|
||||
$a->profile['uid'],
|
||||
GRAVITY_ACTIVITY
|
||||
|
||||
@@ -868,8 +868,9 @@ class Processor
|
||||
}
|
||||
|
||||
$replyto = JsonLD::fetchElement($activity['as:object'], 'as:inReplyTo', '@id');
|
||||
if (Post::exists(['uri' => $replyto])) {
|
||||
Logger::info('Post is a reply to an existing post - accepted', ['id' => $id, 'replyto' => $replyto]);
|
||||
$uriid = ItemURI::getIdByURI($replyto);
|
||||
if (Post::exists(['uri-id' => $uriid])) {
|
||||
Logger::info('Post is a reply to an existing post - accepted', ['id' => $id, 'uri-id' => $uriid, 'replyto' => $replyto]);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -930,7 +930,7 @@ class Receiver
|
||||
} else {
|
||||
Logger::log('Empty content for ' . $object_id . ', check if content is available locally.', Logger::DEBUG);
|
||||
|
||||
$item = Post::selectFirst([], ['uri' => $object_id]);
|
||||
$item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['uri' => $object_id]);
|
||||
if (!DBA::isResult($item)) {
|
||||
Logger::log('Object with url ' . $object_id . ' was not found locally.', Logger::DEBUG);
|
||||
return false;
|
||||
|
||||
@@ -258,7 +258,7 @@ class Transmitter
|
||||
$condition = array_merge($condition,
|
||||
['author-id' => $public_contact,
|
||||
'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT],
|
||||
'deleted' => false, 'visible' => true, 'moderated' => false]);
|
||||
'deleted' => false, 'visible' => true]);
|
||||
|
||||
$count = Post::count($condition);
|
||||
|
||||
@@ -1045,19 +1045,19 @@ class Transmitter
|
||||
public static function createActivityFromItem(int $item_id, bool $object_mode = false)
|
||||
{
|
||||
Logger::info('Fetching activity', ['item' => $item_id]);
|
||||
$item = Post::selectFirst([], ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
|
||||
$item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['id' => $item_id, 'parent-network' => Protocol::NATIVE_SUPPORT]);
|
||||
if (!DBA::isResult($item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// In case of a forum post ensure to return the original post if author and forum are on the same machine
|
||||
if (!empty($item['forum_mode'])) {
|
||||
if (($item['gravity'] == GRAVITY_PARENT) && !empty($item['forum_mode'])) {
|
||||
$author = Contact::getById($item['author-id'], ['nurl']);
|
||||
if (!empty($author['nurl'])) {
|
||||
$self = Contact::selectFirst(['uid'], ['nurl' => $author['nurl'], 'self' => true]);
|
||||
if (!empty($self['uid'])) {
|
||||
$forum_item = Post::selectFirst([], ['uri-id' => $item['uri-id'], 'uid' => $self['uid']]);
|
||||
if (DBA::isResult($item)) {
|
||||
$forum_item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['uri-id' => $item['uri-id'], 'uid' => $self['uid']]);
|
||||
if (DBA::isResult($forum_item)) {
|
||||
$item = $forum_item;
|
||||
}
|
||||
}
|
||||
@@ -1645,7 +1645,7 @@ class Transmitter
|
||||
return [];
|
||||
}
|
||||
|
||||
$reshared_item = Post::selectFirst([], ['guid' => $reshared['guid']]);
|
||||
$reshared_item = Post::selectFirst(Item::DELIVER_FIELDLIST, ['guid' => $reshared['guid']]);
|
||||
if (!DBA::isResult($reshared_item)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -887,9 +887,9 @@ class Feed
|
||||
$params = ['order' => ['received' => true], 'limit' => $max_items];
|
||||
|
||||
if ($filter === 'posts') {
|
||||
$ret = Post::selectThread([], $condition, $params);
|
||||
$ret = Post::selectThread(Item::DELIVER_FIELDLIST, $condition, $params);
|
||||
} else {
|
||||
$ret = Post::select([], $condition, $params);
|
||||
$ret = Post::select(Item::DELIVER_FIELDLIST, $condition, $params);
|
||||
}
|
||||
|
||||
$items = Post::toArray($ret);
|
||||
@@ -1041,7 +1041,7 @@ class Feed
|
||||
|
||||
$condition = ['uid' => $owner["uid"], 'guid' => $repeated_guid, 'private' => [Item::PUBLIC, Item::UNLISTED],
|
||||
'network' => Protocol::FEDERATED];
|
||||
$repeated_item = Post::selectFirst([], $condition);
|
||||
$repeated_item = Post::selectFirst(Item::DELIVER_FIELDLIST, $condition);
|
||||
if (!DBA::isResult($repeated_item)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ use Friendica\Util\Network;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Model\Conversation;
|
||||
use Friendica\Model\FContact;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Protocol\Relay;
|
||||
|
||||
class Delivery
|
||||
@@ -80,9 +81,9 @@ class Delivery
|
||||
}
|
||||
$parent_id = intval($item['parent']);
|
||||
|
||||
$condition = ['id' => [$target_id, $parent_id], 'visible' => true, 'moderated' => false];
|
||||
$condition = ['id' => [$target_id, $parent_id], 'visible' => true];
|
||||
$params = ['order' => ['id']];
|
||||
$itemdata = Model\Post::select([], $condition, $params);
|
||||
$itemdata = Model\Post::select(Item::DELIVER_FIELDLIST, $condition, $params);
|
||||
|
||||
while ($item = Model\Post::fetch($itemdata)) {
|
||||
if ($item['verb'] == Activity::ANNOUNCE) {
|
||||
|
||||
@@ -100,8 +100,8 @@ class Notifier
|
||||
$delivery_contacts_stmt = DBA::select('contact', ['id', 'url', 'addr', 'network', 'protocol', 'batch'], $condition);
|
||||
} else {
|
||||
// find ancestors
|
||||
$condition = ['id' => $target_id, 'visible' => true, 'moderated' => false];
|
||||
$target_item = Post::selectFirst([], $condition);
|
||||
$condition = ['id' => $target_id, 'visible' => true];
|
||||
$target_item = Post::selectFirst(Item::DELIVER_FIELDLIST, $condition);
|
||||
|
||||
if (!DBA::isResult($target_item) || !intval($target_item['parent'])) {
|
||||
Logger::info('No target item', ['cmd' => $cmd, 'target' => $target_id]);
|
||||
@@ -117,9 +117,9 @@ class Notifier
|
||||
return;
|
||||
}
|
||||
|
||||
$condition = ['parent' => $target_item['parent'], 'visible' => true, 'moderated' => false];
|
||||
$condition = ['parent' => $target_item['parent'], 'visible' => true];
|
||||
$params = ['order' => ['id']];
|
||||
$items_stmt = Post::select([], $condition, $params);
|
||||
$items_stmt = Post::select(Item::DELIVER_FIELDLIST, $condition, $params);
|
||||
if (!DBA::isResult($items_stmt)) {
|
||||
Logger::info('No item found', ['cmd' => $cmd, 'target' => $target_id]);
|
||||
return;
|
||||
@@ -792,6 +792,6 @@ class Notifier
|
||||
*/
|
||||
public static function isForumPost(array $item)
|
||||
{
|
||||
return !empty($item['forum_mode']);
|
||||
return ($item['gravity'] == GRAVITY_PARENT) && !empty($item['forum_mode']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,13 +47,14 @@ class RemoveContact {
|
||||
$condition = ['uid' => $contact['uid'], 'contact-id' => $id];
|
||||
}
|
||||
do {
|
||||
$items = Post::select(['id', 'guid', 'uri-id', 'uid'], $condition, ['limit' => 100]);
|
||||
$items = Post::select(['id', 'post-user-id', 'uri-id', 'guid'], $condition, ['limit' => 100]);
|
||||
while ($item = Post::fetch($items)) {
|
||||
Logger::info('Delete removed contact item', ['id' => $item['id'], 'guid' => $item['guid']]);
|
||||
Logger::info('Delete removed contact item', ['id' => $item['id'], 'uri-id' => $item['uri-id'], 'guid' => $item['guid']]);
|
||||
DBA::delete('item', ['id' => $item['id']]);
|
||||
Post\User::delete(['uri-id' => $item['uri-id'], 'uid' => $item['uid']]);
|
||||
Post::delete(['uri-id' => $item['uri-id']]);
|
||||
Post\ThreadUser::delete(['post-user-id' => $item['post-user-id']]);
|
||||
Post\Thread::delete(['uri-id' => $item['uri-id']]);
|
||||
Post\ThreadUser::delete(['uri-id' => $item['uri-id'], 'uid' => $item['uid']]);
|
||||
Post\User::delete(['id' => $item['post-user-id']]);
|
||||
}
|
||||
DBA::close($items);
|
||||
} while (Post::exists($condition));
|
||||
|
||||
Reference in New Issue
Block a user