Skip to content

Commit ff68b4e

Browse files
committed
Account for response pagination.
1 parent a5f21d0 commit ff68b4e

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.0.3] - 2025-05-12
11+
12+
### Fixed
13+
14+
- Zones are now collected across paginated responses.
15+
1016
## [0.0.2] - 2025-04-04
1117

1218
### Fixed

items.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
$lastCached = $data->saved ?? null;
2323
$now = time();
2424
$shouldRefreshCache = ! $lastCached || ($now - $lastCached) > $cacheSeconds;
25+
$collectedZones = [];
2526

2627
if ($shouldRefreshCache) {
2728
$workflow->logger()->info('Refreshing data...');
@@ -38,12 +39,10 @@
3839
}
3940

4041
$adapter = new Cloudflare\API\Adapter\Guzzle($authorization);
41-
$zones = (new Cloudflare\API\Endpoints\Zones($adapter))->listZones()->result ?? [];
42-
43-
$workflow->logger()->log((new Cloudflare\API\Endpoints\Zones($adapter))->listZones());
42+
collectZoneList($adapter);
4443

4544
$data = (object)[
46-
'zones' => stripUnnecessaryZoneProperties($zones),
45+
'zones' => stripUnnecessaryZoneProperties($collectedZones),
4746
'saved' => $now,
4847
];
4948

@@ -66,6 +65,24 @@
6665

6766
$workflow->output();
6867

68+
/**
69+
* Fetches zone info across pagination and populates `$collectedZones`.
70+
* @param $adapter
71+
* @param int $page
72+
* @return void
73+
*/
74+
function collectZoneList($adapter, int $page = 1): void
75+
{
76+
global $collectedZones;
77+
$zonesResponse = (new Cloudflare\API\Endpoints\Zones($adapter))->listZones(page: $page);
78+
$zonesResponseInfo = $zonesResponse->result_info;
79+
$collectedZones = array_merge($collectedZones, $zonesResponse->result ?? []);
80+
81+
if ($zonesResponseInfo->page < $zonesResponseInfo->total_pages) {
82+
collectZoneList($adapter, $page+1);
83+
}
84+
}
85+
6986
/**
7087
* Removes properties from each zone that we don’t need to save.
7188
* @param $zones

0 commit comments

Comments
 (0)