Skip to content

Commit f114e2f

Browse files
authored
Merge pull request #283 from wp-cli/try/wporg-api
Use existing `WpOrgApi` helper class
2 parents e804145 + 002188b commit f114e2f

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

src/Core_Command.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,31 +1013,19 @@ private static function find_var( $var_name, $code ) {
10131013
* @return string|array String message on failure. An array of checksums on success.
10141014
*/
10151015
private static function get_core_checksums( $version, $locale, $insecure ) {
1016-
$query = http_build_query( compact( 'version', 'locale' ), '', '&' );
1017-
$url = "https://api.wordpress.org/core/checksums/1.0/?{$query}";
1016+
$wp_org_api = new WpOrgApi( [ 'insecure' => $insecure ] );
10181017

1019-
$headers = [ 'Accept' => 'application/json' ];
1020-
$options = [
1021-
'timeout' => 30,
1022-
'insecure' => $insecure,
1023-
];
1024-
1025-
$response = Utils\http_request( 'GET', $url, null, $headers, $options );
1026-
1027-
if ( ! $response->success || 200 !== (int) $response->status_code ) {
1028-
return "Checksum request '{$url}' failed (HTTP {$response->status_code}).";
1018+
try {
1019+
$checksums = $wp_org_api->get_core_checksums( $version, $locale );
1020+
} catch ( Exception $exception ) {
1021+
return $exception->getMessage();
10291022
}
10301023

1031-
$body = trim( $response->body );
1032-
$body = json_decode( $body, true );
1033-
1034-
if ( ! is_array( $body )
1035-
|| ! isset( $body['checksums'] )
1036-
|| ! is_array( $body['checksums'] ) ) {
1024+
if ( false === $checksums ) {
10371025
return "Checksums not available for WordPress {$version}/{$locale}.";
10381026
}
10391027

1040-
return $body['checksums'];
1028+
return $checksums;
10411029
}
10421030

10431031
/**
@@ -1437,9 +1425,11 @@ private function cleanup_extra_files( $version_from, $version_to, $locale, $inse
14371425
WP_CLI::warning( "{$old_checksums} Please cleanup files manually." );
14381426
return;
14391427
}
1428+
14401429
$new_checksums = self::get_core_checksums( $version_to, $locale ?: 'en_US', $insecure );
14411430
if ( ! is_array( $new_checksums ) ) {
14421431
WP_CLI::warning( "{$new_checksums} Please cleanup files manually." );
1432+
14431433
return;
14441434
}
14451435

0 commit comments

Comments
 (0)