1
0
Fork 0

Merge pull request #5232 from annando/no-author-link

Separate functions for fetching items for the system and for users
This commit is contained in:
Hypolite Petovan 2018-06-17 18:41:46 -04:00 committed by GitHub
commit af39296f06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 256 additions and 231 deletions

View file

@ -1626,7 +1626,7 @@ function api_search($type)
}
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params);
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
$data['status'] = api_format_items(dba::inArray($statuses), $user_info);
@ -1693,7 +1693,7 @@ function api_statuses_home_timeline($type)
}
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params);
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
$items = dba::inArray($statuses);
@ -1770,7 +1770,7 @@ function api_statuses_public_timeline($type)
}
$params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
$statuses = Item::selectThread(api_user(), [], $condition, $params);
$statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$r = dba::inArray($statuses);
} else {
@ -1787,7 +1787,7 @@ function api_statuses_public_timeline($type)
}
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params);
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
$r = dba::inArray($statuses);
}
@ -1846,7 +1846,7 @@ function api_statuses_networkpublic_timeline($type)
}
$params = ['order' => ['iid' => true], 'limit' => [$start, $count]];
$statuses = Item::selectThread(api_user(), [], $condition, $params);
$statuses = Item::selectThreadForUser(api_user(), Item::DISPLAY_FIELDLIST, $condition, $params);
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
@ -1917,7 +1917,7 @@ function api_statuses_show($type)
$params = [];
}
$statuses = Item::select(api_user(), [], $condition, $params);
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
/// @TODO How about copying this to above methods which don't check $r ?
if (!DBM::is_result($statuses)) {
@ -1998,7 +1998,7 @@ function api_conversation_show($type)
}
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params);
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
if (!DBM::is_result($statuses)) {
throw new BadRequestException("There is no status with id $id.");
@ -2048,7 +2048,7 @@ function api_statuses_repeat($type)
logger('API: api_statuses_repeat: '.$id);
$fields = ['body', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
$item = Item::selectFirst(api_user(), $fields, ['id' => $id, 'private' => false]);
$item = Item::selectFirst($fields, ['id' => $id, 'private' => false]);
if (DBM::is_result($item) && $item['body'] != "") {
if (strpos($item['body'], "[/share]") !== false) {
@ -2168,7 +2168,7 @@ function api_statuses_mentions($type)
}
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params);
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
@ -2248,7 +2248,7 @@ function api_statuses_user_timeline($type)
}
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params);
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
$ret = api_format_items(dba::inArray($statuses), $user_info, true, $type);
@ -2300,7 +2300,7 @@ function api_favorites_create_destroy($type)
$itemid = intval($_REQUEST['id']);
}
$item = Item::selectFirst(api_user(), [], ['id' => $itemid, 'uid' => api_user()]);
$item = Item::selectFirstForUser(api_user(), [], ['id' => $itemid, 'uid' => api_user()]);
if (!DBM::is_result($item)) {
throw new BadRequestException("Invalid item.");
@ -2390,7 +2390,7 @@ function api_favorites($type)
$condition[] = $max_id;
}
$statuses = Item::select(api_user(), [], $condition, $params);
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
$ret = api_format_items(dba::inArray($statuses), $user_info, false, $type);
}
@ -3198,7 +3198,7 @@ function api_lists_statuses($type)
}
$params = ['order' => ['id' => true], 'limit' => [$start, $count]];
$statuses = Item::select(api_user(), [], $condition, $params);
$statuses = Item::selectForUser(api_user(), [], $condition, $params);
$items = api_format_items(dba::inArray($statuses), $user_info, false, $type);
@ -4723,7 +4723,7 @@ function prepare_photo_data($type, $scale, $photo_id)
$condition = ["`parent` = ? AND `uid` = ? AND (`verb` = ? OR `type`='photo')",
$item[0]['parent'], api_user(), ACTIVITY_POST];
$statuses = Item::select(api_user(), [], $condition);
$statuses = Item::selectForUser(api_user(), [], $condition);
// prepare output of comments
$commentData = api_format_items(dba::inArray($statuses), $user_info, false, $type);
@ -5716,7 +5716,7 @@ function api_friendica_notification_seen($type)
$nm->setSeen($note);
if ($note['otype']=='item') {
// would be really better with an ItemsManager and $im->getByID() :-P
$item = Item::selectFirst(api_user(), [], ['id' => $note['iid'], 'uid' => api_user()]);
$item = Item::selectFirstForUser(api_user(), [], ['id' => $note['iid'], 'uid' => api_user()]);
if (DBM::is_result($$item)) {
// we found the item, return it to the user
$ret = api_format_items([$item], $user_info, false, $type);

View file

@ -788,7 +788,7 @@ function conversation_add_children($parents, $block_authors, $order, $uid) {
if ($block_authors) {
$condition[0] .= "AND NOT `author`.`hidden`";
}
$thread_items = Item::select(local_user(), [], $condition, $params);
$thread_items = Item::selectForUser(local_user(), [], $condition, $params);
$comments = dba::inArray($thread_items);

View file

@ -130,7 +130,7 @@ function notification($params)
$item = null;
if ($params['otype'] === 'item' && $parent_id) {
$item = Item::selectFirst($params['uid'], [], ['id' => $parent_id]);
$item = Item::selectFirstForUser($params['uid'], [], ['id' => $parent_id]);
}
$item_post_type = item_post_type($item);
@ -724,23 +724,24 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
$profiles = $profiles2;
$profile_list = "";
$ret = dba::select('contact', ['id'], ['uid' => 0, 'nurl' => $profiles]);
foreach ($profiles AS $profile) {
if ($profile_list != "")
$profile_list .= "', '";
$contacts = [];
$profile_list .= dbesc($profile);
while ($contact = dba::fetch($ret)) {
$contacts[] = $contact['id'];
}
$profile_list = "'".$profile_list."'";
$contact_list = implode(',', $contacts);
dba::close($ret);
// Only act if it is a "real" post
// We need the additional check for the "local_profile" because of mixed situations on connector networks
$item = q("SELECT `id`, `mention`, `tag`,`parent`, `title`, `body`, `author-id`, `guid`,
`parent-uri`, `uri`, `contact-id`, `network`
FROM `item` WHERE `id` = %d AND `verb` IN ('%s', '') AND `type` != 'activity' AND
NOT (`author-link` IN ($profile_list)) LIMIT 1",
NOT (`author-id` IN ($contact_list)) LIMIT 1",
intval($itemid), dbesc(ACTIVITY_POST));
if (!$item)
return false;
@ -807,7 +808,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
// Is it a post that the user had started or where he interacted?
$parent = q("SELECT `thread`.`iid` FROM `thread` INNER JOIN `item` ON `item`.`parent` = `thread`.`iid`
WHERE `thread`.`iid` = %d AND NOT `thread`.`ignored` AND
(`thread`.`mention` OR `item`.`author-link` IN ($profile_list))
(`thread`.`mention` OR `item`.`author-id` IN ($contact_list))
LIMIT 1",
intval($item[0]["parent"]));

View file

@ -258,7 +258,7 @@ function acl_content(App $a)
$condition = ["`parent` = ?", $conv_id];
$params = ['order' => ['author-name' => true]];
$authors = Item::select(local_user(), ['author-link'], $condition, $params);
$authors = Item::selectForUser(local_user(), ['author-link'], $condition, $params);
$item_authors = [];
while ($author = dba::fetch($authors)) {
$item_authors[$author['author-link']] = $author['author-link'];

View file

@ -349,7 +349,7 @@ function display_content(App $a, $update = false, $update_uid = 0) {
$condition = ["`item`.`parent-uri` = (SELECT `parent-uri` FROM `item` WHERE `id` = ?)
AND `item`.`uid` IN (0, ?) " . $sql_extra, $item_id, local_user()];
$params = ['order' => ['uid', 'parent' => true, 'gravity', 'id']];
$r = Item::select(local_user(), [], $condition, $params);
$r = Item::selectForUser(local_user(), [], $condition, $params);
if (!DBM::is_result($r)) {
notice(L10n::t('Item not found.') . EOL);

View file

@ -455,7 +455,7 @@ function networkFlatView(App $a, $update = 0)
}
$params = ['order' => ['id' => true], 'limit' => [$a->pager['start'], $a->pager['itemspage']]];
$result = Item::select(local_user(), [], $condition, $params);
$result = Item::selectForUser(local_user(), [], $condition, $params);
$items = dba::inArray($result);
$condition = ['unseen' => true, 'uid' => local_user()];

View file

@ -68,7 +68,7 @@ function notes_content(App $a, $update = false)
$params = ['order' => ['created' => true],
'limit' => [$a->pager['start'], $a->pager['itemspage']]];
$r = Item::select(local_user(), ['item_id'], $condition, $params);
$r = Item::selectForUser(local_user(), ['item_id'], $condition, $params);
if (DBM::is_result($r)) {
$parents_arr = [];
@ -79,7 +79,7 @@ function notes_content(App $a, $update = false)
dba::close($r);
$condition = ['uid' => local_user(), 'parent' => $parents_arr];
$result = Item::select(local_user(), [], $condition);
$result = Item::selectForUser(local_user(), [], $condition);
if (DBM::is_result($result)) {
$items = conv_sort(dba::inArray($result), 'commented');
$o .= conversation($a, $items, 'notes', $update);

View file

@ -132,7 +132,7 @@ function ping_init(App $a)
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
$params = ['order' => ['created' => true]];
$items = Item::select(local_user(), $fields, $condition, $params);
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
if (DBM::is_result($items)) {
$items_unseen = dba::inArray($items);

View file

@ -71,7 +71,7 @@ function poke_init(App $a) {
if ($parent) {
$fields = ['uri', 'private', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid'];
$condition = ['id' => $parent, 'parent' => $parent, 'uid' => $uid];
$item = Item::selectFirst(local_user(), $fields, $condition);
$item = Item::selectFirst($fields, $condition);
if (DBM::is_result($item)) {
$parent_uri = $item['uri'];

View file

@ -338,7 +338,7 @@ function profile_content(App $a, $update = 0)
}
$condition = ['uid' => $a->profile['profile_uid'], 'parent' => $parents_arr];
$result = Item::select($a->profile['profile_uid'], [], $condition);
$result = Item::selectForUser($a->profile['profile_uid'], [], $condition);
$items = conv_sort(dba::inArray($result), 'created');
} else {
$items = [];

View file

@ -211,7 +211,7 @@ function search_content(App $a) {
}
dba::close($terms);
$items = Item::select(local_user(), [], ['id' => array_reverse($itemids)]);
$items = Item::selectForUser(local_user(), [], ['id' => array_reverse($itemids)]);
$r = dba::inArray($items);
} else {
logger("Start fulltext search for '".$search."'", LOGGER_DEBUG);
@ -221,7 +221,7 @@ function search_content(App $a) {
local_user(), $search];
$params = ['order' => ['id' => true],
'limit' => [$a->pager['start'], $a->pager['itemspage']]];
$items = Item::select(local_user(), [], $condition, $params);
$items = Item::selectForUser(local_user(), [], $condition, $params);
$r = dba::inArray($items);
}

View file

@ -13,7 +13,7 @@ function share_init(App $a) {
$fields = ['private', 'body', 'author-name', 'author-link', 'author-avatar',
'guid', 'created', 'plink', 'title'];
$item = Item::selectFirst(local_user(), $fields, ['id' => $post_id]);
$item = Item::selectFirst($fields, ['id' => $post_id]);
if (!DBM::is_result($item) || $item['private'] == 1) {
killme();

View file

@ -23,7 +23,7 @@ function subthread_content(App $a) {
$item_id = (($a->argc > 1) ? notags(trim($a->argv[1])) : 0);
$condition = ["`parent` = ? OR `parent-uri` = ? AND `parent` = `id`", $item_id, $item_id];
$item = Item::selectFirst(local_user(), [], $condition);
$item = Item::selectFirst([], $condition);
if (empty($item_id) || !DBM::is_result($item)) {
logger('subthread: no item ' . $item_id);

View file

@ -32,7 +32,7 @@ function tagger_content(App $a) {
logger('tagger: tag ' . $term . ' item ' . $item_id);
$item = Item::selectFirst(local_user(), [], ['id' => $item_id]);
$item = Item::selectFirst([], ['id' => $item_id]);
if (!$item_id || !DBM::is_result($item)) {
logger('tagger: no item ' . $item_id);

View file

@ -407,7 +407,7 @@ class NotificationsManager extends BaseObject
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
$items = Item::select(local_user(), $fields, $condition, $params);
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
if (DBM::is_result($items)) {
$notifs = $this->formatNotifs(dba::inArray($items), $ident);
@ -492,7 +492,7 @@ class NotificationsManager extends BaseObject
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
$items = Item::select(local_user(), $fields, $condition, $params);
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
if (DBM::is_result($items)) {
$notifs = $this->formatNotifs(dba::inArray($items), $ident);
@ -532,7 +532,7 @@ class NotificationsManager extends BaseObject
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
$items = Item::select(local_user(), $fields, $condition, $params);
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
if (DBM::is_result($items)) {
$notifs = $this->formatNotifs(dba::inArray($items), $ident);

View file

@ -1068,7 +1068,7 @@ class Contact extends BaseObject
$author_id, ACTIVITY_POST, local_user()];
$params = ['order' => ['created' => true],
'limit' => [$a->pager['start'], $a->pager['itemspage']]];
$r = Item::select(local_user(), [], $condition, $params);
$r = Item::selectForUser(local_user(), [], $condition, $params);
$items = dba::inArray($r);

View file

@ -33,8 +33,31 @@ require_once 'include/text.php';
class Item extends BaseObject
{
// Field list that is used to display the items
const DISPLAY_FIELDLIST = ['uid', 'id', 'parent', 'uri', 'thr-parent', 'parent-uri', 'guid',
'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
'wall', 'private', 'starred', 'origin', 'title', 'body', 'file', 'attach',
'content-warning', 'location', 'coord', 'app', 'rendered-hash', 'rendered-html', 'object',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'item_id', 'item_network',
'author-id', 'author-link', 'author-name', 'author-avatar',
'owner-id', 'owner-link', 'owner-name', 'owner-avatar',
'contact-id', 'contact-link', 'contact-name', 'contact-avatar',
'network', 'url', 'name', 'writable', 'self', 'cid', 'alias',
'event-id', 'event-created', 'event-edited', 'event-start', 'event-finish',
'event-summary', 'event-desc', 'event-location', 'event-type',
'event-nofinish', 'event-adjust', 'event-ignore', 'event-id'];
// Field list that is used to deliver items via the protocols
const DELIVER_FIELDLIST = ['uid', 'id', 'parent', 'uri', 'thr-parent', 'parent-uri', 'guid',
'created', 'edited', 'verb', 'object-type', 'object', 'target',
'private', 'title', 'body', 'location', 'coord', 'app',
'attach', 'tag', 'bookmark', 'deleted', 'extid',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
'author-id', 'author-link', 'owner-link', 'contact-uid',
'signed_text', 'signature', 'signer'];
/**
* Retrieve a single record from the item table and returns it in an associative array
* Retrieve a single record from the item table for a given user and returns it in an associative array
*
* @brief Retrieve a single record from a table
* @param integer $uid User ID
@ -44,10 +67,53 @@ class Item extends BaseObject
* @return bool|array
* @see dba::select
*/
public static function selectFirst($uid, array $fields = [], array $condition = [], $params = [])
public static function selectFirstForUser($uid, array $selected = [], array $condition = [], $params = [])
{
$params['uid'] = $uid;
if (empty($selected)) {
$selected = Item::DISPLAY_FIELDLIST;
}
return self::selectFirst($selected, $condition, $params);
}
/**
* @brief Select rows from the item table for a given user
*
* @param integer $uid User ID
* @param array $selected Array of selected fields, empty for all
* @param array $condition Array of fields for condition
* @param array $params Array of several parameters
*
* @return boolean|object
*/
public static function selectForUser($uid, array $selected = [], array $condition = [], $params = [])
{
$params['uid'] = $uid;
if (empty($selected)) {
$selected = Item::DISPLAY_FIELDLIST;
}
return self::select($selected, $condition, $params);
}
/**
* Retrieve a single record from the item table and returns it in an associative array
*
* @brief Retrieve a single record from a table
* @param array $fields
* @param array $condition
* @param array $params
* @return bool|array
* @see dba::select
*/
public static function selectFirst(array $fields = [], array $condition = [], $params = [])
{
$params['limit'] = 1;
$result = self::select($uid, $fields, $condition, $params);
$result = self::select($fields, $condition, $params);
if (is_bool($result)) {
return $result;
@ -61,15 +127,22 @@ class Item extends BaseObject
/**
* @brief Select rows from the item table
*
* @param integer $uid User ID
* @param array $fields Array of selected fields, empty for all
* @param array $selected Array of selected fields, empty for all
* @param array $condition Array of fields for condition
* @param array $params Array of several parameters
*
* @return boolean|object
*/
public static function select($uid, array $selected = [], array $condition = [], $params = [])
public static function select(array $selected = [], array $condition = [], $params = [])
{
$uid = 0;
$usermode = false;
if (isset($params['uid'])) {
$uid = $params['uid'];
$usermode = true;
}
$fields = self::fieldlist($selected);
$select_fields = self::constructSelectFields($fields, $selected);
@ -78,7 +151,9 @@ class Item extends BaseObject
$condition_string = self::addTablesToFields($condition_string, $fields);
if ($usermode) {
$condition_string = $condition_string . ' AND ' . self::condition(false);
}
$param_string = self::addTablesToFields(dba::buildParameter($params), $fields);
@ -100,10 +175,10 @@ class Item extends BaseObject
* @return bool|array
* @see dba::select
*/
public static function selectFirstThread($uid, array $fields = [], array $condition = [], $params = [])
public static function selectFirstThreadForUser($uid, array $fields = [], array $condition = [], $params = [])
{
$params['limit'] = 1;
$result = self::selectThread($uid, $fields, $condition, $params);
$result = self::selectThreadForUser($uid, $fields, $condition, $params);
if (is_bool($result)) {
return $result;
@ -124,8 +199,12 @@ class Item extends BaseObject
*
* @return boolean|object
*/
public static function selectThread($uid, array $selected = [], array $condition = [], $params = [])
public static function selectThreadForUser($uid, array $selected = [], array $condition = [], $params = [])
{
if (empty($selected)) {
$selected = Item::DISPLAY_FIELDLIST;
}
$fields = self::fieldlist($selected);
$threadfields = ['thread' => ['iid', 'uid', 'contact-id', 'owner-id', 'author-id',
@ -160,40 +239,39 @@ class Item extends BaseObject
*/
private static function fieldlist($selected)
{
/*
These Fields are not added below. They are here to for bug search.
'type', 'extid', 'changed', 'moderated', 'target-type', 'target', 'resource-id',
'tag', 'inform', 'pubmail', 'visible', 'bookmark', 'unseen', 'deleted',
'forum_mode', 'mention', 'global', 'shadow',
*/
$fields = [];
$item_fields = ['author-id', 'owner-id', 'contact-id', 'uid', 'id', 'parent',
'uri', 'thr-parent', 'parent-uri', 'content-warning',
'commented', 'created', 'edited', 'received', 'verb', 'object-type', 'postopts', 'plink',
'guid', 'wall', 'private', 'starred', 'origin', 'title', 'body', 'file', 'event-id',
'location', 'coord', 'app', 'attach', 'rendered-hash', 'rendered-html', 'object',
'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'unseen',
$fields['item'] = ['id', 'uid', 'parent', 'uri', 'parent-uri', 'thr-parent', 'guid',
'contact-id', 'owner-id', 'author-id', 'type', 'wall', 'gravity', 'extid',
'created', 'edited', 'commented', 'received', 'changed',
'title', 'body', 'app', 'verb', 'object-type', 'object', 'target-type', 'target',
'postopts', 'plink', 'resource-id', 'event-id', 'tag', 'attach', 'inform',
'file', 'location', 'coord', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid',
'private', 'pubmail', 'moderated', 'visible', 'starred', 'bookmark',
'unseen', 'deleted', 'origin', 'forum_mode', 'mention',
'rendered-hash', 'rendered-html', 'global', 'shadow', 'content-warning',
'id' => 'item_id', 'network' => 'item_network'];
$author_fields = ['url' => 'author-link', 'name' => 'author-name', 'thumb' => 'author-avatar'];
$owner_fields = ['url' => 'owner-link', 'name' => 'owner-name', 'thumb' => 'owner-avatar'];
$contact_fields = ['url' => 'contact-link', 'name' => 'contact-name', 'thumb' => 'contact-avatar',
'network', 'url', 'name', 'writable', 'self', 'id' => 'cid', 'alias'];
$fields['author'] = ['url' => 'author-link', 'name' => 'author-name', 'thumb' => 'author-avatar'];
$event_fields = ['created' => 'event-created', 'edited' => 'event-edited',
$fields['owner'] = ['url' => 'owner-link', 'name' => 'owner-name', 'thumb' => 'owner-avatar'];
$fields['contact'] = ['url' => 'contact-link', 'name' => 'contact-name', 'thumb' => 'contact-avatar',
'network', 'url', 'name', 'writable', 'self', 'id' => 'cid', 'alias', 'uid' => 'contact-uid',
'photo', 'name-date', 'uri-date', 'avatar-date', 'thumb', 'dfrn-id'];
$fields['parent-item'] = ['guid' => 'parent-guid'];
$fields['parent-item-author'] = ['url' => 'parent-author-link', 'name' => 'parent-author-name'];
$fields['event'] = ['created' => 'event-created', 'edited' => 'event-edited',
'start' => 'event-start','finish' => 'event-finish',
'summary' => 'event-summary','desc' => 'event-desc',
'location' => 'event-location', 'type' => 'event-type',
'nofinish' => 'event-nofinish','adjust' => 'event-adjust',
'ignore' => 'event-ignore', 'id' => 'event-id'];
$fields = ['item' => $item_fields, 'author' => $author_fields, 'owner' => $owner_fields,
'contact' => $contact_fields, 'event' => $event_fields];
if (!empty($selected)) {
$fields['parent-item'] = ['guid' => 'parent-guid'];
$fields['parent-item-author'] = ['url' => 'parent-author-link', 'name' => 'parent-author-name'];
}
$fields['sign'] = ['signed_text', 'signature', 'signer'];
return $fields;
}
@ -257,6 +335,10 @@ class Item extends BaseObject
$joins .= " LEFT JOIN `event` ON `event-id` = `event`.`id`";
}
if (strpos($sql_commands, "`sign`.") !== false) {
$joins .= " LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`";
}
if ((strpos($sql_commands, "`parent-item`.") !== false) || (strpos($sql_commands, "`parent-author`.") !== false)) {
$joins .= " STRAIGHT_JOIN `item` AS `parent-item` ON `parent-item`.`id` = `item`.`parent`";
}

View file

@ -228,17 +228,10 @@ class DFRN
$check_date = DateTimeFormat::utc($last_update);
$r = q(
"SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`,
`contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
`contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`sign`.`signed_text`, `sign`.`signature`, `sign`.`signer`
"SELECT `item`.`id`
FROM `item` USE INDEX (`uid_wall_changed`) $sql_post_table
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`
WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`moderated` AND `item`.`parent` != 0
AND `item`.`wall` AND `item`.`changed` > '%s'
WHERE `item`.`uid` = %d AND `item`.`wall` AND `item`.`changed` > '%s'
$sql_extra
ORDER BY `item`.`parent` ".$sort.", `item`.`created` ASC LIMIT 0, 300",
intval($owner_id),
@ -246,13 +239,23 @@ class DFRN
dbesc($sort)
);
$ids = [];
foreach ($r as $item) {
$ids[] = $item['id'];
}
if (!empty($ids)) {
$ret = Item::select(Item::DELIVER_FIELDLIST, ['id' => $ids]);
$items = dba::inArray($ret);
} else {
$items = [];
}
/*
* Will check further below if this actually returned results.
* We will provide an empty feed if that is the case.
*/
$items = $r;
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
@ -321,33 +324,18 @@ class DFRN
public static function itemFeed($item_id, $conversation = false)
{
if ($conversation) {
$condition = '`item`.`parent`';
$condition = ['parent' => $item_id];
} else {
$condition = '`item`.`id`';
$condition = ['id' => $item_id];
}
$r = q(
"SELECT `item`.*, `item`.`id` AS `item_id`,
`contact`.`name`, `contact`.`network`, `contact`.`photo`, `contact`.`url`,
`contact`.`name-date`, `contact`.`uri-date`, `contact`.`avatar-date`,
`contact`.`thumb`, `contact`.`dfrn-id`, `contact`.`self`,
`sign`.`signed_text`, `sign`.`signature`, `sign`.`signer`
FROM `item`
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`
WHERE %s = %d AND `item`.`visible` AND NOT `item`.`moderated` AND `item`.`parent` != 0
AND NOT `item`.`private`",
$condition,
intval($item_id)
);
if (!DBM::is_result($r)) {
$ret = Item::select(Item::DELIVER_FIELDLIST, $condition);
$items = dba::inArray($ret);
if (!DBM::is_result($items)) {
killme();
}
$items = $r;
$item = $r[0];
$item = $items[0];
if ($item['uid'] != 0) {
$owner = User::getOwnerDataById($item['uid']);
@ -2253,6 +2241,8 @@ class DFRN
}
if ($Blink && link_compare($Blink, System::baseUrl() . "/profile/" . $importer["nickname"])) {
$author = dba::selectFirst('contact', ['name', 'thumb', 'url'], ['id' => $item['author-id']]);
// send a notification
notification(
[
@ -2264,10 +2254,9 @@ class DFRN
"uid" => $importer["importer_uid"],
"item" => $item,
"link" => System::baseUrl()."/display/".urlencode(Item::getGuidById($posted_id)),
"source_name" => stripslashes($item["author-name"]),
"source_link" => $item["author-link"],
"source_photo" => ((link_compare($item["author-link"], $importer["url"]))
? $importer["thumb"] : $item["author-avatar"]),
"source_name" => $author["name"],
"source_link" => $author["url"],
"source_photo" => $author["thumb"],
"verb" => $item["verb"],
"otype" => "person",
"activity" => $verb,
@ -2334,9 +2323,9 @@ class DFRN
// only one like or dislike per person
// splitted into two queries for performance issues
$r = q(
"SELECT `id` FROM `item` WHERE `uid` = %d AND `author-link` = '%s' AND `verb` = '%s' AND `parent-uri` = '%s' AND NOT `deleted` LIMIT 1",
"SELECT `id` FROM `item` WHERE `uid` = %d AND `author-id` = %d AND `verb` = '%s' AND `parent-uri` = '%s' AND NOT `deleted` LIMIT 1",
intval($item["uid"]),
dbesc($item["author-link"]),
intval($item["author-id"]),
dbesc($item["verb"]),
dbesc($item["parent-uri"])
);
@ -2345,9 +2334,9 @@ class DFRN
}
$r = q(
"SELECT `id` FROM `item` WHERE `uid` = %d AND `author-link` = '%s' AND `verb` = '%s' AND `thr-parent` = '%s' AND NOT `deleted` LIMIT 1",
"SELECT `id` FROM `item` WHERE `uid` = %d AND `author-id` = %d AND `verb` = '%s' AND `thr-parent` = '%s' AND NOT `deleted` LIMIT 1",
intval($item["uid"]),
dbesc($item["author-link"]),
intval($item["author-id"]),
dbesc($item["verb"]),
dbesc($item["parent-uri"])
);
@ -2469,16 +2458,14 @@ class DFRN
// Fetch the owner
$owner = self::fetchauthor($xpath, $entry, $importer, "dfrn:owner", true);
$item["owner-name"] = $owner["name"];
$item["owner-link"] = $owner["link"];
$item["owner-avatar"] = $owner["avatar"];
$item["owner-id"] = Contact::getIdForURL($owner["link"], 0);
// fetch the author
$author = self::fetchauthor($xpath, $entry, $importer, "atom:author", true);
$item["author-name"] = $author["name"];
$item["author-link"] = $author["link"];
$item["author-avatar"] = $author["avatar"];
$item["author-id"] = Contact::getIdForURL($author["link"], 0);
$item["title"] = $xpath->query("atom:title/text()", $entry)->item(0)->nodeValue;
@ -2736,9 +2723,8 @@ class DFRN
* but we're going to unconditionally correct it here so that the post will always be owned by our contact.
*/
logger('Correcting item owner.', LOGGER_DEBUG);
$item["owner-name"] = $importer["senderName"];
$item["owner-link"] = $importer["url"];
$item["owner-avatar"] = $importer["thumb"];
$item["owner-id"] = Contact::getIdForURL($importer["url"], 0);
}
if (($importer["rel"] == CONTACT_IS_FOLLOWER) && (!self::tgroupCheck($importer["importer_uid"], $item))) {

View file

@ -69,7 +69,7 @@ class Diaspora
if (Config::get("system", "relay_directly", false)) {
// We distribute our stuff based on the parent to ensure that the thread will be complete
$parent = dba::selectFirst('item', ['parent'], ['id' => $item_id]);
$parent = Item::selectFirst(['parent'], ['id' => $item_id]);
if (!DBM::is_result($parent)) {
return;
}
@ -1170,15 +1170,10 @@ class Diaspora
*/
private static function messageExists($uid, $guid)
{
$r = q(
"SELECT `id` FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
intval($uid),
dbesc($guid)
);
if (DBM::is_result($r)) {
$item = Item::selectFirst(['id'], ['uid' => $uid, 'guid' => $guid]);
if (DBM::is_result($item)) {
logger("message ".$guid." already exists for user ".$uid);
return $r[0]["id"];
return $item["id"];
}
return false;
@ -1385,16 +1380,13 @@ class Diaspora
*/
private static function parentItem($uid, $guid, $author, $contact)
{
$r = q(
"SELECT `id`, `parent`, `body`, `wall`, `uri`, `guid`, `private`, `origin`,
`author-name`, `author-link`, `author-avatar`,
`owner-name`, `owner-link`, `owner-avatar`
FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
intval($uid),
dbesc($guid)
);
$fields = ['id', 'parent', 'body', 'wall', 'uri', 'guid', 'private', 'origin',
'author-name', 'author-link', 'author-avatar',
'owner-name', 'owner-link', 'owner-avatar'];
$condition = ['uid' => $uid, 'guid' => $guid];
$item = Item::selectFirst($fields, $condition);
if (!$r) {
if (!DBM::is_result($item)) {
$result = self::storeByGuid($guid, $contact["url"], $uid);
if (!$result) {
@ -1405,23 +1397,16 @@ class Diaspora
if ($result) {
logger("Fetched missing item ".$guid." - result: ".$result, LOGGER_DEBUG);
$r = q(
"SELECT `id`, `body`, `wall`, `uri`, `private`, `origin`,
`author-name`, `author-link`, `author-avatar`,
`owner-name`, `owner-link`, `owner-avatar`
FROM `item` WHERE `uid` = %d AND `guid` = '%s' LIMIT 1",
intval($uid),
dbesc($guid)
);
$item = Item::selectFirst($fields, $condition);
}
}
if (!$r) {
if (!DBM::is_result($item)) {
logger("parent item not found: parent: ".$guid." - user: ".$uid);
return false;
} else {
logger("parent item found: parent: ".$guid." - user: ".$uid);
return $r[0];
return $item;
}
}
@ -1602,7 +1587,7 @@ class Diaspora
*/
private static function getUriFromGuid($author, $guid, $onlyfound = false)
{
$item = dba::selectFirst('item', ['uri'], ['guid' => $guid]);
$item = Item::selectFirst(['uri'], ['guid' => $guid]);
if (DBM::is_result($item)) {
return $item["uri"];
} elseif (!$onlyfound) {
@ -1632,9 +1617,9 @@ class Diaspora
*/
private static function getGuidFromUri($uri, $uid)
{
$r = q("SELECT `guid` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($uri), intval($uid));
if (DBM::is_result($r)) {
return $r[0]["guid"];
$item = Item::selectFirst(['guid'], ['uri' => $uri, 'uid' => $uid]);
if (DBM::is_result($item)) {
return $item["guid"];
} else {
return false;
}
@ -1649,11 +1634,10 @@ class Diaspora
*/
private static function importerForGuid($guid)
{
$item = dba::fetch_first("SELECT `uid` FROM `item` WHERE `origin` AND `guid` = ? LIMIT 1", $guid);
$item = Item::selectFirst(['uid'], ['origin' => true, 'guid' => $guid]);
if (DBM::is_result($item)) {
logger("Found user ".$item['uid']." as owner of item ".$guid, LOGGER_DEBUG);
$contact = dba::fetch_first("SELECT * FROM `contact` WHERE `self` AND `uid` = ?", $item['uid']);
$contact = dba::selectFirst('contact', [], ['self' => true, 'uid' => $item['uid']]);
if (DBM::is_result($contact)) {
return $contact;
}
@ -1721,13 +1705,11 @@ class Diaspora
$datarray["contact-id"] = $author_contact["cid"];
$datarray["network"] = $author_contact["network"];
$datarray["author-name"] = $person["name"];
$datarray["author-link"] = $person["url"];
$datarray["author-avatar"] = ((x($person, "thumb")) ? $person["thumb"] : $person["photo"]);
$datarray["author-id"] = Contact::getIdForURL($person["url"], 0);
$datarray["owner-name"] = $contact["name"];
$datarray["owner-link"] = $contact["url"];
$datarray["owner-avatar"] = ((x($contact, "thumb")) ? $contact["thumb"] : $contact["photo"]);
$datarray["owner-id"] = Contact::getIdForURL($contact["url"], 0);
$datarray["guid"] = $guid;
$datarray["uri"] = self::getUriFromGuid($author, $guid);
@ -2056,13 +2038,11 @@ class Diaspora
$datarray["contact-id"] = $author_contact["cid"];
$datarray["network"] = $author_contact["network"];
$datarray["author-name"] = $person["name"];
$datarray["author-link"] = $person["url"];
$datarray["author-avatar"] = ((x($person, "thumb")) ? $person["thumb"] : $person["photo"]);
$datarray["author-id"] = Contact::getIdForURL($person["url"], 0);
$datarray["owner-name"] = $contact["name"];
$datarray["owner-link"] = $contact["url"];
$datarray["owner-avatar"] = ((x($contact, "thumb")) ? $contact["thumb"] : $contact["photo"]);
$datarray["owner-id"] = Contact::getIdForURL($contact["url"], 0);
$datarray["guid"] = $guid;
$datarray["uri"] = self::getUriFromGuid($author, $guid);
@ -2079,7 +2059,7 @@ class Diaspora
// like on comments have the comment as parent. So we need to fetch the toplevel parent
if ($parent_item["id"] != $parent_item["parent"]) {
$toplevel = dba::selectFirst('item', ['origin'], ['id' => $parent_item["parent"]]);
$toplevel = Item::selectFirst(['origin'], ['id' => $parent_item["parent"]]);
$origin = $toplevel["origin"];
} else {
$origin = $parent_item["origin"];
@ -2216,7 +2196,7 @@ class Diaspora
return false;
}
$item = dba::selectFirst('item', ['id'], ['guid' => $parent_guid, 'origin' => true, 'private' => false]);
$item = Item::selectFirst(['id'], ['guid' => $parent_guid, 'origin' => true, 'private' => false]);
if (!DBM::is_result($item)) {
logger('Item not found, no origin or private: '.$parent_guid);
return false;
@ -2237,11 +2217,11 @@ class Diaspora
}
// Send all existing comments and likes to the requesting server
$comments = dba::p("SELECT `item`.`id`, `item`.`verb`, `contact`.`self`
FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`parent` = ? AND `item`.`id` != `item`.`parent`", $item['id']);
$comments = Item::select(['id', 'verb', 'self'], ['parent' => $item['id']]);
while ($comment = dba::fetch($comments)) {
if ($comment['id'] == $comment['parent']) {
continue;
}
if ($comment['verb'] == ACTIVITY_POST) {
$cmd = $comment['self'] ? 'comment-new' : 'comment-import';
} else {
@ -2599,7 +2579,7 @@ class Diaspora
$fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
'author-name', 'author-link', 'author-avatar'];
$condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false];
$item = dba::selectfirst('item', $fields, $condition);
$item = Item::selectFirst($fields, $condition);
if (DBM::is_result($item)) {
logger("reshared message ".$guid." already exists on system.");
@ -2643,7 +2623,7 @@ class Diaspora
$fields = ['body', 'tag', 'app', 'created', 'object-type', 'uri', 'guid',
'author-name', 'author-link', 'author-avatar'];
$condition = ['guid' => $guid, 'visible' => true, 'deleted' => false, 'private' => false];
$item = dba::selectfirst('item', $fields, $condition);
$item = Item::selectFirst($fields, $condition);
if (DBM::is_result($item)) {
// If it is a reshared post from another network then reformat to avoid display problems with two share elements
@ -2701,13 +2681,11 @@ class Diaspora
$datarray["contact-id"] = $contact["id"];
$datarray["network"] = NETWORK_DIASPORA;
$datarray["author-name"] = $contact["name"];
$datarray["author-link"] = $contact["url"];
$datarray["author-avatar"] = ((x($contact, "thumb")) ? $contact["thumb"] : $contact["photo"]);
$datarray["author-id"] = Contact::getIdForURL($contact["url"], 0);
$datarray["owner-name"] = $datarray["author-name"];
$datarray["owner-link"] = $datarray["author-link"];
$datarray["owner-avatar"] = $datarray["author-avatar"];
$datarray["owner-id"] = $datarray["author-id"];
$datarray["guid"] = $guid;
$datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
@ -2787,7 +2765,7 @@ class Diaspora
} else {
$condition = ["`guid` = ? AND `uid` = ? AND NOT `file` LIKE '%%[%%' AND NOT `deleted`", $target_guid, $importer['uid']];
}
$r = dba::select('item', $fields, $condition);
$r = Item::select($fields, $condition);
if (!DBM::is_result($r)) {
logger("Target guid ".$target_guid." was not found on this system for user ".$importer['uid'].".");
return false;
@ -2795,7 +2773,7 @@ class Diaspora
while ($item = dba::fetch($r)) {
// Fetch the parent item
$parent = dba::selectFirst('item', ['author-link'], ['id' => $item["parent"]]);
$parent = Item::selectFirst(['author-link'], ['id' => $item["parent"]]);
// Only delete it if the parent author really fits
if (!link_compare($parent["author-link"], $contact["url"]) && !link_compare($item["author-link"], $contact["url"])) {
@ -2921,13 +2899,11 @@ class Diaspora
$datarray["contact-id"] = $contact["id"];
$datarray["network"] = NETWORK_DIASPORA;
$datarray["author-name"] = $contact["name"];
$datarray["author-link"] = $contact["url"];
$datarray["author-avatar"] = ((x($contact, "thumb")) ? $contact["thumb"] : $contact["photo"]);
$datarray["author-id"] = Contact::getIdForURL($contact["url"], 0);
$datarray["owner-name"] = $datarray["author-name"];
$datarray["owner-link"] = $datarray["author-link"];
$datarray["owner-avatar"] = $datarray["author-avatar"];
$datarray["owner-id"] = $datarray["author-id"];
$datarray["guid"] = $guid;
$datarray["uri"] = $datarray["parent-uri"] = self::getUriFromGuid($author, $guid);
@ -3433,7 +3409,7 @@ class Diaspora
if (($guid != "") && $complete) {
$condition = ['guid' => $guid, 'network' => [NETWORK_DFRN, NETWORK_DIASPORA]];
$item = dba::selectFirst('item', ['contact-id'], $condition);
$item = Item::selectFirst(['contact-id'], $condition);
if (DBM::is_result($item)) {
$ret= [];
$ret["root_handle"] = self::handleFromContact($item["contact-id"]);
@ -3700,16 +3676,11 @@ class Diaspora
*/
private static function constructLike($item, $owner)
{
$p = q(
"SELECT `guid`, `uri`, `parent-uri` FROM `item` WHERE `uri` = '%s' LIMIT 1",
dbesc($item["thr-parent"])
);
if (!DBM::is_result($p)) {
$parent = Item::selectFirst(['guid', 'uri', 'parent-uri'], ['uri' => $item["thr-parent"]]);
if (!DBM::is_result($parent)) {
return false;
}
$parent = $p[0];
$target_type = ($parent["uri"] === $parent["parent-uri"] ? "Post" : "Comment");
$positive = null;
if ($item['verb'] === ACTIVITY_LIKE) {
@ -3736,16 +3707,11 @@ class Diaspora
*/
private static function constructAttend($item, $owner)
{
$p = q(
"SELECT `guid`, `uri`, `parent-uri` FROM `item` WHERE `uri` = '%s' LIMIT 1",
dbesc($item["thr-parent"])
);
if (!DBM::is_result($p)) {
$parent = Item::selectFirst(['guid', 'uri', 'parent-uri'], ['uri' => $item["thr-parent"]]);
if (!DBM::is_result($parent)) {
return false;
}
$parent = $p[0];
switch ($item['verb']) {
case ACTIVITY_ATTEND:
$attend_answer = 'accepted';
@ -3785,18 +3751,11 @@ class Diaspora
return $result;
}
$p = q(
"SELECT `guid` FROM `item` WHERE `parent` = %d AND `id` = %d LIMIT 1",
intval($item["parent"]),
intval($item["parent"])
);
if (!DBM::is_result($p)) {
$parent = Item::selectFirst(['guid'], ['id' => $item["parent"], 'parent' => $item["parent"]]);
if (!DBM::is_result($parent)) {
return false;
}
$parent = $p[0];
$text = html_entity_decode(BBCode::toMarkdown($item["body"]));
$created = DateTimeFormat::utc($item["created"], DateTimeFormat::ATOM);
@ -4265,16 +4224,16 @@ class Diaspora
$contact["uprvkey"] = $r[0]['prvkey'];
$r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1", intval($post_id));
if (!DBM::is_result($r)) {
$item = Item::selectFirst([], ['id' => $post_id]);
if (!DBM::is_result($item)) {
return false;
}
if (!in_array($r[0]["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
if (!in_array($item["verb"], [ACTIVITY_LIKE, ACTIVITY_DISLIKE])) {
return false;
}
$message = self::constructLike($r[0], $contact);
$message = self::constructLike($item, $contact);
if ($message === false) {
return false;
}

View file

@ -59,14 +59,10 @@ class Delivery extends BaseObject
}
$parent_id = intval($item['parent']);
$itemdata = dba::p("SELECT `item`.*, `contact`.`uid` AS `cuid`,
`sign`.`signed_text`,`sign`.`signature`,`sign`.`signer`
FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id`
WHERE `item`.`id` IN (?, ?) AND `visible` AND NOT `moderated`
ORDER BY `item`.`id`",
$item_id, $parent_id);
$condition = ['id' => [$item_id, $parent_id], 'visible' => true, 'moderated' => false];
$params = ['order' => ['id']];
$itemdata = Item::select([], $condition, $params);
$items = [];
while ($item = dba::fetch($itemdata)) {
if ($item['id'] == $parent_id) {
@ -79,7 +75,7 @@ class Delivery extends BaseObject
}
dba::close($itemdata);
$uid = $target_item['cuid'];
$uid = $target_item['contact-uid'];
// avoid race condition with deleting entries
if ($items[0]['deleted']) {

View file

@ -10,6 +10,7 @@ use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Group;
use Friendica\Model\Item;
use Friendica\Model\User;
use Friendica\Model\PushSubscriber;
use Friendica\Network\Probe;
@ -104,27 +105,27 @@ class Notifier {
intval($uid), NETWORK_DFRN, NETWORK_DIASPORA);
} else {
// find ancestors
$target_item = dba::fetch_first("SELECT `item`.*, `contact`.`uid` AS `cuid` FROM `item`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`id` = ? AND `visible` AND NOT `moderated`", $item_id);
$condition = ['id' => $item_id, 'visible' => true, 'moderated' => false];
$target_item = Item::selectFirst([], $condition);
if (!DBM::is_result($target_item) || !intval($target_item['parent'])) {
return;
}
$parent_id = intval($target_item['parent']);
$uid = $target_item['cuid'];
$uid = $target_item['contact-uid'];
$updated = $target_item['edited'];
$items = q("SELECT `item`.*, `sign`.`signed_text`,`sign`.`signature`,`sign`.`signer`
FROM `item` LEFT JOIN `sign` ON `sign`.`iid` = `item`.`id` WHERE `parent` = %d AND visible AND NOT moderated ORDER BY `id` ASC",
intval($parent_id)
);
$condition = ['parent' => $parent_id, 'visible' => true, 'moderated' => false];
$params = ['order' => ['id']];
$ret = Item::select([], $condition, $params);
if (!count($items)) {
if (!DBM::is_result($ret)) {
return;
}
$items = dba::inArray($ret);
// avoid race condition with deleting entries
if ($items[0]['deleted']) {
foreach ($items as $item) {