From: Michael Date: Sat, 8 Jul 2023 07:55:18 +0000 (+0000) Subject: Fix id/uri-id chaos in API calls X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ef309cbcd37a587fd08ead170bcc2d12159706b8;p=friendica.git Fix id/uri-id chaos in API calls --- diff --git a/src/Module/Api/Mastodon/Statuses/Bookmark.php b/src/Module/Api/Mastodon/Statuses/Bookmark.php index 255b459c33..59c61f9913 100644 --- a/src/Module/Api/Mastodon/Statuses/Bookmark.php +++ b/src/Module/Api/Mastodon/Statuses/Bookmark.php @@ -42,7 +42,7 @@ class Bookmark extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - $item = Post::selectOriginal(['uid', 'id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]); + $item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]); if (!DBA::isResult($item)) { DI::mstdnError()->RecordNotFound(); } @@ -52,7 +52,7 @@ class Bookmark extends BaseApi } if ($item['uid'] == 0) { - $stored = Item::storeForUserByUriId($item['id'], $uid, ['post-reason' => Item::PR_ACTIVITY]); + $stored = Item::storeForUserByUriId($item['uri-id'], $uid, ['post-reason' => Item::PR_ACTIVITY]); if (!empty($stored)) { $item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]); if (!DBA::isResult($item)) { diff --git a/src/Module/Api/Mastodon/Statuses/Card.php b/src/Module/Api/Mastodon/Statuses/Card.php index 6d29ee879e..3e973d9bba 100644 --- a/src/Module/Api/Mastodon/Statuses/Card.php +++ b/src/Module/Api/Mastodon/Statuses/Card.php @@ -43,11 +43,11 @@ class Card extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - if (!$post = Post::selectOriginal(['id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) { + if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) { throw new HTTPException\NotFoundException('Item with URI ID ' . $this->parameters['id'] . ' not found' . ($uid ? ' for user ' . $uid : '.')); } - $card = DI::mstdnCard()->createFromUriId($post['id']); + $card = DI::mstdnCard()->createFromUriId($post['uri-id']); System::jsonExit($card->toArray()); } diff --git a/src/Module/Api/Mastodon/Statuses/FavouritedBy.php b/src/Module/Api/Mastodon/Statuses/FavouritedBy.php index 326e48d823..fcfb97d926 100644 --- a/src/Module/Api/Mastodon/Statuses/FavouritedBy.php +++ b/src/Module/Api/Mastodon/Statuses/FavouritedBy.php @@ -44,11 +44,11 @@ class FavouritedBy extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - if (!$post = Post::selectOriginal(['id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) { + if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) { DI::mstdnError()->RecordNotFound(); } - $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::LIKE, 'deleted' => false]); + $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['uri-id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::LIKE, 'deleted' => false]); $accounts = []; diff --git a/src/Module/Api/Mastodon/Statuses/Mute.php b/src/Module/Api/Mastodon/Statuses/Mute.php index 0c1068490c..1f00d39d0e 100644 --- a/src/Module/Api/Mastodon/Statuses/Mute.php +++ b/src/Module/Api/Mastodon/Statuses/Mute.php @@ -42,7 +42,7 @@ class Mute extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - $item = Post::selectOriginalForUser($uid, ['id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); + $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { DI::mstdnError()->RecordNotFound(); } @@ -51,7 +51,7 @@ class Mute extends BaseApi DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be muted')); } - Post\ThreadUser::setIgnored($item['id'], $uid, true); + Post\ThreadUser::setIgnored($item['uri-id'], $uid, true); System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); } diff --git a/src/Module/Api/Mastodon/Statuses/Pin.php b/src/Module/Api/Mastodon/Statuses/Pin.php index d092b4255f..33a0116eb1 100644 --- a/src/Module/Api/Mastodon/Statuses/Pin.php +++ b/src/Module/Api/Mastodon/Statuses/Pin.php @@ -41,12 +41,12 @@ class Pin extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - $item = Post::selectOriginalForUser($uid, ['id', 'gravity', 'author-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); + $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity', 'author-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { DI::mstdnError()->RecordNotFound(); } - Post\Collection::add($item['id'], Post\Collection::FEATURED, $item['author-id'], $uid); + Post\Collection::add($item['uri-id'], Post\Collection::FEATURED, $item['author-id'], $uid); System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); } diff --git a/src/Module/Api/Mastodon/Statuses/RebloggedBy.php b/src/Module/Api/Mastodon/Statuses/RebloggedBy.php index b225d17439..a12975a8be 100644 --- a/src/Module/Api/Mastodon/Statuses/RebloggedBy.php +++ b/src/Module/Api/Mastodon/Statuses/RebloggedBy.php @@ -44,11 +44,11 @@ class RebloggedBy extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - if (!$post = Post::selectOriginal(['id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) { + if (!$post = Post::selectOriginal(['uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [0, $uid]])) { DI::mstdnError()->RecordNotFound(); } - $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE]); + $activities = Post::selectPosts(['author-id'], ['thr-parent-id' => $post['uri-id'], 'gravity' => Item::GRAVITY_ACTIVITY, 'verb' => Activity::ANNOUNCE]); $accounts = []; diff --git a/src/Module/Api/Mastodon/Statuses/Unbookmark.php b/src/Module/Api/Mastodon/Statuses/Unbookmark.php index 4f6db11fd3..f95fd9445d 100644 --- a/src/Module/Api/Mastodon/Statuses/Unbookmark.php +++ b/src/Module/Api/Mastodon/Statuses/Unbookmark.php @@ -42,7 +42,7 @@ class Unbookmark extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - $item = Post::selectOriginal(['uid', 'id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]); + $item = Post::selectOriginal(['uid', 'id', 'uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]], ['order' => ['uid' => true]]); if (!DBA::isResult($item)) { DI::mstdnError()->RecordNotFound(); } @@ -52,7 +52,7 @@ class Unbookmark extends BaseApi } if ($item['uid'] == 0) { - $stored = Item::storeForUserByUriId($item['id'], $uid, ['post-reason' => Item::PR_ACTIVITY]); + $stored = Item::storeForUserByUriId($item['uri-id'], $uid, ['post-reason' => Item::PR_ACTIVITY]); if (!empty($stored)) { $item = Post::selectFirst(['id', 'gravity'], ['id' => $stored]); if (!DBA::isResult($item)) { diff --git a/src/Module/Api/Mastodon/Statuses/Unmute.php b/src/Module/Api/Mastodon/Statuses/Unmute.php index b7a24beed2..2285422cac 100644 --- a/src/Module/Api/Mastodon/Statuses/Unmute.php +++ b/src/Module/Api/Mastodon/Statuses/Unmute.php @@ -42,7 +42,7 @@ class Unmute extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - $item = Post::selectOriginalForUser($uid, ['id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); + $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { DI::mstdnError()->RecordNotFound(); } @@ -51,7 +51,7 @@ class Unmute extends BaseApi DI::mstdnError()->UnprocessableEntity(DI::l10n()->t('Only starting posts can be unmuted')); } - Post\ThreadUser::setIgnored($item['id'], $uid, false); + Post\ThreadUser::setIgnored($item['uri-id'], $uid, false); System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); } diff --git a/src/Module/Api/Mastodon/Statuses/Unpin.php b/src/Module/Api/Mastodon/Statuses/Unpin.php index 523ce4d554..c80582d15a 100644 --- a/src/Module/Api/Mastodon/Statuses/Unpin.php +++ b/src/Module/Api/Mastodon/Statuses/Unpin.php @@ -41,12 +41,12 @@ class Unpin extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - $item = Post::selectOriginalForUser($uid, ['id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); + $item = Post::selectOriginalForUser($uid, ['uri-id', 'gravity'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { DI::mstdnError()->RecordNotFound(); } - Post\Collection::remove($item['id'], Post\Collection::FEATURED, $uid); + Post\Collection::remove($item['uri-id'], Post\Collection::FEATURED, $uid); System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); }