Upgrade/Install: Restore or clean up the temporary plugin or theme backup on shutdown.

This allows these actions to run ''after'' the main process, without affecting the update. Actions running on `shutdown` are immune to PHP timeouts, so in case the failure was due to a PHP timeout, we'll still be able to properly restore the previous version.

Follow-up to [51815], [51898], [51899].

Props aristath, peterwilsoncc.
See #54166.
Built from https://develop.svn.wordpress.org/trunk@51902


git-svn-id: http://core.svn.wordpress.org/trunk@51495 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2021-10-11 15:09:05 +00:00
parent 130979f91e
commit 2030b6e313
2 changed files with 20 additions and 3 deletions

View File

@ -843,7 +843,18 @@ class WP_Upgrader {
$this->skin->set_result( $result );
if ( is_wp_error( $result ) ) {
if ( ! empty( $options['hook_extra']['temp_backup'] ) ) {
$this->restore_temp_backup( $options['hook_extra']['temp_backup'] );
/*
* Restore the backup on shutdown.
* Actions running on `shutdown` are immune to PHP timeouts,
* so in case the failure was due to a PHP timeout,
* we'll still be able to properly restore the previous version.
*/
add_action(
'shutdown',
function() use ( $options ) {
$this->restore_temp_backup( $options['hook_extra']['temp_backup'] );
}
);
}
$this->skin->error( $result );
@ -859,7 +870,13 @@ class WP_Upgrader {
// Clean up the backup kept in the temp-backup directory.
if ( ! empty( $options['hook_extra']['temp_backup'] ) ) {
$this->delete_temp_backup( $options['hook_extra']['temp_backup'] );
// Delete the backup on `shutdown` to avoid a PHP timeout.
add_action(
'shutdown',
function() use ( $options ) {
$this->delete_temp_backup( $options['hook_extra']['temp_backup'] );
}
);
}
if ( ! $options['is_multi'] ) {

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.9-alpha-51901';
$wp_version = '5.9-alpha-51902';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.