Make WordPress Core

Changeset 55720

Timestamp:
05/04/2023 02:34:58 AM (15 months ago)
Author:
SergeyBiryukov
Message:

Upgrade/Install: Create a temporary backup of plugins and themes before updating.

This aims to make the update process more reliable and ensures that if a plugin or theme update fails, the previous version can be safely restored.

  • When updating a plugin or theme, the old version is moved to a temporary backup directory:
    • wp-content/upgrade-temp-backup/plugins/[plugin-slug] for plugins
    • wp-content/upgrade-temp-backup/themes/[theme-slug] for themes.
  • If the update fails, then the backup kept in the temporary backup directory is restored to its original location.
  • If the update succeeds, the temporary backup is deleted.

To further help troubleshoot plugin and theme updates, two new checks were added to the Site Health screen:

  • A check to make sure that the upgrade-temp-backup directory is writable.
  • A check that there is enough disk space available to safely perform updates.

To avoid confusion: The temporary backup directory will NOT be used to “roll back” a plugin to a previous version after a completed update. This directory will simply contain a transient backup of the previous version of a plugin or theme being updated, and as soon as the update process finishes, the directory will be empty.

Follow-up to [55204], [55220].

Props afragen, costdev, pbiron, azaozz, hellofromTonya, aristath, peterwilsoncc, TJNowell, bronsonquick, Clorith, dd32, poena, TimothyBlynJacobs, audrasjb, mikeschroder, a2hosting, KZeni, galbaras, richards1052, Boniu91, mai21, francina, TobiasBg, desrosj, noisysocks, johnbillion, dlh, chaion07, davidbaumwald, jrf, thisisyeasin, ignatggeorgiev, SergeyBiryukov.
Fixes #51857.

Location:
trunk/src
Files:
5 edited

