
內容簡介
這是一個功能插件,用於測試插件或主題更新失敗時的自動回滾。
它基於PR 的 #51857。當前的 PR #2225 和加到核心的 PR #3958。
更新插件/主題時,舊版本的插件/主題會移動到 wp-content/temp-backup/plugins/PLUGINNAME 或 wp-content/temp-backup/themes/THEMENAME 文件夾中。我們之所以選擇移動而不是壓縮,是因為壓縮/解壓縮是非常耗資源的過程,會增加低端共享主機的風險。另一方面,移動是即時完成的,不會成為瓶頸。
如果更新失敗,那麼我們在 temp-backup 文件夾中保存的“備份”將被恢復到其原始位置
如果更新成功,則刪除“備份”
在站點健康狀態屏幕中新增了2個檢查:
檢查回滾文件夾是否可寫。
檢查是否有足夠的磁盤空間可以安全地執行更新。
為避免混淆:不能使用“temp-backup”文件夾將插件回滾到以前的版本後進行的更新。此文件夾將僅包含正在更新的插件/主題的前一版本的瞬時備份,並且一旦更新過程完成,文件夾將為空。
測試
如果 wp-content/temp-backup 文件夾不可寫入,則網站健康屏幕中應顯示錯誤。
如果服務器可用空間小於20MB,則網站健康屏幕中應顯示錯誤,提示更新可能失敗。
如果服務器可用空間小於100MB,則應提示磁盤空間不足。
更新插件時,您應該能夠在 wp-content/temp-backup/plugins/PLUGINNAME 文件夾中看到舊的插件。主題也是一樣。由於更新有時會很快,而我們在測試期間可能會錯過文件夾創建,您可以模擬更新失敗以進行演示。這將提前返回並跳過更新成功時的備份刪除。
當插件更新失敗時,應恢復先前的版本。為測試此功能,將插件的版本更改為先前的版本號碼,運行更新,然後在失敗時應安裝在站點上的先前版本(您更改版本號的版本)。要模擬更新失敗並確認這一點是否正常工作,可以使用以下片段:
add_filter( 'upgrader_install_package_result', function() {
return new WP_Error( 'simulated_error', 'Simulated Error' );
});
或者,您可以安裝回滾更新測試插件,根據需要啟用。
或者使用內置的模擬失敗功能。只需從 plugins.php 頁面操作鏈結中啟用/停用即可。
報告問題
請在 GitHub 提交問題和 PR。
徽標來自於一個網絡迷因生成器。 原始文章。
外掛標籤
開發者團隊
📦 歷史版本下載
原文外掛簡介
This is a feature plugin is for testing Rollback Auto-Update, aka Rollback part 3. This feature only protects plugins during the auto-update process.
As part of the normal Rollback process, the currently installed version of the plugin is moved to wp-content/upgrade-temp-backup/plugins. An active plugin is checked to ensure it doesn’t cause a PHP fatal error when visiting the site. An inactive plugin is not checked because it cannot cause your site to white screen.
Rollback parts 1 was merged into WordPress 6.2 as the move_dir(). Rollback part 2 was merged into WordPress 6.3 and protects the manual update process of plugins and themes.
r53578
r55204
r55219
r55220
r55223
r55720
Testing
Requires WordPress 6.3
This only works on auto-updates.
Run the following commands from the terminal. You might need to run the command several times to get it started:
wp cron event run wp_version_check
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 simulate an update failure to demonstrate.
When a plugin auto-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, use the built-in Simulate failure link. Just activate/deactivate from the plugins.php page action link. This link will only be present if the plugin has an update pending.
Reporting
Please submit issues and PRs to GitHub.
Logo from a meme generator. Original artwork by Allie Brosh.
