From b5df0ded63e3679fdbafd4f19cfccd1cff1ec2d3 Mon Sep 17 00:00:00 2001 From: Jannik Zschiesche Date: Thu, 5 Mar 2026 16:44:10 +0100 Subject: [PATCH] Fix invalid pagination handling `ManagementApi::sendPaginatedRequest()` --- CHANGELOG.md | 6 ++++++ src/Api/ManagementApi.php | 23 ++++++++++++++++++----- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdfd8ae..95f9c73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +5.1.4 +===== + +* (bug) Fix invalid pagination handling `ManagementApi::sendPaginatedRequest()`. + + 5.1.3 ===== diff --git a/src/Api/ManagementApi.php b/src/Api/ManagementApi.php index 0fc7123..e2edcc2 100644 --- a/src/Api/ManagementApi.php +++ b/src/Api/ManagementApi.php @@ -349,17 +349,27 @@ public function fetchDatasourceEntries ( /** * @return AssetData[] */ - public function fetchAllAssets () : array + public function fetchAllAssets ( + ?TorrStyle $io = null, + ) : array { $assets = []; $page = 1; + $maxPage = null; do { + $io?->writeln(\sprintf( + "• Fetching all assets metadata page %s / %s for space %s", + $page, + $maxPage ?? "(unknown)", + $this->config->spaceId, + )); + /** @var PaginatedApiResult $result */ $result = $this->sendPaginatedRequest( "assets", $page, - 1000, + 25, // seems to be the max allowed value "assets", ); @@ -463,11 +473,14 @@ private function sendPaginatedRequest ( } $totalValues = (int) $headers["total"][0]; + // use value from headers, if we passed a perPage-value too large. Storyblok will automatically reduce it + // to the max allowed value + $perPage = (int) $headers["per-page"][0]; return new PaginatedApiResult( - (int) $headers["per-page"][0], - (int) ceil($totalValues / $perPage), - "" !== $response->getContent() + perPage: $perPage, + totalPages: (int) ceil($totalValues / $perPage), + entries: "" !== $response->getContent() ? $response->toArray()[$resultKey] : [], );