Legend:

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

    r53426 r55720  
    227227                'clear_working'     => true,
    228228                'hook_extra'        => array(
    229                     'plugin' => $plugin,
    230                     'type'   => 'plugin',
    231                     'action' => 'update',
     229                    'plugin'      => $plugin,
     230                    'type'        => 'plugin',
     231                    'action'      => 'update',
     232                    'temp_backup' => array(
     233                        'slug' => dirname( $plugin ),
     234                        'src'  => WP_PLUGIN_DIR,
     235                        'dir'  => 'plugins',
     236                    ),
    232237                ),
    233238            )
     
    343348                    'is_multi'          => true,
    344349                    'hook_extra'        => array(
    345                         'plugin' => $plugin,
     350                        'plugin'      => $plugin,
     351                        'temp_backup' => array(
     352                            'slug' => dirname( $plugin ),
     353                            'src'  => WP_PLUGIN_DIR,
     354                            'dir'  => 'plugins',
     355                        ),
    346356                    ),
    347357                )
  • trunk/src/wp-admin/includes/class-theme-upgrader.php

    r53426 r55720  
    329329                'clear_working'     => true,
    330330                'hook_extra'        => array(
    331                     'theme'  => $theme,
    332                     'type'   => 'theme',
    333                     'action' => 'update',
     331                    'theme'       => $theme,
     332                    'type'        => 'theme',
     333                    'action'      => 'update',
     334                    'temp_backup' => array(
     335                        'slug' => $theme,
     336                        'src'  => get_theme_root( $theme ),
     337                        'dir'  => 'themes',
     338                    ),
    334339                ),
    335340            )
     
    444449                    'is_multi'          => true,
    445450                    'hook_extra'        => array(
    446                         'theme' => $theme,
     451                        'theme'       => $theme,
     452                        'temp_backup' => array(
     453                            'slug' => $theme,
     454                            'src'  => get_theme_root( $theme ),
     455                            'dir'  => 'themes',
     456                        ),
    447457                    ),
    448458                )
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r55703 r55720  
    19271927
    19281928    /**
     1929
     1930
     1931
     1932
     1933
     1934
     1935
     1936
     1937
     1938
     1939
     1940
     1941
     1942
     1943
     1944
     1945
     1946
     1947
     1948
     1949
     1950
     1951
     1952
     1953
     1954
     1955
     1956
     1957
     1958
     1959
     1960
     1961
     1962
     1963
     1964
     1965
     1966
     1967
     1968
     1969
     1970
     1971
     1972
     1973
     1974
     1975
     1976
     1977
     1978
     1979
     1980
     1981
     1982
     1983
     1984
     1985
     1986
     1987
     1988
     1989
     1990
     1991
     1992
     1993
     1994
     1995
     1996
     1997
     1998
     1999
     2000
     2001
     2002
     2003
     2004
     2005
     2006
     2007
     2008
     2009
     2010
     2011
     2012
     2013
     2014
     2015
     2016
     2017
     2018
     2019
     2020
     2021
     2022
     2023
     2024
     2025
     2026
     2027
     2028
     2029
     2030
     2031
     2032
     2033
     2034
     2035
     2036
     2037
     2038
     2039
     2040
     2041
     2042
     2043
     2044
     2045
     2046
     2047
     2048
     2049
     2050
     2051
     2052
     2053
     2054
     2055
     2056
     2057
     2058
     2059
     2060
     2061
     2062
     2063
     2064
     2065
     2066
     2067
     2068
     2069
     2070
     2071
     2072
     2073
     2074
     2075
     2076
     2077
     2078
     2079
     2080
     2081
     2082
     2083
     2084
     2085
     2086
     2087
     2088
     2089
     2090
     2091
     2092
     2093
     2094
     2095
     2096
     2097
     2098
     2099
     2100
     2101
     2102
     2103
     2104
     2105
     2106
     2107
     2108
     2109
     2110
     2111
     2112
     2113
     2114
     2115
    19292116     * Tests if loopbacks work as expected.
    19302117     *
     
    25332720        $tests = array(
    25342721            'direct' => array(
    2535                 'wordpress_version'         => array(
     2722                'wordpress_version'         => array(
    25362723                    'label' => __( 'WordPress Version' ),
    25372724                    'test'  => 'wordpress_version',
    25382725                ),
    2539                 'plugin_version'            => array(
     2726                'plugin_version'            => array(
    25402727                    'label' => __( 'Plugin Versions' ),
    25412728                    'test'  => 'plugin_version',
    25422729                ),
    2543                 'theme_version'             => array(
     2730                'theme_version'             => array(
    25442731                    'label' => __( 'Theme Versions' ),
    25452732                    'test'  => 'theme_version',
    25462733                ),
    2547                 'php_version'               => array(
     2734                'php_version'               => array(
    25482735                    'label' => __( 'PHP Version' ),
    25492736                    'test'  => 'php_version',
    25502737                ),
    2551                 'php_extensions'            => array(
     2738                'php_extensions'            => array(
    25522739                    'label' => __( 'PHP Extensions' ),
    25532740                    'test'  => 'php_extensions',
    25542741                ),
    2555                 'php_default_timezone'      => array(
     2742                'php_default_timezone'      => array(
    25562743                    'label' => __( 'PHP Default Timezone' ),
    25572744                    'test'  => 'php_default_timezone',
    25582745                ),
    2559                 'php_sessions'              => array(
     2746                'php_sessions'              => array(
    25602747                    'label' => __( 'PHP Sessions' ),
    25612748                    'test'  => 'php_sessions',
    25622749                ),
    2563                 'sql_server'                => array(
     2750                'sql_server'                => array(
    25642751                    'label' => __( 'Database Server version' ),
    25652752                    'test'  => 'sql_server',
    25662753                ),
    2567                 'utf8mb4_support'           => array(
     2754                'utf8mb4_support'           => array(
    25682755                    'label' => __( 'MySQL utf8mb4 support' ),
    25692756                    'test'  => 'utf8mb4_support',
    25702757                ),
    2571                 'ssl_support'               => array(
     2758                'ssl_support'               => array(
    25722759                    'label' => __( 'Secure communication' ),
    25732760                    'test'  => 'ssl_support',
    25742761                ),
    2575                 'scheduled_events'          => array(
     2762                'scheduled_events'          => array(
    25762763                    'label' => __( 'Scheduled events' ),
    25772764                    'test'  => 'scheduled_events',
    25782765                ),
    2579                 'http_requests'             => array(
     2766                'http_requests'             => array(
    25802767                    'label' => __( 'HTTP Requests' ),
    25812768                    'test'  => 'http_requests',
    25822769                ),
    2583                 'rest_availability'         => array(
     2770                'rest_availability'         => array(
    25842771                    'label'     => __( 'REST API availability' ),
    25852772                    'test'      => 'rest_availability',
    25862773                    'skip_cron' => true,
    25872774                ),
    2588                 'debug_enabled'             => array(
     2775                'debug_enabled'             => array(
    25892776                    'label' => __( 'Debugging enabled' ),
    25902777                    'test'  => 'is_in_debug_mode',
    25912778                ),
    2592                 'file_uploads'              => array(
     2779                'file_uploads'              => array(
    25932780                    'label' => __( 'File uploads' ),
    25942781                    'test'  => 'file_uploads',
    25952782                ),
    2596                 'plugin_theme_auto_updates' => array(
     2783                'plugin_theme_auto_updates' => array(
    25972784                    'label' => __( 'Plugin and theme auto-updates' ),
    25982785                    'test'  => 'plugin_theme_auto_updates',
     2786
     2787
     2788
     2789
     2790
     2791
     2792
     2793
    25992794                ),
    26002795            ),
  • trunk/src/wp-admin/includes/class-wp-upgrader.php

    r55258 r55720  
    114114
    115115    /**
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
    116136     * Construct the upgrader with a skin.
    117137     *
     
    135155     * and also add the generic strings to `WP_Upgrader::$strings`.
    136156     *
     157
     158
    137159     * @since 2.8.0
     160
    138161     */
    139162    public function init() {
    140163        $this->skin->set_upgrader( $this );
    141164        $this->generic_strings();
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
     178
     179
    142180    }
    143181
     
    168206        $this->strings['maintenance_start'] = __( 'Enabling Maintenance mode…' );
    169207        $this->strings['maintenance_end']   = __( 'Disabling Maintenance mode…' );
     208
     209
     210
     211
     212
     213
     214
     215
     216
    170217    }
    171218
     
    309356        $this->skin->feedback( 'unpack_package' );
    310357
     358
     359
     360
     361
    311362        $upgrade_folder = $wp_filesystem->wp_content_dir() . 'upgrade/';
    312363
     
    533584        if ( is_wp_error( $source ) ) {
    534585            return $source;
     586
     587
     588
     589
     590
     591
     592
     593
     594
     595
    535596        }
    536597
     
    615676        }
    616677
    617         // Clear the working folder?
     678        // Clear the working ?
    618679        if ( $args['clear_working'] ) {
    619680            $wp_filesystem->delete( $remote_source, true );
     
    828889
    829890        $this->skin->set_result( $result );
     891
    830892        if ( is_wp_error( $result ) ) {
     893
     894
     895
     896
     897
     898
     899
     900
     901
     902
     903
    831904            $this->skin->error( $result );
    832905
     
    840913
    841914        $this->skin->after();
     915
     916
     917
     918
     919
     920
    842921
    843922        if ( ! $options['is_multi'] ) {
     
    9671046        return delete_option( $lock_name . '.lock' );
    9681047    }
     1048
     1049
     1050
     1051
     1052
     1053
     1054
     1055
     1056
     1057
     1058
     1059
     1060
     1061
     1062
     1063
     1064
     1065
     1066
     1067
     1068
     1069
     1070
     1071
     1072
     1073
     1074
     1075
     1076
     1077
     1078
     1079
     1080
     1081
     1082
     1083
     1084
     1085
     1086
     1087
     1088
     1089
     1090
     1091
     1092
     1093
     1094
     1095
     1096
     1097
     1098
     1099
     1100
     1101
     1102
     1103
     1104
     1105
     1106
     1107
     1108
     1109
     1110
     1111
     1112
     1113
     1114
     1115
     1116
     1117
     1118
     1119
     1120
     1121
     1122
     1123
     1124
     1125
     1126
     1127
     1128
     1129
     1130
     1131
     1132
     1133
     1134
     1135
     1136
     1137
     1138
     1139
     1140
     1141
     1142
     1143
     1144
     1145
     1146
     1147
     1148
     1149
     1150
     1151
     1152
     1153
     1154
     1155
     1156
     1157
     1158
     1159
     1160
     1161
     1162
     1163
     1164
     1165
     1166
     1167
     1168
     1169
     1170
     1171
     1172
     1173
     1174
     1175
     1176
     1177
     1178
     1179
     1180
     1181
     1182
     1183
     1184
     1185
     1186
     1187
     1188
     1189
     1190
     1191
     1192
     1193
     1194
     1195
     1196
     1197
     1198
     1199
     1200
     1201
     1202
     1203
     1204
     1205
     1206
     1207
     1208
     1209
     1210
     1211
    9691212}
    9701213
  • trunk/src/wp-includes/update.php

    r55641 r55720  
    10781078}
    10791079
     1080
     1081
     1082
     1083
     1084
     1085
     1086
     1087
     1088
     1089
     1090
     1091
     1092
     1093
     1094
     1095
     1096
     1097
     1098
     1099
     1100
     1101
     1102
     1103
     1104
     1105
     1106
     1107
     1108
     1109
     1110
     1111
     1112
     1113
     1114
     1115
     1116
     1117
     1118
     1119
     1120
     1121
     1122
     1123
     1124
     1125
     1126
     1127
     1128
     1129
     1130
     1131
     1132
     1133
     1134
     1135
    10801136if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) {
    10811137    return;
     
    11021158
    11031159add_action( 'init', 'wp_schedule_update_checks' );
     1160
     1161
Note: See TracChangeset for help on using the changeset viewer.