]> git.mxchange.org Git - friendica.git/blobdiff - include/api.php
Fix the test data
[friendica.git] / include / api.php
index 00e51d249b9db8f236e5818c0431ca86992e4b56..4aa4b21e29199e4a0c339cb884d94b251f2062fd 100644 (file)
@@ -1644,19 +1644,19 @@ function api_statuses_home_timeline($type)
 
        $start = max(0, ($page - 1) * $count);
 
-       $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `item`.`id` > ?",
+       $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ?",
                api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
 
        if ($max_id > 0) {
-               $condition[0] .= " AND `item`.`id` <= ?";
+               $condition[0] .= " AND `id` <= ?";
                $condition[] = $max_id;
        }
        if ($exclude_replies) {
-               $condition[0] .= ' AND `item`.`gravity` = ?';
+               $condition[0] .= ' AND `gravity` = ?';
                $condition[] = GRAVITY_PARENT;
        }
        if ($conversation_id > 0) {
-               $condition[0] .= " AND `item`.`parent` = ?";
+               $condition[0] .= " AND `parent` = ?";
                $condition[] = $conversation_id;
        }
 
@@ -1746,15 +1746,15 @@ function api_statuses_public_timeline($type)
 
                $r = Item::toArray($statuses);
        } else {
-               $condition = ["`gravity` IN (?, ?) AND `id` > ? AND `private` = ? AND `wall` AND `item`.`origin` AND NOT `author`.`hidden`",
+               $condition = ["`gravity` IN (?, ?) AND `id` > ? AND `private` = ? AND `wall` AND `origin` AND NOT `author-hidden`",
                        GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, Item::PUBLIC];
 
                if ($max_id > 0) {
-                       $condition[0] .= " AND `item`.`id` <= ?";
+                       $condition[0] .= " AND `id` <= ?";
                        $condition[] = $max_id;
                }
                if ($conversation_id > 0) {
-                       $condition[0] .= " AND `item`.`parent` = ?";
+                       $condition[0] .= " AND `parent` = ?";
                        $condition[] = $conversation_id;
                }
 
@@ -1881,14 +1881,14 @@ function api_statuses_show($type)
        $conversation = !empty($_REQUEST['conversation']);
 
        // try to fetch the item for the local user - or the public item, if there is no local one
-       $uri_item = Post::selectFirst(['uri'], ['id' => $id]);
+       $uri_item = Post::selectFirst(['uri-id'], ['id' => $id]);
        if (!DBA::isResult($uri_item)) {
-               throw new BadRequestException("There is no status with this id.");
+               throw new BadRequestException(sprintf("There is no status with the id %d", $id));
        }
 
-       $item = Post::selectFirst(['id'], ['uri' => $uri_item['uri'], 'uid' => [0, api_user()]], ['order' => ['uid' => true]]);
+       $item = Post::selectFirst(['id'], ['uri-id' => $uri_item['uri-id'], 'uid' => [0, api_user()]], ['order' => ['uid' => true]]);
        if (!DBA::isResult($item)) {
-               throw new BadRequestException("There is no status with this id.");
+               throw new BadRequestException(sprintf("There is no status with the uri-id %d for the given user.", $uri_item['uri-id']));
        }
 
        $id = $item['id'];
@@ -1905,7 +1905,7 @@ function api_statuses_show($type)
 
        /// @TODO How about copying this to above methods which don't check $r ?
        if (!DBA::isResult($statuses)) {
-               throw new BadRequestException("There is no status with this id.");
+               throw new BadRequestException(sprintf("There is no status or conversation with the id %d.", $id));
        }
 
        $ret = api_format_items(Post::toArray($statuses), $user_info, false, $type);
@@ -1964,23 +1964,23 @@ function api_conversation_show($type)
        Logger::info(API_LOG_PREFIX . '{subaction}', ['module' => 'api', 'action' => 'conversation', 'subaction' => 'show', 'id' => $id]);
 
        // try to fetch the item for the local user - or the public item, if there is no local one
-       $item = Post::selectFirst(['parent-uri'], ['id' => $id]);
+       $item = Post::selectFirst(['parent-uri-id'], ['id' => $id]);
        if (!DBA::isResult($item)) {
                throw new BadRequestException("There is no status with this id.");
        }
 
-       $parent = Post::selectFirst(['id'], ['uri' => $item['parent-uri'], 'uid' => [0, api_user()]], ['order' => ['uid' => true]]);
+       $parent = Post::selectFirst(['id'], ['uri-id' => $item['parent-uri-id'], 'uid' => [0, api_user()]], ['order' => ['uid' => true]]);
        if (!DBA::isResult($parent)) {
                throw new BadRequestException("There is no status with this id.");
        }
 
        $id = $parent['id'];
 
-       $condition = ["`parent` = ? AND `uid` IN (0, ?) AND `gravity` IN (?, ?) AND `item`.`id` > ?",
+       $condition = ["`parent` = ? AND `uid` IN (0, ?) AND `gravity` IN (?, ?) AND `id` > ?",
                $id, api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
 
        if ($max_id > 0) {
-               $condition[0] .= " AND `item`.`id` <= ?";
+               $condition[0] .= " AND `id` <= ?";
                $condition[] = $max_id;
        }
 
@@ -2041,9 +2041,9 @@ function api_statuses_repeat($type)
        Logger::log('API: api_statuses_repeat: '.$id);
 
        $fields = ['uri-id', 'network', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
-       $item = Item::selectFirst($fields, ['id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED]]);
-
-       if (DBA::isResult($item) && $item['body'] != "") {
+       $item = Post::selectFirst($fields, ['id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED]]);
+       if (DBA::isResult($item) && !empty($item['body'])) {
                if (in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::TWITTER])) {
                        if (!Item::performActivity($id, 'announce', local_user())) {
                                throw new InternalServerErrorException();
@@ -2171,11 +2171,11 @@ function api_statuses_mentions($type)
 
        $start = max(0, ($page - 1) * $count);
 
-       $query = "SELECT `item`.`id` FROM `user-item`
-               INNER JOIN `item` ON `item`.`id` = `user-item`.`iid` AND `item`.`gravity` IN (?, ?)
-               WHERE (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`) AND
-                       `user-item`.`uid` = ? AND `user-item`.`notification-type` & ? != 0
-                       AND `user-item`.`iid` > ?";
+       $query = "`gravity` IN (?, ?) AND `id` IN (SELECT `iid` FROM `user-item`                
+               WHERE (`hidden` IS NULL OR NOT `hidden`) AND
+                       `uid` = ? AND `notification-type` & ? != 0
+                       AND `iid` > ?";
+
        $condition = [GRAVITY_PARENT, GRAVITY_COMMENT, api_user(),
                UserItem::NOTIF_EXPLICIT_TAGGED | UserItem::NOTIF_IMPLICIT_TAGGED |
                UserItem::NOTIF_THREAD_COMMENT | UserItem::NOTIF_DIRECT_COMMENT |
@@ -2183,23 +2183,16 @@ function api_statuses_mentions($type)
                $since_id];
 
        if ($max_id > 0) {
-               $query .= " AND `item`.`id` <= ?";
+               $query .= " AND `iid` <= ?";
                $condition[] = $max_id;
        }
 
-       $query .= " ORDER BY `user-item`.`iid` DESC LIMIT ?, ?";
-       $condition[] = $start;
-       $condition[] = $count;
+       $query .= ")";
 
-       $useritems = DBA::p($query, $condition);
-       $itemids = [];
-       while ($useritem = DBA::fetch($useritems)) {
-               $itemids[] = $useritem['id'];
-       }
-       DBA::close($useritems);
+       array_unshift($condition, $query);
 
        $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
-       $statuses = Post::selectForUser(api_user(), [], ['id' => $itemids], $params);
+       $statuses = Post::selectForUser(api_user(), [], $condition, $params);
 
        $ret = api_format_items(Post::toArray($statuses), $user_info, false, $type);
 
@@ -2253,25 +2246,25 @@ function api_statuses_user_timeline($type)
 
        $start = max(0, ($page - 1) * $count);
 
-       $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `item`.`id` > ? AND `item`.`contact-id` = ?",
+       $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ? AND `contact-id` = ?",
                api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $user_info['cid']];
 
        if ($user_info['self'] == 1) {
-               $condition[0] .= ' AND `item`.`wall` ';
+               $condition[0] .= ' AND `wall` ';
        }
 
        if ($exclude_replies) {
-               $condition[0] .= ' AND `item`.`gravity` = ?';
+               $condition[0] .= ' AND `gravity` = ?';
                $condition[] = GRAVITY_PARENT;
        }
 
        if ($conversation_id > 0) {
-               $condition[0] .= " AND `item`.`parent` = ?";
+               $condition[0] .= " AND `parent` = ?";
                $condition[] = $conversation_id;
        }
 
        if ($max_id > 0) {
-               $condition[0] .= " AND `item`.`id` <= ?";
+               $condition[0] .= " AND `id` <= ?";
                $condition[] = $max_id;
        }
 
@@ -2426,7 +2419,7 @@ function api_favorites($type)
                $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
 
                if ($max_id > 0) {
-                       $condition[0] .= " AND `item`.`id` <= ?";
+                       $condition[0] .= " AND `id` <= ?";
                        $condition[] = $max_id;
                }
 
@@ -2875,7 +2868,7 @@ function api_format_items_activities($item, $type = "json")
        $condition = ['uid' => $item['uid'], 'thr-parent' => $item['uri'], 'gravity' => GRAVITY_ACTIVITY];
        $ret = Post::selectForUser($item['uid'], ['author-id', 'verb'], $condition);
 
-       while ($parent_item = Item::fetch($ret)) {
+       while ($parent_item = Post::fetch($ret)) {
                // not used as result should be structured like other user data
                //builtin_activity_puller($i, $activities);
 
@@ -3304,19 +3297,19 @@ function api_lists_statuses($type)
 
        $start = max(0, ($page - 1) * $count);
 
-       $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ? AND `group_member`.`gid` = ?",
+       $condition = ["`uid` = ? AND `gravity` IN (?, ?) AND `id` > ? AND `group-id` = ?",
                api_user(), GRAVITY_PARENT, GRAVITY_COMMENT, $since_id, $_REQUEST['list_id']];
 
        if ($max_id > 0) {
-               $condition[0] .= " AND `item`.`id` <= ?";
+               $condition[0] .= " AND `id` <= ?";
                $condition[] = $max_id;
        }
        if ($exclude_replies > 0) {
-               $condition[0] .= ' AND `item`.`gravity` = ?';
+               $condition[0] .= ' AND `gravity` = ?';
                $condition[] = GRAVITY_PARENT;
        }
        if ($conversation_id > 0) {
-               $condition[0] .= " AND `item`.`parent` = ?";
+               $condition[0] .= " AND `parent` = ?";
                $condition[] = $conversation_id;
        }
 
@@ -6014,7 +6007,7 @@ function bindComments(&$data)
        }
 
        $idStr = DBA::escape(implode(', ', $ids));
-       $sql = "SELECT `parent`, COUNT(*) as comments FROM `item` WHERE `parent` IN ($idStr) AND `deleted` = ? AND `gravity`= ? GROUP BY `parent`";
+       $sql = "SELECT `parent`, COUNT(*) as comments FROM `post-view` WHERE `parent` IN ($idStr) AND `deleted` = ? AND `gravity`= ? GROUP BY `parent`";
        $items = DBA::p($sql, 0, GRAVITY_COMMENT);
        $itemsData = DBA::toArray($items);