Repository navigation
Expand file tree
/
Copy pathplugin-status.php
More file actions
52 lines (42 loc) · 1.75 KB
/
Copy pathplugin-status.php
File metadata and controls
52 lines (42 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
declare(strict_types=1);
/**
* Prints status, latest version and closure of plugins, chunk by chunk.
*
* Usage: php examples/plugin-status.php [slug ...]
*/
use GoSuccess\WordpressOrg\Directory\LookupStatus;
use GoSuccess\WordpressOrg\Exception\RateLimitException;
use GoSuccess\WordpressOrg\Exception\WordpressOrgException;
use GoSuccess\WordpressOrg\WordpressOrg;
$client = require __DIR__ . '/bootstrap.php';
assert($client instanceof WordpressOrg);
$slugs = array_slice($argv ?? [], 1);
if ($slugs === []) {
$slugs = ['akismet', 'display-widgets', 'no-such-plugin-zzzq'];
}
try {
// Each chunk (up to batchSize slugs) is one request; handle it before the next starts.
foreach ($client->plugins->lookupChunks(array_values($slugs)) as $results) {
foreach ($results as $slug => $lookup) {
$detail = match ($lookup->status) {
LookupStatus::Found => 'version ' . ($lookup->version() ?? '?'),
LookupStatus::Closed => sprintf(
'closed %s (%s)',
$lookup->closure?->date?->format('Y-m-d') ?? '?',
$lookup->closure->reason ?? '?',
),
LookupStatus::NotFound => $lookup->error ?? 'not found',
LookupStatus::Unknown => 'no usable answer',
};
printf("%-24s %-9s %s\n", $slug, $lookup->status->name, $detail);
}
}
} catch (RateLimitException $e) {
fwrite(STDERR, sprintf("Rate limited; retry after %s seconds.\n", $e->retryAfter ?? 'an unknown number of'));
exit(1);
} catch (WordpressOrgException $e) {
// A failing chunk throws; the slugs of that chunk are not reported as unknown.
fwrite(STDERR, 'Lookup failed: ' . $e->getMessage() . "\n");
exit(1);
}