wp-cli / extension-command

Manages plugins and themes, including installs, activations, and updates.
MIT License
85 stars 82 forks source link

Subtheme installation fails after installing main theme, if subtheme was tried first, due to left-behind directory #410

Open mvl22 opened 4 months ago

mvl22 commented 4 months ago

If you attempt to install a theme which is a subtheme, the install returns:

The parent theme could not be found. You will need to install the parent theme, <parent-theme-name>, before you can use this child theme.

However, it leaves behind a directory. After going to install the parent theme, re-running the command to install the subtheme then fails, with:

Destination folder already exists.

For instance:

# Attempt to install rockfield theme (not realising this is a subtheme)
wp theme install https://public-api.wordpress.com/rest/v1/themes/download/rockfield.zip --activate
# returns error "The parent theme could not be found. You will need to install the parent theme..."

# Attempt to install main theme
wp theme install https://public-api.wordpress.com/rest/v1/themes/download/varia.zip --activate
# returns success

# Now, go back to install the subtheme, rockfield:
wp theme install https://public-api.wordpress.com/rest/v1/themes/download/rockfield.zip --activate
# returns error "Destination folder already exists..."

# Workaround - firstly remove the left-behind folder, then retry the subtheme install:
rm -rf /path/to/wp-content/themes/rockfield-wpcom
wp theme install https://public-api.wordpress.com/rest/v1/themes/download/rockfield.zip --activate

If installation of a subtheme fails because the main theme is not there, the folder should not be left behind, i.e. it should be properly atomic.

wojsmol commented 4 months ago

Hi Other workaround is to use --force parameter - wp theme install https://public-api.wordpress.com/rest/v1/themes/download/rockfield.zip --activate --force

danielbachhuber commented 4 months ago

If installation of a subtheme fails because the main theme is not there, the folder should not be left behind, i.e. it should be properly atomic.

I agree with this.

Feel free to submit a pull request, if you'd like. Here is some guidance on our pull request best practices.

UmeshSingla commented 1 month ago

I'm unable to replicate the issue. WP CLI definitely throws an error when it tries to activate the newly installed child theme with no parent theme available in WordPress install.

But once you install the parent theme, child theme can be successfully activated from the back-end or the shell, there is no need to install the child theme again.

wp theme install https://public-api.wordpress.com/rest/v1/themes/download/rockfield.zip --activate

Downloading installation package from https://public-api.wordpress.com/rest/v1/themes/download/rockfield.zip... Unpacking the package... Installing the theme... This theme requires a parent theme. Checking if it is installed... The parent theme could not be found. You will need to install the parent theme, varia-wpcom, before you can use this child theme. Theme installed successfully. Activating 'rockfield-wpcom'... Error: The parent theme is missing. Please install the "varia-wpcom" parent theme.

wp theme install https://public-api.wordpress.com/rest/v1/themes/download/varia.zip --activate

Downloading installation package from https://public-api.wordpress.com/rest/v1/themes/download/varia.zip... Unpacking the package... Installing the theme... Theme installed successfully. Activating 'varia-wpcom'... Success: Switched to 'Varia' theme. Success: Installed 1 of 1 themes.

wp theme activate rockfield-wpcom

Success: Switched to 'Rockfield' theme.