Skip to content

Conversation

@aristath
Copy link
Member

@aristath aristath commented Jul 12, 2021

This patch aims to improve the stability of plugin/theme updates, by adding the ability to "rollback" failed updates.

  • When updating a plugin/theme, the old version of the plugin/theme gets moved to a wp-content/upgrade/temp-backup/plugins/PLUGINNAME or wp-content/upgrade/temp-backup/themes/THEMENAME folder. The reason we chose to move instead of zip, is because zipping/unzipping are very resources-intensive processes, and would increase the risk on low-end, shared hosts. Moving on the other hand is performed instantly and won't be a bottleneck.
  • If the update fails, then the "backup" we kept in the upgrade/temp-backup folder gets restored to its original location
  • If the update succeeds, then the "backup" is deleted
  • 2 new checks were added in the site-health screen:
    • Check to make sure that the rollbacks folder is writable.
    • Check there is enough disk-space available to safely perform updates.

To avoid confusion: The "temp-backup" folder will NOT be used to "roll-back" a plugin to a previous version after an update. This folder will simply contain a transient backup of the previous version of a plugins/themes getting updated, and as soon as the update process finishes, the folder will be empty.

Testing instructions:

  • If the wp-content/temp-backup folder is not writable, there should be an error in the site-health screen.
  • If the server has less than 20MB available, there should be an error in the site-health screen that updates may fail. If the server has less than 100MB, it should be a notice that disk space is running low.
  • When updating a plugin, you should be able to see the old plugin in the wp-content/upgrade/temp-backup/plugins/PLUGINNAME folder. The same should apply for themes. Since updates sometimes run fast and we may miss the folder creation during testing, you can add return true; as the 1st line inside the WP_Upgrader->delete_temp_backup() method. This will return early and skip deleting the backup on update-success.
  • When a plugin update fails, the previous version should be restored. To test that, change the version of a plugin to a previous number, run the update, and on fail the previous version (the one where you changed the version number) should still be installed on the site. To simulate an update failure and confirm this works, you can use the snippet below:
add_filter( 'upgrader_install_package_result', function() {
   return new WP_Error( 'simulated_error', 'Simulated Error' );
});

^ That is the main feature in this PR and what should be thoroughly tested: Update failures.

Trac ticket: https://core.trac.wordpress.org/ticket/51857


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@aristath aristath force-pushed the fix/update-unzip-rollbacks branch 3 times, most recently from 5ed7968 to 8f4fbb8 Compare July 15, 2021 05:37
@aristath aristath marked this pull request as ready for review August 16, 2021 08:43
@aristath aristath force-pushed the fix/update-unzip-rollbacks branch from 6b7b338 to fb471b3 Compare August 18, 2021 10:46
@aristath aristath force-pushed the fix/update-unzip-rollbacks branch from 1385ad8 to 84521d7 Compare September 6, 2021 09:06
@SergeyBiryukov
Copy link
Member

Thanks for the PR! Merged in https://core.trac.wordpress.org/changeset/51815.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants