diff --git a/features/core.feature b/features/core.feature index b0cc7b5d67..0a9f5af4cc 100644 --- a/features/core.feature +++ b/features/core.feature @@ -270,9 +270,9 @@ Feature: Manage WordPress installation When I run `wp core check-update` Then STDOUT should be a table containing rows: | version | update_type | package_url | - | 4.0 | major | https://wordpress.org/wordpress-4.0.zip | - | 3.9.2 | major | https://wordpress.org/wordpress-3.9.2.zip | - | 3.8.4 | minor | https://wordpress.org/wordpress-3.8.4.zip | + | 4.0.1 | major | https://wordpress.org/wordpress-4.0.1.zip | + | 3.9.3 | major | https://wordpress.org/wordpress-3.9.3.zip | + | 3.8.5 | minor | https://wordpress.org/wordpress-3.8.5.zip | When I run `wp core check-update --field=version | wc -l` Then STDOUT should be: @@ -283,8 +283,8 @@ Feature: Manage WordPress installation When I run `wp core check-update --major` Then STDOUT should be a table containing rows: | version | update_type | package_url | - | 4.0 | major | https://wordpress.org/wordpress-4.0.zip | - | 3.9.2 | major | https://wordpress.org/wordpress-3.9.2.zip | + | 4.0.1 | major | https://wordpress.org/wordpress-4.0.1.zip | + | 3.9.3 | major | https://wordpress.org/wordpress-3.9.3.zip | When I run `wp core check-update --major --field=version | wc -l` Then STDOUT should be: @@ -295,7 +295,7 @@ Feature: Manage WordPress installation When I run `wp core check-update --minor` Then STDOUT should be a table containing rows: | version | update_type | package_url | - | 3.8.4 | minor | https://wordpress.org/wordpress-3.8.4.zip | + | 3.8.5 | minor | https://wordpress.org/wordpress-3.8.5.zip | When I run `wp core check-update --minor --field=version | wc -l` Then STDOUT should be: diff --git a/features/plugin.feature b/features/plugin.feature index 530c217d79..c79aee297b 100644 --- a/features/plugin.feature +++ b/features/plugin.feature @@ -324,3 +324,16 @@ Feature: Manage WordPress plugins | handbook/handbook | inactive | | handbook/functionality-for-pages | active | + Scenario: Install a plugin, then update to a specific version of that plugin + Given a WP install + + When I run `wp plugin install akismet --version=2.5.7 --force` + Then STDOUT should not be empty + + When I run `wp plugin update akismet --version=2.6.0` + Then STDOUT should not be empty + + When I run `wp plugin list --fields=name,version` + Then STDOUT should be a table containing rows: + | name | version | + | akismet | 2.6.0 | diff --git a/features/theme.feature b/features/theme.feature index 6ad011a7e2..fde24c9933 100644 --- a/features/theme.feature +++ b/features/theme.feature @@ -211,3 +211,17 @@ Feature: Manage WordPress themes """ Error: This is not a multisite install. """ + + Scenario: Install a theme, then update to a specific version of that theme + Given a WP install + + When I run `wp theme install p2 --version=1.4.1` + Then STDOUT should not be empty + + When I run `wp theme update p2 --version=1.4.2` + Then STDOUT should not be empty + + When I run `wp theme list --fields=name,version` + Then STDOUT should be a table containing rows: + | name | version | + | p2 | 1.4.2 | diff --git a/php/commands/core.php b/php/commands/core.php index dfdb15e289..85807ad809 100644 --- a/php/commands/core.php +++ b/php/commands/core.php @@ -52,7 +52,7 @@ function check_update( $_, $assoc_args ) { $release_data = json_decode( $response->body ); $release_versions = array_keys( (array) $release_data ); usort( $release_versions, function( $a, $b ){ - return ! version_compare( $a, $b ); + return 1 === version_compare( $a, $b ); }); $locale = get_locale(); @@ -86,6 +86,7 @@ function check_update( $_, $assoc_args ) { } if ( $updates ) { + $updates = array_reverse( $updates ); $formatter = new \WP_CLI\Formatter( $assoc_args, array( 'version', 'update_type', 'package_url' ) diff --git a/php/commands/plugin.php b/php/commands/plugin.php index 95cd478b79..1cdaadaae9 100644 --- a/php/commands/plugin.php +++ b/php/commands/plugin.php @@ -298,8 +298,7 @@ protected function install_from_repo( $slug, $assoc_args ) { * : If set, all plugins that have updates will be updated. * * [--version=] - * : If set, the plugin will be updated to the latest development version, - * regardless of what version is currently installed. + * : If set, the plugin will be updated to the specified version. * * [--dry-run] * : Preview which plugins would be updated. @@ -311,9 +310,11 @@ protected function install_from_repo( $slug, $assoc_args ) { * wp plugin update --all */ function update( $args, $assoc_args ) { - if ( isset( $assoc_args['version'] ) && 'dev' == $assoc_args['version'] ) { + if ( isset( $assoc_args['version'] ) ) { foreach ( $this->fetcher->get_many( $args ) as $plugin ) { $this->_delete( $plugin ); + + $assoc_args['force'] = 1; $this->install( array( $plugin->name ), $assoc_args ); } } else { diff --git a/php/commands/scaffold.php b/php/commands/scaffold.php index babe849e42..050b812285 100644 --- a/php/commands/scaffold.php +++ b/php/commands/scaffold.php @@ -490,7 +490,7 @@ function plugin_tests( $args, $assoc_args ) { foreach ( $to_copy as $file => $dir ) { $wp_filesystem->copy( WP_CLI_ROOT . "/templates/$file", "$dir/$file", true ); if ( 'install-wp-tests.sh' === $file ) { - if ( ! $wp_filesystem->chmod( "$dir/$file", '0755' ) ) { + if ( ! $wp_filesystem->chmod( "$dir/$file", 0755 ) ) { WP_CLI::warning( "Couldn't mark install-wp-tests.sh as executable." ); } } @@ -632,4 +632,3 @@ private function init_wp_filesystem() { } WP_CLI::add_command( 'scaffold', 'Scaffold_Command' ); - diff --git a/php/commands/theme.php b/php/commands/theme.php index adceda527d..9a09e10f0f 100644 --- a/php/commands/theme.php +++ b/php/commands/theme.php @@ -440,8 +440,7 @@ public function get( $args, $assoc_args ) { * : If set, all themes that have updates will be updated. * * [--version=] - * : If set, the theme will be updated to the latest development version, - * regardless of what version is currently installed. + * : If set, the plugin will be updated to the specified version. * * [--dry-run] * : Preview which themes would be updated. @@ -453,7 +452,19 @@ public function get( $args, $assoc_args ) { * wp theme update --all */ function update( $args, $assoc_args ) { - parent::update_many( $args, $assoc_args ); + if ( isset( $assoc_args['version'] ) ) { + foreach ( $this->fetcher->get_many( $args ) as $theme ) { + $r = delete_theme( $theme->stylesheet ); + if ( is_wp_error( $r ) ) { + WP_CLI::warning( $r ); + } else { + $assoc_args['force'] = 1; + $this->install( array( $theme->stylesheet ), $assoc_args ); + } + } + } else { + parent::update_many( $args, $assoc_args ); + } } /** diff --git a/utils/wp-cli-updatedeb.sh b/utils/wp-cli-updatedeb.sh new file mode 100644 index 0000000000..c4f34efb51 --- /dev/null +++ b/utils/wp-cli-updatedeb.sh @@ -0,0 +1,83 @@ +#!/bin/bash +# +# Package wp-cli to be installed in Debian-compatible systems. +# Only the phar file is included. +# +# VERSION :0.2 +# DATE :2014-11-19 +# AUTHOR :Viktor Szépe +# LICENSE :The MIT License (MIT) +# URL :https://github.com/wp-cli/wp-cli/tree/master/utils +# BASH-VERSION :4.2+ + +# packages source path +DIR="php-wpcli" +# phar URL +PHAR="https://github.com/wp-cli/builds/raw/gh-pages/phar/wp-cli.phar" + +die() { + local RET="$1" + shift + + echo -e "$@" >&2 + exit "$RET" +} + +dump_control() { + cat > DEBIAN/control < +Section: php +Priority: optional +Depends: php5-cli, php5-mysql | php5-mysqlnd, mysql-client +Homepage: http://wp-cli.org/ +Description: wp-cli is a set of command-line tools for managing + WordPress installations. You can update plugins, set up multisite + installs and much more, without using a web browser. + +CTRL +} + +# deb's dir +if ! [ -d "$DIR" ]; then + mkdir "$DIR" || die 1 "Cannot create directory here: ${PWD}" +fi + +pushd "$DIR" + +# control file +if ! [ -r DEBIAN/control ]; then + mkdir DEBIAN + dump_control +fi + +# content dirs +[ -d usr/bin ] || mkdir -p usr/bin + +# download current version +wget -nv -O usr/bin/wp "$PHAR" || die 3 "Phar download failure" +chmod +x usr/bin/wp || die 4 "chmod failure" + +# get version +WPCLI_VER="$(grep -ao "define.*WP_CLI_VERSION.*;" usr/bin/wp | cut -d"'" -f4)" +[ -z "$WPCLI_VER" ] && die 5 "Cannot get wp-cli version" +echo "Current version: ${WPCLI_VER}" + +# update version +sed -i "s/^Version: .*$/Version: ${WPCLI_VER}/" DEBIAN/control || die 6 "Version update failure" + +# update MD5-s +find usr -type f -exec md5sum \{\} \; > DEBIAN/md5sums || die 7 "md5sum creation failure" + +popd + +# build package in the current diretory +WPCLI_PKG="${PWD}/php-wpcli_${WPCLI_VER}_all.deb" +fakeroot dpkg-deb --build "$DIR" "$WPCLI_PKG" || die 8 "Packaging failed" + +# optional steps +echo "sign it: dpkg-sig -k -s builder \"$WPCLI_PKG\"" +echo "include in your repo: pushd /var/www/" +echo "reprepro includedeb wheezy \"$WPCLI_PKG\" && popd"