From 2e57b4eed6d1f946e051690bd45029fc99f08348 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 21 Aug 2014 10:55:40 -0700 Subject: [PATCH 1/9] Abstract `_request()` to a common utility so we can use inside a filter --- php/commands/core.php | 43 ++++--------------------------------------- php/utils.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 39 deletions(-) diff --git a/php/commands/core.php b/php/commands/core.php index c9c084a4ee..8a6fa747c8 100644 --- a/php/commands/core.php +++ b/php/commands/core.php @@ -75,7 +75,7 @@ public function download( $args, $assoc_args ) { 'filename' => $temp ); - self::_request( 'GET', $download_url, $headers, $options ); + Utils\get_request( $download_url, $headers, $options ); self::_extract( $temp, ABSPATH ); $cache->import( $cache_key, $temp ); unlink($temp); @@ -134,44 +134,9 @@ private static function _rmdir( $dir ) { rmdir( $dir ); } - private static function _request( $method, $url, $headers = array(), $options = array() ) { - $pem_copied = false; - - // cURL can't read Phar archives - if ( 0 === strpos( WP_CLI_ROOT, 'phar://' ) ) { - $options['verify'] = sys_get_temp_dir() . '/wp-cli-cacert.pem'; - - copy( - WP_CLI_ROOT . '/vendor/rmccue/requests/library/Requests/Transport/cacert.pem', - $options['verify'] - ); - $pem_copied = true; - } - - try { - $request = Requests::get( $url, $headers, $options ); - if ( $pem_copied ) { - unlink( $options['verify'] ); - } - return $request; - } catch( Requests_Exception $ex ) { - // Handle SSL certificate issues gracefully - WP_CLI::warning( $ex->getMessage() ); - if ( $pem_copied ) { - unlink( $options['verify'] ); - } - $options['verify'] = false; - try { - return Requests::get( $url, $headers, $options ); - } catch( Requests_Exception $ex ) { - WP_CLI::error( $ex->getMessage() ); - } - } - } - private static function _read( $url ) { $headers = array('Accept' => 'application/json'); - return self::_request( 'GET', $url, $headers )->body; + return Utils\get_request( $url, $headers )->body; } private function get_download_offer( $locale ) { @@ -694,11 +659,11 @@ private static function get_core_checksums( $version, $locale ) { $headers = array( 'Accept' => 'application/json' ); - $response = self::_request( 'GET', $url, $headers, $options ); + $response = Utils\get_request( $url, $headers, $options ); if ( $ssl && ! $response->success ) { WP_CLI::warning( 'wp-cli could not establish a secure connection to WordPress.org. Please contact your server administrator.' ); - $response = self::_request( 'GET', $http_url, $headers, $options ); + $response = Utils\get_request( $http_url, $headers, $options ); } if ( ! $response->success || 200 != $response->status_code ) diff --git a/php/utils.php b/php/utils.php index e033be5bb1..60362ad7b4 100644 --- a/php/utils.php +++ b/php/utils.php @@ -401,3 +401,45 @@ function replace_path_consts( $source, $path ) { return str_replace( $old, $new, $source ); } + +/** + * Download a remote URL + * + * @param string $url + * @param array $headers + * @param array $options + */ +function get_request( $url, $headers = array(), $options = array() ) { + $pem_copied = false; + + // cURL can't read Phar archives + if ( 0 === strpos( WP_CLI_ROOT, 'phar://' ) ) { + $options['verify'] = sys_get_temp_dir() . '/wp-cli-cacert.pem'; + + copy( + WP_CLI_ROOT . '/vendor/rmccue/requests/library/Requests/Transport/cacert.pem', + $options['verify'] + ); + $pem_copied = true; + } + + try { + $request = \Requests::get( $url, $headers, $options ); + if ( $pem_copied ) { + unlink( $options['verify'] ); + } + return $request; + } catch( \Requests_Exception $ex ) { + // Handle SSL certificate issues gracefully + \WP_CLI::warning( $ex->getMessage() ); + if ( $pem_copied ) { + unlink( $options['verify'] ); + } + $options['verify'] = false; + try { + return \Requests::get( $url, $headers, $options ); + } catch( \Requests_Exception $ex ) { + \WP_CLI::error( $ex->getMessage() ); + } + } +} From 7e4d2f685608b33fa6210b0c3e20b8b082272635 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 21 Aug 2014 11:01:21 -0700 Subject: [PATCH 2/9] `wp core update` should use cached files too --- features/core.feature | 20 ++++++++++++++++++++ php/commands/core.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/features/core.feature b/features/core.feature index a8998aecd0..4191bdb6fc 100644 --- a/features/core.feature +++ b/features/core.feature @@ -299,6 +299,26 @@ Feature: Manage WordPress installation Error: WordPress install doesn't verify against checksums. """ + Scenario: Core update from cache + Given a WP install + And an empty cache + + When I run `wp core update --version=3.8.1 --force` + Then STDOUT should not contain: + """ + Using cached file + """ + + When I run `wp core update --version=3.9 --force` + Then STDOUT should not be empty + + When I run `wp core update --version=3.8.1 --force` + Then STDOUT should contain: + """ + Using cached file '{SUITE_CACHE_DIR}/core/en_US-3.8.1.tar.gz'... + """ + + Scenario: User defined in wp-cli.yml Given an empty directory And WP files diff --git a/php/commands/core.php b/php/commands/core.php index 8a6fa747c8..c8483cdb1b 100644 --- a/php/commands/core.php +++ b/php/commands/core.php @@ -819,7 +819,38 @@ function update( $args, $assoc_args ) { WP_CLI::log( "Starting update..." ); } + $defer_cached_file = function( $reply, $package, $upgrader ) use ( $update ) { + + if ( ! preg_match('!^(http|https|ftp)://!i', $package) && file_exists( $package ) ) //Local file or remote? + return $reply; //must be a local file.. + + $cache = WP_CLI::get_cache(); + $cache_key = "core/{$update->locale}-{$update->version}.tar.gz"; + $cache_file = $cache->has( $cache_key ); + + if ( $cache_file ) { + WP_CLI::log( "Using cached file '$cache_file'..." ); + return $cache_file; + } else { + // We need to use a temporary file because piping from cURL to tar is flaky + // on MinGW (and probably in other environments too). + $temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.tar.gz'; + + $headers = array('Accept' => 'application/json'); + $options = array( + 'timeout' => 600, // 10 minutes ought to be enough for everybody + 'filename' => $temp + ); + + Utils\get_request( $package, $headers, $options ); + $cache->import( $cache_key, $temp ); + unlink($temp); + return $cache->has( $cache_key ); + } + }; + add_filter( 'upgrader_pre_download', $defer_cached_file, 10, 3 ); $result = Utils\get_upgrader( $upgrader )->upgrade( $update ); + remove_filter( 'upgrader_pre_download', $defer_cached_file ); if ( is_wp_error($result) ) { $msg = WP_CLI::error_to_string( $result ); From 5fbcb26b8b1cca7aa29a1ac8b163b80aa9d96b2c Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 21 Aug 2014 11:43:11 -0700 Subject: [PATCH 3/9] Copy cache to a temp file, so upgrader can later delete it --- php/commands/core.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/php/commands/core.php b/php/commands/core.php index c8483cdb1b..cd411989bb 100644 --- a/php/commands/core.php +++ b/php/commands/core.php @@ -824,13 +824,16 @@ function update( $args, $assoc_args ) { if ( ! preg_match('!^(http|https|ftp)://!i', $package) && file_exists( $package ) ) //Local file or remote? return $reply; //must be a local file.. + $temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.tar.gz'; + $cache = WP_CLI::get_cache(); $cache_key = "core/{$update->locale}-{$update->version}.tar.gz"; $cache_file = $cache->has( $cache_key ); if ( $cache_file ) { WP_CLI::log( "Using cached file '$cache_file'..." ); - return $cache_file; + copy( $cache_file, $temp ); + return $temp; } else { // We need to use a temporary file because piping from cURL to tar is flaky // on MinGW (and probably in other environments too). @@ -844,8 +847,7 @@ function update( $args, $assoc_args ) { Utils\get_request( $package, $headers, $options ); $cache->import( $cache_key, $temp ); - unlink($temp); - return $cache->has( $cache_key ); + return $temp; } }; add_filter( 'upgrader_pre_download', $defer_cached_file, 10, 3 ); From 8359b62380c99bbc8aa9bd20a8178b45f070bf2e Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 21 Aug 2014 12:36:43 -0700 Subject: [PATCH 4/9] Subclass, because the filter we want to use isn't available until 3.7.1 --- php/WP_CLI/CoreUpgrader.php | 67 +++++++++++++++++++++++ php/WP_CLI/NonDestructiveCoreUpgrader.php | 2 +- php/commands/core.php | 37 +------------ 3 files changed, 71 insertions(+), 35 deletions(-) create mode 100644 php/WP_CLI/CoreUpgrader.php diff --git a/php/WP_CLI/CoreUpgrader.php b/php/WP_CLI/CoreUpgrader.php new file mode 100644 index 0000000000..37cc7f0d40 --- /dev/null +++ b/php/WP_CLI/CoreUpgrader.php @@ -0,0 +1,67 @@ +strings['no_package'] ); + + $this->skin->feedback( 'downloading_package', $package ); + + $temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.tar.gz'; + + $cache = WP_CLI::get_cache(); + $update = $GLOBALS['wp_cli_update_obj']; + $cache_key = "core/{$update->locale}-{$update->version}.tar.gz"; + $cache_file = $cache->has( $cache_key ); + + if ( $cache_file ) { + WP_CLI::log( "Using cached file '$cache_file'..." ); + copy( $cache_file, $temp ); + return $temp; + } else { + // We need to use a temporary file because piping from cURL to tar is flaky + // on MinGW (and probably in other environments too). + $temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.tar.gz'; + + $headers = array('Accept' => 'application/json'); + $options = array( + 'timeout' => 600, // 10 minutes ought to be enough for everybody + 'filename' => $temp + ); + + Utils\get_request( $package, $headers, $options ); + $cache->import( $cache_key, $temp ); + return $temp; + } + + } + +} + diff --git a/php/WP_CLI/NonDestructiveCoreUpgrader.php b/php/WP_CLI/NonDestructiveCoreUpgrader.php index 41ba059493..ebad21cbd2 100644 --- a/php/WP_CLI/NonDestructiveCoreUpgrader.php +++ b/php/WP_CLI/NonDestructiveCoreUpgrader.php @@ -7,7 +7,7 @@ * * @package wp-cli */ -class NonDestructiveCoreUpgrader extends \Core_Upgrader { +class NonDestructiveCoreUpgrader extends CoreUpgrader { function unpack_package($package, $delete_package = false) { return parent::unpack_package( $package, $delete_package ); } diff --git a/php/commands/core.php b/php/commands/core.php index cd411989bb..f95e396e9d 100644 --- a/php/commands/core.php +++ b/php/commands/core.php @@ -750,7 +750,7 @@ function update( $args, $assoc_args ) { global $wp_version; $update = $from_api = null; - $upgrader = 'Core_Upgrader'; + $upgrader = 'WP_CLI\\CoreUpgrader'; if ( ! empty( $args[0] ) ) { @@ -819,40 +819,9 @@ function update( $args, $assoc_args ) { WP_CLI::log( "Starting update..." ); } - $defer_cached_file = function( $reply, $package, $upgrader ) use ( $update ) { - - if ( ! preg_match('!^(http|https|ftp)://!i', $package) && file_exists( $package ) ) //Local file or remote? - return $reply; //must be a local file.. - - $temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.tar.gz'; - - $cache = WP_CLI::get_cache(); - $cache_key = "core/{$update->locale}-{$update->version}.tar.gz"; - $cache_file = $cache->has( $cache_key ); - - if ( $cache_file ) { - WP_CLI::log( "Using cached file '$cache_file'..." ); - copy( $cache_file, $temp ); - return $temp; - } else { - // We need to use a temporary file because piping from cURL to tar is flaky - // on MinGW (and probably in other environments too). - $temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.tar.gz'; - - $headers = array('Accept' => 'application/json'); - $options = array( - 'timeout' => 600, // 10 minutes ought to be enough for everybody - 'filename' => $temp - ); - - Utils\get_request( $package, $headers, $options ); - $cache->import( $cache_key, $temp ); - return $temp; - } - }; - add_filter( 'upgrader_pre_download', $defer_cached_file, 10, 3 ); + $GLOBALS['wp_cli_update_obj'] = $update; $result = Utils\get_upgrader( $upgrader )->upgrade( $update ); - remove_filter( 'upgrader_pre_download', $defer_cached_file ); + unset( $GLOBALS['wp_cli_update_obj'] ); if ( is_wp_error($result) ) { $msg = WP_CLI::error_to_string( $result ); From 8ec0370bdee7ca01db980ada68a397d3de055e34 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 21 Aug 2014 12:40:36 -0700 Subject: [PATCH 5/9] Only indicate "Downloading" when we're actually downloading something --- features/core.feature | 8 ++++++++ php/WP_CLI/CoreUpgrader.php | 4 ++-- php/commands/core.php | 2 -- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/features/core.feature b/features/core.feature index 4191bdb6fc..9be8d2686d 100644 --- a/features/core.feature +++ b/features/core.feature @@ -308,6 +308,10 @@ Feature: Manage WordPress installation """ Using cached file """ + And STDOUT should contain: + """ + Downloading + """ When I run `wp core update --version=3.9 --force` Then STDOUT should not be empty @@ -317,6 +321,10 @@ Feature: Manage WordPress installation """ Using cached file '{SUITE_CACHE_DIR}/core/en_US-3.8.1.tar.gz'... """ + And STDOUT should not contain: + """ + Downloading + """ Scenario: User defined in wp-cli.yml diff --git a/php/WP_CLI/CoreUpgrader.php b/php/WP_CLI/CoreUpgrader.php index 37cc7f0d40..f30dfbdbb6 100644 --- a/php/WP_CLI/CoreUpgrader.php +++ b/php/WP_CLI/CoreUpgrader.php @@ -32,8 +32,6 @@ function download_package( $package ) { if ( empty( $package ) ) return new WP_Error( 'no_package', $this->strings['no_package'] ); - $this->skin->feedback( 'downloading_package', $package ); - $temp = sys_get_temp_dir() . '/' . uniqid('wp_') . '.tar.gz'; $cache = WP_CLI::get_cache(); @@ -56,6 +54,8 @@ function download_package( $package ) { 'filename' => $temp ); + $this->skin->feedback( 'downloading_package', $package ); + Utils\get_request( $package, $headers, $options ); $cache->import( $cache_key, $temp ); return $temp; diff --git a/php/commands/core.php b/php/commands/core.php index f95e396e9d..fed6a8cc65 100644 --- a/php/commands/core.php +++ b/php/commands/core.php @@ -790,8 +790,6 @@ function update( $args, $assoc_args ) { $new_package = $this->get_download_url($version, $locale); - WP_CLI::log( sprintf( 'Downloading WordPress %s (%s)...', $assoc_args['version'], $locale ) ); - $update = (object) array( 'response' => 'upgrade', 'current' => $assoc_args['version'], From 3811d39e217b333b0dcf86428368f7a1cc02e6ef Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 21 Aug 2014 12:44:46 -0700 Subject: [PATCH 6/9] Make this method generally more useful --- php/WP_CLI/CoreUpgrader.php | 2 +- php/commands/core.php | 8 ++++---- php/utils.php | 10 +++++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/php/WP_CLI/CoreUpgrader.php b/php/WP_CLI/CoreUpgrader.php index f30dfbdbb6..931fd4bbad 100644 --- a/php/WP_CLI/CoreUpgrader.php +++ b/php/WP_CLI/CoreUpgrader.php @@ -56,7 +56,7 @@ function download_package( $package ) { $this->skin->feedback( 'downloading_package', $package ); - Utils\get_request( $package, $headers, $options ); + Utils\http_request( 'GET', $package, $headers, $options ); $cache->import( $cache_key, $temp ); return $temp; } diff --git a/php/commands/core.php b/php/commands/core.php index fed6a8cc65..d88f3e6a0f 100644 --- a/php/commands/core.php +++ b/php/commands/core.php @@ -75,7 +75,7 @@ public function download( $args, $assoc_args ) { 'filename' => $temp ); - Utils\get_request( $download_url, $headers, $options ); + Utils\http_request( 'GET', $download_url, $headers, $options ); self::_extract( $temp, ABSPATH ); $cache->import( $cache_key, $temp ); unlink($temp); @@ -136,7 +136,7 @@ private static function _rmdir( $dir ) { private static function _read( $url ) { $headers = array('Accept' => 'application/json'); - return Utils\get_request( $url, $headers )->body; + return Utils\http_request( 'GET', $url, $headers )->body; } private function get_download_offer( $locale ) { @@ -659,11 +659,11 @@ private static function get_core_checksums( $version, $locale ) { $headers = array( 'Accept' => 'application/json' ); - $response = Utils\get_request( $url, $headers, $options ); + $response = Utils\http_request( 'GET', $url, $headers, $options ); if ( $ssl && ! $response->success ) { WP_CLI::warning( 'wp-cli could not establish a secure connection to WordPress.org. Please contact your server administrator.' ); - $response = Utils\get_request( $http_url, $headers, $options ); + $response = Utils\http_request( 'GET', $http_url, $headers, $options ); } if ( ! $response->success || 200 != $response->status_code ) diff --git a/php/utils.php b/php/utils.php index 60362ad7b4..3b34f5360e 100644 --- a/php/utils.php +++ b/php/utils.php @@ -403,13 +403,15 @@ function replace_path_consts( $source, $path ) { } /** - * Download a remote URL + * Make a HTTP request to a remote URL * + * @param string $method * @param string $url * @param array $headers * @param array $options + * @return object */ -function get_request( $url, $headers = array(), $options = array() ) { +function http_request( $method, $url, $headers = array(), $options = array() ) { $pem_copied = false; // cURL can't read Phar archives @@ -423,8 +425,10 @@ function get_request( $url, $headers = array(), $options = array() ) { $pem_copied = true; } + $method = strtolower( $method ); + try { - $request = \Requests::get( $url, $headers, $options ); + $request = \Requests::$method( $url, $headers, $options ); if ( $pem_copied ) { unlink( $options['verify'] ); } From b438af1924057350a7ab93b690b74c90ac0fc22e Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 21 Aug 2014 12:47:42 -0700 Subject: [PATCH 7/9] Validate methods --- php/utils.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/php/utils.php b/php/utils.php index 3b34f5360e..96d6419393 100644 --- a/php/utils.php +++ b/php/utils.php @@ -414,6 +414,13 @@ function replace_path_consts( $source, $path ) { function http_request( $method, $url, $headers = array(), $options = array() ) { $pem_copied = false; + $method = strtolower( $method ); + + if ( ! in_array( $method, array( 'get', 'post', 'put', 'delete', 'head', 'patch' ) ) ) { + $method = strtoupper( $method ); + WP_CLI::error( "Invalid method: {$method}" ); + } + // cURL can't read Phar archives if ( 0 === strpos( WP_CLI_ROOT, 'phar://' ) ) { $options['verify'] = sys_get_temp_dir() . '/wp-cli-cacert.pem'; @@ -425,8 +432,6 @@ function http_request( $method, $url, $headers = array(), $options = array() ) { $pem_copied = true; } - $method = strtolower( $method ); - try { $request = \Requests::$method( $url, $headers, $options ); if ( $pem_copied ) { From 494cc3e82c754496ac8fec1098839337dcceab72 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 21 Aug 2014 15:15:19 -0700 Subject: [PATCH 8/9] Allow `\Requests` to validate method on its own --- php/utils.php | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/php/utils.php b/php/utils.php index 96d6419393..e9baef00e6 100644 --- a/php/utils.php +++ b/php/utils.php @@ -414,13 +414,6 @@ function replace_path_consts( $source, $path ) { function http_request( $method, $url, $headers = array(), $options = array() ) { $pem_copied = false; - $method = strtolower( $method ); - - if ( ! in_array( $method, array( 'get', 'post', 'put', 'delete', 'head', 'patch' ) ) ) { - $method = strtoupper( $method ); - WP_CLI::error( "Invalid method: {$method}" ); - } - // cURL can't read Phar archives if ( 0 === strpos( WP_CLI_ROOT, 'phar://' ) ) { $options['verify'] = sys_get_temp_dir() . '/wp-cli-cacert.pem'; @@ -433,7 +426,7 @@ function http_request( $method, $url, $headers = array(), $options = array() ) { } try { - $request = \Requests::$method( $url, $headers, $options ); + $request = \Requests::request( $url, null, $method, $headers, $options ); if ( $pem_copied ) { unlink( $options['verify'] ); } @@ -446,7 +439,7 @@ function http_request( $method, $url, $headers = array(), $options = array() ) { } $options['verify'] = false; try { - return \Requests::get( $url, $headers, $options ); + return \Requests::request( $url, null, $method, $headers, $options ); } catch( \Requests_Exception $ex ) { \WP_CLI::error( $ex->getMessage() ); } From ec52a45ca1255dcafe46cfb0b30fc5a441a661fc Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 21 Aug 2014 15:44:24 -0700 Subject: [PATCH 9/9] Pass args in expected order, and allow `$data` as an option too --- php/WP_CLI/CoreUpgrader.php | 2 +- php/commands/core.php | 8 ++++---- php/utils.php | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/php/WP_CLI/CoreUpgrader.php b/php/WP_CLI/CoreUpgrader.php index 931fd4bbad..d3d3692e44 100644 --- a/php/WP_CLI/CoreUpgrader.php +++ b/php/WP_CLI/CoreUpgrader.php @@ -56,7 +56,7 @@ function download_package( $package ) { $this->skin->feedback( 'downloading_package', $package ); - Utils\http_request( 'GET', $package, $headers, $options ); + Utils\http_request( 'GET', $package, null, $headers, $options ); $cache->import( $cache_key, $temp ); return $temp; } diff --git a/php/commands/core.php b/php/commands/core.php index d88f3e6a0f..9466a3e6fe 100644 --- a/php/commands/core.php +++ b/php/commands/core.php @@ -75,7 +75,7 @@ public function download( $args, $assoc_args ) { 'filename' => $temp ); - Utils\http_request( 'GET', $download_url, $headers, $options ); + Utils\http_request( 'GET', $download_url, null, $headers, $options ); self::_extract( $temp, ABSPATH ); $cache->import( $cache_key, $temp ); unlink($temp); @@ -136,7 +136,7 @@ private static function _rmdir( $dir ) { private static function _read( $url ) { $headers = array('Accept' => 'application/json'); - return Utils\http_request( 'GET', $url, $headers )->body; + return Utils\http_request( 'GET', $url, null, $headers )->body; } private function get_download_offer( $locale ) { @@ -659,11 +659,11 @@ private static function get_core_checksums( $version, $locale ) { $headers = array( 'Accept' => 'application/json' ); - $response = Utils\http_request( 'GET', $url, $headers, $options ); + $response = Utils\http_request( 'GET', $url, null, $headers, $options ); if ( $ssl && ! $response->success ) { WP_CLI::warning( 'wp-cli could not establish a secure connection to WordPress.org. Please contact your server administrator.' ); - $response = Utils\http_request( 'GET', $http_url, $headers, $options ); + $response = Utils\http_request( 'GET', $http_url, null, $headers, $options ); } if ( ! $response->success || 200 != $response->status_code ) diff --git a/php/utils.php b/php/utils.php index e9baef00e6..fbee550acb 100644 --- a/php/utils.php +++ b/php/utils.php @@ -411,7 +411,7 @@ function replace_path_consts( $source, $path ) { * @param array $options * @return object */ -function http_request( $method, $url, $headers = array(), $options = array() ) { +function http_request( $method, $url, $data = null, $headers = array(), $options = array() ) { $pem_copied = false; // cURL can't read Phar archives @@ -426,7 +426,7 @@ function http_request( $method, $url, $headers = array(), $options = array() ) { } try { - $request = \Requests::request( $url, null, $method, $headers, $options ); + $request = \Requests::request( $url, $headers, $data, $method, $options ); if ( $pem_copied ) { unlink( $options['verify'] ); } @@ -439,7 +439,7 @@ function http_request( $method, $url, $headers = array(), $options = array() ) { } $options['verify'] = false; try { - return \Requests::request( $url, null, $method, $headers, $options ); + return \Requests::request( $url, $headers, $data, $method, $options ); } catch( \Requests_Exception $ex ) { \WP_CLI::error( $ex->getMessage() ); }