Skip to content

Commit

Permalink
Merge pull request #41 from wp-cli/30-download_url
Browse files Browse the repository at this point in the history
Use `download_url()` in language pack upgrader
  • Loading branch information
schlessera authored Aug 3, 2018
2 parents 710c821 + 7198de2 commit 67cba55
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/WP_CLI/LanguagePackUpgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,14 @@ public function download_package( $package ) {
return $temp;
}

/*
* Download to a temporary file because piping from cURL to tar is flaky
* on MinGW (and probably in other environments too).
*/
$headers = array( 'Accept' => 'application/json' );
$options = array(
'timeout' => 600, // 10 minutes ought to be enough for everybody.
'filename' => $temp
);

$this->skin->feedback( 'downloading_package', $package );

/** @var \Requests_Response|null $req */
$req = Utils\http_request( 'GET', $package, null, $headers, $options );
if ( null !== $req && $req->status_code !== 200 ) {
return new \WP_Error( 'download_failed', $this->strings['download_failed'] );
$temp = download_url( $package, 600 ); // 10 minutes ought to be enough for everybody.

if ( is_wp_error( $temp ) ) {
return $temp;
}

$cache->import( $cache_key, $temp );

return $temp;
Expand Down

0 comments on commit 67cba55

Please sign in to comment.