Skip to content

Theme updates non-atomic when --version flag specified #263

@msaladna

Description

@msaladna

Bug Report

Describe the current, buggy behavior

When --version=x.y.z is supplied to theme update the theme is first deleted, then installed. This is disastrous if WP cannot find the specified version for a theme or if a user supplies an incorrect version as the theme has now been deleted from the site.

Problem code

		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'] = true;
					$this->install( array( $theme->stylesheet ), $assoc_args );
				}
			}
		}

Reference: Theme_Command.php 658-668

Describe how other contributors can replicate this bug

wp --debug theme update twentynineteen --version=7.2
# Reports Error: Can't find the requested theme's version 7.2 in the WordPress.org theme repository (HTTP code 404).
wp --debug theme update twentynineteen --version=7.2
# Reports Warning: The 'twentynineteen' theme could not be found.
wp theme list
# twentynineteen now omitted from list

Describe what you would expect as the correct outcome
Theme update fails safely and does not remove the existing theme.

OS:     Linux 3.10.0-1062.18.1.el7.x86_64 #1 SMP Tue Mar 17 23:49:17 UTC 2020 x86_64
Shell:  /bin/bash
PHP binary:     /.socket/php/usr/bin/php
PHP version:    7.4.11
php.ini used:   /etc/php.ini
MySQL binary:   /usr/bin/mysql
MySQL version:  mysql  Ver 15.1 Distrib 10.3.22-MariaDB, for Linux (x86_64) using readline 5.1
SQL modes:      STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
WP-CLI root dir:        /var/www/wp-cli
WP-CLI vendor dir:      /var/www/wp-cli/vendor
WP_CLI phar path:
WP-CLI packages dir:
WP-CLI global config:   /home/benchmark-user/.wp-cli/config.yml
WP-CLI project config:
WP-CLI version: 2.5.0-alpha

Provide a possible solution
Rename theme, apply update, then delete or rename directory depending upon install().

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions