WordPress.org

Make WordPress Core

Changeset 51902


Ignore:
Timestamp:
10/11/2021 03:07:52 PM (8 weeks ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-upgrader.php

    r51899 r51902  
    844844        if ( is_wp_error( $result ) ) {
    845845            if ( ! empty( $options['hook_extra']['temp_backup'] ) ) {
    846                 $this->restore_temp_backup( $options['hook_extra']['temp_backup'] );
     846                /*
     847                 * Restore the backup on shutdown.
     848                 * Actions running on `shutdown` are immune to PHP timeouts,
     849                 * so in case the failure was due to a PHP timeout,
     850                 * we'll still be able to properly restore the previous version.
     851                 */
     852                add_action(
     853                    'shutdown',
     854                    function() use ( $options ) {
     855                        $this->restore_temp_backup( $options['hook_extra']['temp_backup'] );
     856                    }
     857                );
    847858            }
    848859            $this->skin->error( $result );
     
    860871        // Clean up the backup kept in the temp-backup directory.
    861872        if ( ! empty( $options['hook_extra']['temp_backup'] ) ) {
    862             $this->delete_temp_backup( $options['hook_extra']['temp_backup'] );
     873            // Delete the backup on `shutdown` to avoid a PHP timeout.
     874            add_action(
     875                'shutdown',
     876                function() use ( $options ) {
     877                    $this->delete_temp_backup( $options['hook_extra']['temp_backup'] );
     878                }
     879            );
    863880        }
    864881
Note: See TracChangeset for help on using the changeset viewer.