Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Use existing WpOrgApi helper class
  • Loading branch information
swissspidy committed Feb 9, 2025
commit 002188be2692e1dbbda4b1dc7999bd4c7c205dbb
28 changes: 9 additions & 19 deletions src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -1013,31 +1013,19 @@ private static function find_var( $var_name, $code ) {
* @return string|array String message on failure. An array of checksums on success.
*/
private static function get_core_checksums( $version, $locale, $insecure ) {
$query = http_build_query( compact( 'version', 'locale' ), '', '&' );
$url = "https://api.wordpress.org/core/checksums/1.0/?{$query}";
$wp_org_api = new WpOrgApi( [ 'insecure' => $insecure ] );

$headers = [ 'Accept' => 'application/json' ];
$options = [
'timeout' => 30,
'insecure' => $insecure,
];

$response = Utils\http_request( 'GET', $url, null, $headers, $options );

if ( ! $response->success || 200 !== (int) $response->status_code ) {
return "Checksum request '{$url}' failed (HTTP {$response->status_code}).";
try {
$checksums = $wp_org_api->get_core_checksums( $version, $locale );
} catch ( Exception $exception ) {
return $exception->getMessage();
}

$body = trim( $response->body );
$body = json_decode( $body, true );

if ( ! is_array( $body )
|| ! isset( $body['checksums'] )
|| ! is_array( $body['checksums'] ) ) {
if ( false === $checksums ) {
return "Checksums not available for WordPress {$version}/{$locale}.";
}

return $body['checksums'];
return $checksums;
}

/**
Expand Down Expand Up @@ -1437,9 +1425,11 @@ private function cleanup_extra_files( $version_from, $version_to, $locale, $inse
WP_CLI::warning( "{$old_checksums} Please cleanup files manually." );
return;
}

$new_checksums = self::get_core_checksums( $version_to, $locale ?: 'en_US', $insecure );
if ( ! is_array( $new_checksums ) ) {
WP_CLI::warning( "{$new_checksums} Please cleanup files manually." );

return;
}

Expand Down