From 6e10de92847dd7ef1bf20f8eac05316fbe31e1e7 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 17 Jun 2018 17:05:17 +0000 Subject: [PATCH] New function to fetch item data especially for users --- include/api.php | 30 ++++++------ include/conversation.php | 2 +- include/enotify.php | 2 +- mod/acl.php | 2 +- mod/display.php | 2 +- mod/network.php | 2 +- mod/notes.php | 4 +- mod/ping.php | 2 +- mod/poke.php | 2 +- mod/profile.php | 2 +- mod/search.php | 4 +- mod/share.php | 2 +- mod/subthread.php | 2 +- mod/tagger.php | 2 +- src/Core/NotificationsManager.php | 6 +-- src/Model/Contact.php | 2 +- src/Model/Item.php | 80 +++++++++++++++++++++++++------ src/Protocol/DFRN.php | 24 ++++++---- src/Protocol/Diaspora.php | 38 +++++++-------- 19 files changed, 133 insertions(+), 77 deletions(-) diff --git a/include/api.php b/include/api.php index 9848862d55..d66446cb68 100644 --- a/include/api.php +++ b/include/api.php @@ -1626,7 +1626,7 @@ function api_search($type) } $params = ['order' => ['id' => true], 'limit' => [$start, $count]]; - $statuses = Item::select(api_user(), Item::DISPLAY_FIELDLIST, $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(), Item::DISPLAY_FIELDLIST, $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(), Item::DISPLAY_FIELDLIST, $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(), Item::DISPLAY_FIELDLIST, $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(), Item::DISPLAY_FIELDLIST, $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(), Item::DISPLAY_FIELDLIST, $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(), Item::DISPLAY_FIELDLIST, $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(), Item::DISPLAY_FIELDLIST, $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(), Item::DISPLAY_FIELDLIST, $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(), Item::DISPLAY_FIELDLIST, ['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(), Item::DISPLAY_FIELDLIST, $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(), Item::DISPLAY_FIELDLIST, $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(), Item::DISPLAY_FIELDLIST, $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(), Item::DISPLAY_FIELDLIST, ['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); diff --git a/include/conversation.php b/include/conversation.php index 9730c4af9d..97be7e9aa9 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -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(), Item::DISPLAY_FIELDLIST, $condition, $params); + $thread_items = Item::selectForUser(local_user(), [], $condition, $params); $comments = dba::inArray($thread_items); diff --git a/include/enotify.php b/include/enotify.php index 3e01736f15..00459ac5c0 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -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); diff --git a/mod/acl.php b/mod/acl.php index 7f17156896..ede6940329 100644 --- a/mod/acl.php +++ b/mod/acl.php @@ -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']; diff --git a/mod/display.php b/mod/display.php index ad71f3b1c4..7198d4bb5f 100644 --- a/mod/display.php +++ b/mod/display.php @@ -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(), Item::DISPLAY_FIELDLIST, $condition, $params); + $r = Item::selectForUser(local_user(), [], $condition, $params); if (!DBM::is_result($r)) { notice(L10n::t('Item not found.') . EOL); diff --git a/mod/network.php b/mod/network.php index 6921f54d80..61d957e1ad 100644 --- a/mod/network.php +++ b/mod/network.php @@ -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(), Item::DISPLAY_FIELDLIST, $condition, $params); + $result = Item::selectForUser(local_user(), [], $condition, $params); $items = dba::inArray($result); $condition = ['unseen' => true, 'uid' => local_user()]; diff --git a/mod/notes.php b/mod/notes.php index 0001a035f2..69b544472f 100644 --- a/mod/notes.php +++ b/mod/notes.php @@ -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(), Item::DISPLAY_FIELDLIST, $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); diff --git a/mod/ping.php b/mod/ping.php index 0256500dfe..06d83a1d9a 100644 --- a/mod/ping.php +++ b/mod/ping.php @@ -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); diff --git a/mod/poke.php b/mod/poke.php index 470f1eb2d6..55bb799d1f 100644 --- a/mod/poke.php +++ b/mod/poke.php @@ -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']; diff --git a/mod/profile.php b/mod/profile.php index 0efc9d5bec..49d6fe261d 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -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'], Item::DISPLAY_FIELDLIST, $condition); + $result = Item::selectForUser($a->profile['profile_uid'], [], $condition); $items = conv_sort(dba::inArray($result), 'created'); } else { $items = []; diff --git a/mod/search.php b/mod/search.php index 3c421984a2..6580246e4a 100644 --- a/mod/search.php +++ b/mod/search.php @@ -211,7 +211,7 @@ function search_content(App $a) { } dba::close($terms); - $items = Item::select(local_user(), Item::DISPLAY_FIELDLIST, ['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(), Item::DISPLAY_FIELDLIST, $condition, $params); + $items = Item::selectForUser(local_user(), [], $condition, $params); $r = dba::inArray($items); } diff --git a/mod/share.php b/mod/share.php index 8a40288853..fb4495019e 100644 --- a/mod/share.php +++ b/mod/share.php @@ -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(); diff --git a/mod/subthread.php b/mod/subthread.php index e2c11d0a3f..0b6f4ecaaa 100644 --- a/mod/subthread.php +++ b/mod/subthread.php @@ -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); diff --git a/mod/tagger.php b/mod/tagger.php index e72061b592..400c7787f6 100644 --- a/mod/tagger.php +++ b/mod/tagger.php @@ -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); diff --git a/src/Core/NotificationsManager.php b/src/Core/NotificationsManager.php index 609eafc438..8020a281b0 100644 --- a/src/Core/NotificationsManager.php +++ b/src/Core/NotificationsManager.php @@ -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); diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 4e46b49fdd..6a24b7da9f 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -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(), Item::DISPLAY_FIELDLIST, $condition, $params); + $r = Item::selectForUser(local_user(), [], $condition, $params); $items = dba::inArray($r); diff --git a/src/Model/Item.php b/src/Model/Item.php index 647c37d89d..4018db9ff6 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -57,7 +57,7 @@ class Item extends BaseObject '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 @@ -67,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; @@ -84,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); @@ -101,7 +151,9 @@ class Item extends BaseObject $condition_string = self::addTablesToFields($condition_string, $fields); - $condition_string = $condition_string . ' AND ' . self::condition(false); + if ($usermode) { + $condition_string = $condition_string . ' AND ' . self::condition(false); + } $param_string = self::addTablesToFields(dba::buildParameter($params), $fields); @@ -123,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; @@ -147,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', @@ -183,10 +239,6 @@ class Item extends BaseObject */ private static function fieldlist($selected) { - /* - These Fields are not added below. They are here to for bug search. - */ - $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', diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 7f5e0aa4da..2487b3ca57 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -244,15 +244,19 @@ class DFRN $ids[] = $item['id']; } - $condition = ['id' => $ids]; - $fields = ['author-id', 'uid', 'id', 'parent', 'uri', 'thr-parent', - 'parent-uri', 'created', 'edited', 'verb', 'object-type', - 'guid', 'private', 'title', 'body', 'location', 'coord', 'app', - 'attach', 'object', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', - 'extid', 'target', 'tag', 'bookmark', 'deleted', - 'author-link', 'owner-link', 'signed_text', 'signature', 'signer']; - $ret = Item::select($owner_id, $fields, $condition); - $items = dba::inArray($ret); + if (!empty($ids)) { + $condition = ['id' => $ids]; + $fields = ['author-id', 'uid', 'id', 'parent', 'uri', 'thr-parent', + 'parent-uri', 'created', 'edited', 'verb', 'object-type', + 'guid', 'private', 'title', 'body', 'location', 'coord', 'app', + 'attach', 'object', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', + 'extid', 'target', 'tag', 'bookmark', 'deleted', + 'author-link', 'owner-link', 'signed_text', 'signature', 'signer']; + $ret = Item::select($fields, $condition); + $items = dba::inArray($ret); + } else { + $items = []; + } /* * Will check further below if this actually returned results. @@ -338,7 +342,7 @@ class DFRN 'attach', 'object', 'allow_cid', 'allow_gid', 'deny_cid', 'deny_gid', 'extid', 'target', 'tag', 'bookmark', 'deleted', 'author-link', 'owner-link', 'signed_text', 'signature', 'signer']; - $ret = Item::select(0, $fields, $condition); + $ret = Item::select($fields, $condition); $items = dba::inArray($ret); if (!DBM::is_result($items)) { killme(); diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index cb41ba19ef..c42e8c2484 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -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 = Item::selectFirst(0, ['parent'], ['id' => $item_id]); + $parent = Item::selectFirst(['parent'], ['id' => $item_id]); if (!DBM::is_result($parent)) { return; } @@ -1170,7 +1170,7 @@ class Diaspora */ private static function messageExists($uid, $guid) { - $item = Item::selectFirst($uid, ['id'], ['uid' => $uid, 'guid' => $guid]); + $item = Item::selectFirst(['id'], ['uid' => $uid, 'guid' => $guid]); if (DBM::is_result($item)) { logger("message ".$guid." already exists for user ".$uid); return $item["id"]; @@ -1384,7 +1384,7 @@ class Diaspora 'author-name', 'author-link', 'author-avatar', 'owner-name', 'owner-link', 'owner-avatar']; $condition = ['uid' => $uid, 'guid' => $guid]; - $item = Item::selectFirst($uid, $fields, $condition); + $item = Item::selectFirst($fields, $condition); if (!DBM::is_result($item)) { $result = self::storeByGuid($guid, $contact["url"], $uid); @@ -1397,7 +1397,7 @@ class Diaspora if ($result) { logger("Fetched missing item ".$guid." - result: ".$result, LOGGER_DEBUG); - $item = Item::selectFirst($uid, $fields, $condition); + $item = Item::selectFirst($fields, $condition); } } @@ -1587,7 +1587,7 @@ class Diaspora */ private static function getUriFromGuid($author, $guid, $onlyfound = false) { - $item = Item::selectFirst(0, ['uri'], ['guid' => $guid]); + $item = Item::selectFirst(['uri'], ['guid' => $guid]); if (DBM::is_result($item)) { return $item["uri"]; } elseif (!$onlyfound) { @@ -1617,7 +1617,7 @@ class Diaspora */ private static function getGuidFromUri($uri, $uid) { - $item = Item::selectFirst($uid, ['guid'], ['uri' => $uri, 'uid' => $uid]); + $item = Item::selectFirst(['guid'], ['uri' => $uri, 'uid' => $uid]); if (DBM::is_result($item)) { return $item["guid"]; } else { @@ -1634,7 +1634,7 @@ class Diaspora */ private static function importerForGuid($guid) { - $item = Item::selectFirst(0, ['uid'], ['origin' => true, 'guid' => $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::selectFirst('contact', [], ['self' => true, 'uid' => $item['uid']]); @@ -2059,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 = Item::selectFirst($importer["uid"], ['origin'], ['id' => $parent_item["parent"]]); + $toplevel = Item::selectFirst(['origin'], ['id' => $parent_item["parent"]]); $origin = $toplevel["origin"]; } else { $origin = $parent_item["origin"]; @@ -2196,7 +2196,7 @@ class Diaspora return false; } - $item = Item::selectFirst(0, ['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; @@ -2217,7 +2217,7 @@ class Diaspora } // Send all existing comments and likes to the requesting server - $comments = Item::select(0, ['id', 'verb', 'self'], ['parent' => $item['id']]); + $comments = Item::select(['id', 'verb', 'self'], ['parent' => $item['id']]); while ($comment = dba::fetch($comments)) { if ($comment['id'] == $comment['parent']) { continue; @@ -2579,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 = Item::selectFirst(0, $fields, $condition); + $item = Item::selectFirst($fields, $condition); if (DBM::is_result($item)) { logger("reshared message ".$guid." already exists on system."); @@ -2623,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 = Item::selectFirst(0, $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 @@ -2765,7 +2765,7 @@ class Diaspora } else { $condition = ["`guid` = ? AND `uid` = ? AND NOT `file` LIKE '%%[%%' AND NOT `deleted`", $target_guid, $importer['uid']]; } - $r = Item::select($importer['uid'], $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; @@ -2773,7 +2773,7 @@ class Diaspora while ($item = dba::fetch($r)) { // Fetch the parent item - $parent = Item::selectFirst(0, ['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"])) { @@ -3409,7 +3409,7 @@ class Diaspora if (($guid != "") && $complete) { $condition = ['guid' => $guid, 'network' => [NETWORK_DFRN, NETWORK_DIASPORA]]; - $item = Item::selectFirst(0, ['contact-id'], $condition); + $item = Item::selectFirst(['contact-id'], $condition); if (DBM::is_result($item)) { $ret= []; $ret["root_handle"] = self::handleFromContact($item["contact-id"]); @@ -3676,7 +3676,7 @@ class Diaspora */ private static function constructLike($item, $owner) { - $parent = Item::selectFirst(0, ['guid', 'uri', 'parent-uri'], ['uri' => $item["thr-parent"]]); + $parent = Item::selectFirst(['guid', 'uri', 'parent-uri'], ['uri' => $item["thr-parent"]]); if (!DBM::is_result($parent)) { return false; } @@ -3707,7 +3707,7 @@ class Diaspora */ private static function constructAttend($item, $owner) { - $parent = Item::selectFirst(0, ['guid', 'uri', 'parent-uri'], ['uri' => $item["thr-parent"]]); + $parent = Item::selectFirst(['guid', 'uri', 'parent-uri'], ['uri' => $item["thr-parent"]]); if (!DBM::is_result($parent)) { return false; } @@ -3751,7 +3751,7 @@ class Diaspora return $result; } - $parent = Item::selectFirst(0, ['guid'], ['id' => $item["parent"], 'parent' => $item["parent"]]); + $parent = Item::selectFirst(['guid'], ['id' => $item["parent"], 'parent' => $item["parent"]]); if (!DBM::is_result($parent)) { return false; } @@ -4224,7 +4224,7 @@ class Diaspora $contact["uprvkey"] = $r[0]['prvkey']; - $item = Item::selectFirst(0, [], ['id' => $post_id]); + $item = Item::selectFirst([], ['id' => $post_id]); if (!DBM::is_result($item)) { return false; }