Manual work after WordPress auto update failed

WordPress 版本都到 4.9 了,全球 CMS 占有量也早过三分之一了,自动更新居然还是全量下载,连个增量更新都不做(光做 no-content.zip 有啥用拜托?)。虚拟主机下载 WordPress 的包速度又很慢,结果总是超时(虚拟主机控制的那种超时断开),更新失败。

网上搜了一圈,居然官方建议是“绝对是你的主机有问题,请手动更新”。网差一点还被说是主机不行?那就只能自己来呗。

My WordPress auto update always failed because of slow download speed. Just don't know why WordPress doesn't implement a incremental upgrade mechanism (maybe I should search for a ticket?). Whatever, I have to solve it manually, in a smart way.

P.S. 写完这篇之后,看到更新的 API 了,的确是有增量更新的,但他们不用。They actually have incremental upgrade implemented, but they hardly use it.

1 - 手工增量更新 Manual Incremental Upgrade

去 GitHub 看两次更新之间变了什么东西,比如 WordPress 4.9 到 4.9.1(https://github.com/WordPress/WordPress/compare/4.9...4.9.1),只更新了 18 个文件,居然要重新下载一回 10M+ 的内容,真的不能忍。反正也就十几个文件,手工在 GitHub 上下载文件,然后一个一个覆盖到服务器也还行,总比疯狂超时、全覆盖文件快得多。

Go to GitHub to compare changes between versions. Like 4.9 to 4.9.1: https://github.com/WordPress/WordPress/compare/4.9...4.9.1

Only 18 files! Then I manually clicked through View > Raw > Ctrl+S on these 18 files, and override them on the server by FTP. Still better than overriding all files, or always timeout on the dashboard!

下面这个嘛,就是我手工下载的 wordpress-4.9-4.9.1.zip 补丁包(GitHub 版),使用自担风险:https://u14796219.ctfile.com/fs/14796219-232185992

不过像我用的是中文版,手动用 GitHub 的 diff 覆盖完,还是提示有中文版更新。于是我一气之下,把两个本地化版本的 release 包下载下来看区别,卧槽更新是一样的啊。

仔细一看,GitHub 版和中文版有个区别:wp-includes/version.php 里,GitHub 版是没有定义 $wp_local_package 的,而中文版最后有一行 $wp_local_package = 'zh_CN'; ,不加上的话,如果 locale 用的是中文,就会疯狂提示你更新。加上这行之后马上就好了

ATTENTION to localized versions: add $wp_local_package = 'zh_CN'; (change zh_CN to your i18n code) to wp-includes/version.php, or you will get indefinite upgrade notice.

2 - 手动帮自动更新完成下载的步骤 Manually finish the download for the auto upgrade

当然这个方法似乎跟手动解压全部文件覆盖相比,麻烦得多,不过我还是相信程序的更新能力的,所以我只是替程序完成了下载这个超时的步骤而已。

This is somewhat more complex than just overriding all files with the zip. However, I just believe the code does the job better than me.

首先,自然是手动下载 WordPress 页面上提示下载失败的 zip 文件,然后放到服务器的某个位置。然后找到需要更新的 WordPress,修改 wp-admin/includes/class-core-upgrader.php:121

Firstly, download the URL given on the upgrade process page, and put the zip file somewhere on your server. Then patch wp-admin/includes/class-core-upgrader.php:121

// $download = $this->download_package( $current->packages->$to_download );
// Comment this out, and add the line below; $download accepts string|WP_Error
$download = "/absolute-path-to-zip-file.zip";

然后等 10 分钟后 WordPress 的自动更新锁超时,或者不耐烦的话去数据库里 wp_options 里删那条更新锁的记录,然后再运行程序更新。当然更新完之后记得把 class-core-upgrader.php 改回来咯(我也忘记这个会不会被更新覆盖掉了)。

Wait for 10 minutes when WordPress's upgrade lock timed out (or you can manually delete the lock record in MySQL in wp_options), and run the auto upgrade again. After the upgrade, remember to edit back class-core-upgrader.php (I don't remember whether changes to it will be overridden by the upgrade).

发表评论

电子邮件地址不会被公开。 必填项已用*标注