Make WordPress Core


Ignore:
Timestamp:
12/10/2021 12:04:03 AM (3 years ago)
Author:
peterwilsoncc
Message:

Upgrade/install: Revert upgrader rollback features.

Revert the rollback features introduced for theme and plugin upgrades during the WordPress 5.9 cycle. A bug (suspected to be in third party virtualisation software) causes the upgrades to fail consistently on some set ups. The revert is to allow contributors further time to investigate mitigation options.

Reverts [52337], [52289], [52284], [51951], [52192], [51902], [51899], [51898], [51815].

Props pbiron, dlh, peterwilsoncc, galbaras, SergeyBiryukov, afragen, costdev, bronsonquick, aristath, noisysocks, desrosj, TobiasBg, hellofromTonya, francina, Boniu91.
See #54543, #54166, #51857.

File:
1 edited

Legend:

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

    r52337 r52351  
    134134     * and also add the generic strings to `WP_Upgrader::$strings`.
    135135     *
    136      * Additionally, it will schedule a weekly task to clean up the temp-backup directory.
    137      *
    138      * @since 2.8.0
    139      * @since 5.9.0 Added the `schedule_temp_backup_cleanup()` task.
     136     * @since 2.8.0
    140137     */
    141138    public function init() {
    142139        $this->skin->set_upgrader( $this );
    143140        $this->generic_strings();
    144 
    145         if ( ! wp_installing() ) {
    146             $this->schedule_temp_backup_cleanup();
    147         }
    148     }
    149 
    150     /**
    151      * Schedule cleanup of the temp-backup directory.
    152      *
    153      * @since 5.9.0
    154      */
    155     protected function schedule_temp_backup_cleanup() {
    156         if ( false === wp_next_scheduled( 'wp_delete_temp_updater_backups' ) ) {
    157             wp_schedule_event( time(), 'weekly', 'wp_delete_temp_updater_backups' );
    158         }
    159141    }
    160142
     
    185167        $this->strings['maintenance_start'] = __( 'Enabling Maintenance mode…' );
    186168        $this->strings['maintenance_end']   = __( 'Disabling Maintenance mode…' );
    187 
    188         /* translators: %s: temp-backup */
    189         $this->strings['temp_backup_mkdir_failed'] = sprintf( __( 'Could not create the %s directory.' ), 'temp-backup' );
    190         /* translators: %s: temp-backup */
    191         $this->strings['temp_backup_move_failed']    = sprintf( __( 'Could not move old version to the %s directory.' ), 'temp-backup' );
    192         $this->strings['temp_backup_restore_failed'] = __( 'Could not restore original version.' );
    193 
    194169    }
    195170
     
    339314        if ( ! empty( $upgrade_files ) ) {
    340315            foreach ( $upgrade_files as $file ) {
    341                 if ( 'temp-backup' === $file['name'] ) {
    342                     continue;
    343                 }
    344316                $wp_filesystem->delete( $upgrade_folder . $file['name'], true );
    345317            }
     
    522494        }
    523495
    524         if ( ! empty( $args['hook_extra']['temp_backup'] ) ) {
    525             $temp_backup = $this->move_to_temp_backup_dir( $args['hook_extra']['temp_backup'] );
    526             if ( is_wp_error( $temp_backup ) ) {
    527                 return $temp_backup;
    528             }
    529         }
    530 
    531496        // Retain the original source and destinations.
    532497        $remote_source     = $args['source'];
     
    628593        }
    629594
    630         // Move new version of item into place.
    631         $result = move_dir( $source, $remote_destination, $remote_source );
     595        // Copy new version of item into place.
     596        $result = copy_dir( $source, $remote_destination );
    632597        if ( is_wp_error( $result ) ) {
    633598            if ( $args['clear_working'] ) {
     
    637602        }
    638603
    639         // Clear the working directory?
     604        // Clear the working folder?
    640605        if ( $args['clear_working'] ) {
    641606            $wp_filesystem->delete( $remote_source, true );
     
    847812        $this->skin->set_result( $result );
    848813        if ( is_wp_error( $result ) ) {
    849             if ( ! empty( $options['hook_extra']['temp_backup'] ) ) {
    850                 /*
    851                  * Restore the backup on shutdown.
    852                  * Actions running on `shutdown` are immune to PHP timeouts,
    853                  * so in case the failure was due to a PHP timeout,
    854                  * we'll still be able to properly restore the previous version.
    855                  */
    856                 add_action(
    857                     'shutdown',
    858                     function() use ( $options ) {
    859                         $this->restore_temp_backup( $options['hook_extra']['temp_backup'] );
    860                     }
    861                 );
    862             }
    863814            $this->skin->error( $result );
    864815
     
    872823
    873824        $this->skin->after();
    874 
    875         // Clean up the backup kept in the temp-backup directory.
    876         if ( ! empty( $options['hook_extra']['temp_backup'] ) ) {
    877             // Delete the backup on `shutdown` to avoid a PHP timeout.
    878             add_action(
    879                 'shutdown',
    880                 function() use ( $options ) {
    881                     $this->delete_temp_backup( $options['hook_extra']['temp_backup'] );
    882                 }
    883             );
    884         }
    885825
    886826        if ( ! $options['is_multi'] ) {
     
    1008948        return delete_option( $lock_name . '.lock' );
    1009949    }
    1010 
    1011     /**
    1012      * Moves the plugin/theme being updated into a temp-backup directory.
    1013      *
    1014      * @since 5.9.0
    1015      *
    1016      * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
    1017      *
    1018      * @param array $args Array of data for the temp-backup. Must include a slug, the source, and directory.
    1019      * @return bool|WP_Error
    1020      */
    1021     public function move_to_temp_backup_dir( $args ) {
    1022         global $wp_filesystem;
    1023 
    1024         if ( empty( $args['slug'] ) || empty( $args['src'] ) || empty( $args['dir'] ) ) {
    1025             return false;
    1026         }
    1027 
    1028         /**
    1029          * Skip any plugin that has "." as its slug.
    1030          * A slug of "." will result in a `$src` value ending in a period.
    1031          *
    1032          * On Windows, this will cause the 'plugins' folder to be moved,
    1033          * and will cause a failure when attempting to call `mkdir()`.
    1034          */
    1035         if ( '.' === $args['slug'] ) {
    1036             return false;
    1037         }
    1038 
    1039         $dest_dir = $wp_filesystem->wp_content_dir() . 'upgrade/temp-backup/';
    1040         // Create the temp-backup directory if it doesn't exist.
    1041         if ( (
    1042                 ! $wp_filesystem->is_dir( $dest_dir )
    1043                 && ! $wp_filesystem->mkdir( $dest_dir )
    1044             ) || (
    1045                 ! $wp_filesystem->is_dir( $dest_dir . $args['dir'] . '/' )
    1046                 && ! $wp_filesystem->mkdir( $dest_dir . $args['dir'] . '/' )
    1047             )
    1048         ) {
    1049             return new WP_Error( 'fs_temp_backup_mkdir', $this->strings['temp_backup_mkdir_failed'] );
    1050         }
    1051 
    1052         $src  = trailingslashit( $args['src'] ) . $args['slug'];
    1053         $dest = $dest_dir . $args['dir'] . '/' . $args['slug'];
    1054 
    1055         // Delete the temp-backup directory if it already exists.
    1056         if ( $wp_filesystem->is_dir( $dest ) ) {
    1057             $wp_filesystem->delete( $dest, true );
    1058         }
    1059 
    1060         // Move to the temp-backup directory.
    1061         if ( ! move_dir( $src, $dest ) ) {
    1062             return new WP_Error( 'fs_temp_backup_move', $this->strings['temp_backup_move_failed'] );
    1063         }
    1064 
    1065         return true;
    1066     }
    1067 
    1068     /**
    1069      * Restores the plugin/theme from the temp-backup directory.
    1070      *
    1071      * @since 5.9.0
    1072      *
    1073      * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
    1074      *
    1075      * @param array $args Array of data for the temp-backup. Must include a slug, the source, and directory.
    1076      * @return bool|WP_Error
    1077      */
    1078     public function restore_temp_backup( $args ) {
    1079         global $wp_filesystem;
    1080 
    1081         if ( empty( $args['slug'] ) || empty( $args['src'] ) || empty( $args['dir'] ) ) {
    1082             return false;
    1083         }
    1084 
    1085         $src  = $wp_filesystem->wp_content_dir() . 'upgrade/temp-backup/' . $args['dir'] . '/' . $args['slug'];
    1086         $dest = trailingslashit( $args['src'] ) . $args['slug'];
    1087 
    1088         if ( $wp_filesystem->is_dir( $src ) ) {
    1089             // Cleanup.
    1090             if ( $wp_filesystem->is_dir( $dest ) && ! $wp_filesystem->delete( $dest, true ) ) {
    1091                 return new WP_Error( 'fs_temp_backup_delete', $this->strings['temp_backup_restore_failed'] );
    1092             }
    1093 
    1094             // Move it.
    1095             if ( ! move_dir( $src, $dest ) ) {
    1096                 return new WP_Error( 'fs_temp_backup_delete', $this->strings['temp_backup_restore_failed'] );
    1097             }
    1098         }
    1099 
    1100         return true;
    1101     }
    1102 
    1103     /**
    1104      * Deletes a temp-backup.
    1105      *
    1106      * @since 5.9.0
    1107      *
    1108      * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
    1109      *
    1110      * @param array $args Array of data for the temp-backup. Must include a slug, the source, and directory.
    1111      * @return bool
    1112      */
    1113     public function delete_temp_backup( $args ) {
    1114         global $wp_filesystem;
    1115 
    1116         if ( empty( $args['slug'] ) || empty( $args['dir'] ) ) {
    1117             return false;
    1118         }
    1119 
    1120         return $wp_filesystem->delete(
    1121             $wp_filesystem->wp_content_dir() . "upgrade/temp-backup/{$args['dir']}/{$args['slug']}",
    1122             true
    1123         );
    1124     }
    1125950}
    1126951
Note: See TracChangeset for help on using the changeset viewer.