Make WordPress Core

Changeset 52351


Ignore:
Timestamp:
12/10/2021 12:04:03 AM (2 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.

Location:
trunk/src
Files:
6 edited

Legend:

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

    r51815 r52351  
    227227                'clear_working'     => true,
    228228                'hook_extra'        => array(
    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                     ),
     229                    'plugin' => $plugin,
     230                    'type'   => 'plugin',
     231                    'action' => 'update',
    237232                ),
    238233            )
     
    348343                    'is_multi'          => true,
    349344                    'hook_extra'        => array(
    350                         'plugin'      => $plugin,
    351                         'temp_backup' => array(
    352                             'slug' => dirname( $plugin ),
    353                             'src'  => WP_PLUGIN_DIR,
    354                             'dir'  => 'plugins',
    355                         ),
     345                        'plugin' => $plugin,
    356346                    ),
    357347                )
  • trunk/src/wp-admin/includes/class-theme-upgrader.php

    r51815 r52351  
    329329                'clear_working'     => true,
    330330                'hook_extra'        => array(
    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                     ),
     331                    'theme'  => $theme,
     332                    'type'   => 'theme',
     333                    'action' => 'update',
    339334                ),
    340335            )
     
    449444                    'is_multi'          => true,
    450445                    'hook_extra'        => array(
    451                         'theme'       => $theme,
    452                         'temp_backup' => array(
    453                             'slug' => $theme,
    454                             'src'  => get_theme_root( $theme ),
    455                             'dir'  => 'themes',
    456                         ),
     446                        'theme' => $theme,
    457447                    ),
    458448                )
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r51979 r52351  
    18841884
    18851885    /**
    1886      * Test available disk space for updates.
    1887      *
    1888      * @since 5.9.0
    1889      *
    1890      * @return array The test results.
    1891      */
    1892     public function get_test_available_updates_disk_space() {
    1893         $available_space       = function_exists( 'disk_free_space' ) ? (int) @disk_free_space( WP_CONTENT_DIR . '/upgrade/' ) : 0;
    1894         $available_space_in_mb = $available_space / MB_IN_BYTES;
    1895 
    1896         $result = array(
    1897             'label'       => __( 'Disk space available to safely perform updates' ),
    1898             'status'      => 'good',
    1899             'badge'       => array(
    1900                 'label' => __( 'Security' ),
    1901                 'color' => 'blue',
    1902             ),
    1903             'description' => sprintf(
    1904                 /* translators: %s: Available disk space in MB or GB. */
    1905                 '<p>' . __( '%s available disk space was detected, update routines can be performed safely.' ),
    1906                 size_format( $available_space )
    1907             ),
    1908             'actions'     => '',
    1909             'test'        => 'available_updates_disk_space',
    1910         );
    1911 
    1912         if ( $available_space_in_mb < 100 ) {
    1913             $result['description'] = __( 'Available disk space is low, less than 100 MB available.' );
    1914             $result['status']      = 'recommended';
    1915         }
    1916 
    1917         if ( $available_space_in_mb < 20 ) {
    1918             $result['description'] = __( 'Available disk space is critically low, less than 20 MB available. Proceed with caution, updates may fail.' );
    1919             $result['status']      = 'critical';
    1920         }
    1921 
    1922         if ( ! $available_space ) {
    1923             $result['description'] = __( 'Could not determine available disk space for updates.' );
    1924             $result['status']      = 'recommended';
    1925         }
    1926 
    1927         return $result;
    1928     }
    1929 
    1930     /**
    1931      * Test if plugin and theme updates temp-backup directories are writable or can be created.
    1932      *
    1933      * @since 5.9.0
    1934      *
    1935      * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
    1936      *
    1937      * @return array The test results.
    1938      */
    1939     public function get_test_update_temp_backup_writable() {
    1940         global $wp_filesystem;
    1941 
    1942         $result = array(
    1943             'label'       => sprintf(
    1944                 /* translators: %s: temp-backup */
    1945                 __( 'Plugin and theme update %s directory is writable' ),
    1946                 'temp-backup'
    1947             ),
    1948             'status'      => 'good',
    1949             'badge'       => array(
    1950                 'label' => __( 'Security' ),
    1951                 'color' => 'blue',
    1952             ),
    1953             'description' => sprintf(
    1954                 /* translators: %s: wp-content/upgrade/temp-backup */
    1955                 '<p>' . __( 'The %s directory used to improve the stability of plugin and theme updates is writable.' ),
    1956                 '<code>wp-content/upgrade/temp-backup</code>'
    1957             ),
    1958             'actions'     => '',
    1959             'test'        => 'update_temp_backup_writable',
    1960         );
    1961 
    1962         if ( ! $wp_filesystem ) {
    1963             if ( ! function_exists( 'WP_Filesystem' ) ) {
    1964                 require_once wp_normalize_path( ABSPATH . '/wp-admin/includes/file.php' );
    1965             }
    1966             WP_Filesystem();
    1967         }
    1968         $wp_content = $wp_filesystem->wp_content_dir();
    1969 
    1970         $upgrade_dir_exists      = $wp_filesystem->is_dir( "$wp_content/upgrade" );
    1971         $upgrade_dir_is_writable = $wp_filesystem->is_writable( "$wp_content/upgrade" );
    1972         $backup_dir_exists       = $wp_filesystem->is_dir( "$wp_content/upgrade/temp-backup" );
    1973         $backup_dir_is_writable  = $wp_filesystem->is_writable( "$wp_content/upgrade/temp-backup" );
    1974 
    1975         $plugins_dir_exists      = $wp_filesystem->is_dir( "$wp_content/upgrade/temp-backup/plugins" );
    1976         $plugins_dir_is_writable = $wp_filesystem->is_writable( "$wp_content/upgrade/temp-backup/plugins" );
    1977         $themes_dir_exists       = $wp_filesystem->is_dir( "$wp_content/upgrade/temp-backup/themes" );
    1978         $themes_dir_is_writable  = $wp_filesystem->is_writable( "$wp_content/upgrade/temp-backup/themes" );
    1979 
    1980         if ( $plugins_dir_exists && ! $plugins_dir_is_writable && $themes_dir_exists && ! $themes_dir_is_writable ) {
    1981             $result['status'] = 'critical';
    1982             $result['label']  = sprintf(
    1983                 /* translators: %s: temp-backup */
    1984                 __( 'Plugins and themes %s directories exist but are not writable' ),
    1985                 'temp-backup'
    1986             );
    1987             $result['description'] = sprintf(
    1988                 /* translators: 1: wp-content/upgrade/temp-backup/plugins, 2: wp-content/upgrade/temp-backup/themes. */
    1989                 '<p>' . __( 'The %1$s and %2$s directories exist but are not writable. These directories are used to improve the stability of plugin updates. Please make sure the server has write permissions to these directories.' ) . '</p>',
    1990                 '<code>wp-content/upgrade/temp-backup/plugins</code>',
    1991                 '<code>wp-content/upgrade/temp-backup/themes</code>'
    1992             );
    1993             return $result;
    1994         }
    1995 
    1996         if ( $plugins_dir_exists && ! $plugins_dir_is_writable ) {
    1997             $result['status'] = 'critical';
    1998             $result['label']  = sprintf(
    1999                 /* translators: %s: temp-backup */
    2000                 __( 'Plugins %s directory exists but is not writable' ),
    2001                 'temp-backup'
    2002             );
    2003             $result['description'] = sprintf(
    2004                 /* translators: %s: wp-content/upgrade/temp-backup/plugins */
    2005                 '<p>' . __( 'The %s directory exists but is not writable. This directory is used to improve the stability of plugin updates. Please make sure the server has write permissions to this directory.' ) . '</p>',
    2006                 '<code>wp-content/upgrade/temp-backup/plugins</code>'
    2007             );
    2008             return $result;
    2009         }
    2010 
    2011         if ( $themes_dir_exists && ! $themes_dir_is_writable ) {
    2012             $result['status'] = 'critical';
    2013             $result['label']  = sprintf(
    2014                 /* translators: %s: temp-backup */
    2015                 __( 'Themes %s directory exists but is not writable' ),
    2016                 'temp-backup'
    2017             );
    2018             $result['description'] = sprintf(
    2019                 /* translators: %s: wp-content/upgrade/temp-backup/themes */
    2020                 '<p>' . __( 'The %s directory exists but is not writable. This directory is used to improve the stability of theme updates. Please make sure the server has write permissions to this directory.' ) . '</p>',
    2021                 '<code>wp-content/upgrade/temp-backup/themes</code>'
    2022             );
    2023             return $result;
    2024         }
    2025 
    2026         if ( ( ! $plugins_dir_exists || ! $themes_dir_exists ) && $backup_dir_exists && ! $backup_dir_is_writable ) {
    2027             $result['status'] = 'critical';
    2028             $result['label']  = sprintf(
    2029                 /* translators: %s: temp-backup */
    2030                 __( 'The %s directory exists but is not writable' ),
    2031                 'temp-backup'
    2032             );
    2033             $result['description'] = sprintf(
    2034                 /* translators: %s: wp-content/upgrade/temp-backup */
    2035                 '<p>' . __( 'The %s directory exists but is not writable. This directory is used to improve the stability of plugin and theme updates. Please make sure the server has write permissions to this directory.' ) . '</p>',
    2036                 '<code>wp-content/upgrade/temp-backup</code>'
    2037             );
    2038             return $result;
    2039         }
    2040 
    2041         if ( ! $backup_dir_exists && $upgrade_dir_exists && ! $upgrade_dir_is_writable ) {
    2042             $result['status'] = 'critical';
    2043             $result['label']  = sprintf(
    2044                 /* translators: %s: upgrade */
    2045                 __( 'The %s directory exists but is not writable' ),
    2046                 'upgrade'
    2047             );
    2048             $result['description'] = sprintf(
    2049                 /* translators: %s: wp-content/upgrade */
    2050                 '<p>' . __( 'The %s directory exists but is not writable. This directory is used for plugin and theme updates. Please make sure the server has write permissions to this directory.' ) . '</p>',
    2051                 '<code>wp-content/upgrade</code>'
    2052             );
    2053             return $result;
    2054         }
    2055 
    2056         if ( ! $upgrade_dir_exists && ! $wp_filesystem->is_writable( $wp_content ) ) {
    2057             $result['status'] = 'critical';
    2058             $result['label']  = sprintf(
    2059                 /* translators: %s: upgrade */
    2060                 __( 'The %s directory cannot be created' ),
    2061                 'upgrade'
    2062             );
    2063             $result['description'] = sprintf(
    2064                 /* translators: 1: wp-content/upgrade, 2: wp-content. */
    2065                 '<p>' . __( 'The %1$s directory does not exist, and the server does not have write permissions in %2$s to create it. This directory is used for plugin and theme updates. Please make sure the server has write permissions in %2$s.' ) . '</p>',
    2066                 '<code>wp-content/upgrade</code>',
    2067                 '<code>wp-content</code>'
    2068             );
    2069             return $result;
    2070         }
    2071 
    2072         return $result;
    2073     }
    2074 
    2075     /**
    20761886     * Test if loopbacks work as expected.
    20771887     *
     
    24572267        $tests = array(
    24582268            'direct' => array(
    2459                 'wordpress_version'            => array(
     2269                'wordpress_version'         => array(
    24602270                    'label' => __( 'WordPress Version' ),
    24612271                    'test'  => 'wordpress_version',
    24622272                ),
    2463                 'plugin_version'               => array(
     2273                'plugin_version'            => array(
    24642274                    'label' => __( 'Plugin Versions' ),
    24652275                    'test'  => 'plugin_version',
    24662276                ),
    2467                 'theme_version'                => array(
     2277                'theme_version'             => array(
    24682278                    'label' => __( 'Theme Versions' ),
    24692279                    'test'  => 'theme_version',
    24702280                ),
    2471                 'php_version'                  => array(
     2281                'php_version'               => array(
    24722282                    'label' => __( 'PHP Version' ),
    24732283                    'test'  => 'php_version',
    24742284                ),
    2475                 'php_extensions'               => array(
     2285                'php_extensions'            => array(
    24762286                    'label' => __( 'PHP Extensions' ),
    24772287                    'test'  => 'php_extensions',
    24782288                ),
    2479                 'php_default_timezone'         => array(
     2289                'php_default_timezone'      => array(
    24802290                    'label' => __( 'PHP Default Timezone' ),
    24812291                    'test'  => 'php_default_timezone',
    24822292                ),
    2483                 'php_sessions'                 => array(
     2293                'php_sessions'              => array(
    24842294                    'label' => __( 'PHP Sessions' ),
    24852295                    'test'  => 'php_sessions',
    24862296                ),
    2487                 'sql_server'                   => array(
     2297                'sql_server'                => array(
    24882298                    'label' => __( 'Database Server version' ),
    24892299                    'test'  => 'sql_server',
    24902300                ),
    2491                 'utf8mb4_support'              => array(
     2301                'utf8mb4_support'           => array(
    24922302                    'label' => __( 'MySQL utf8mb4 support' ),
    24932303                    'test'  => 'utf8mb4_support',
    24942304                ),
    2495                 'ssl_support'                  => array(
     2305                'ssl_support'               => array(
    24962306                    'label' => __( 'Secure communication' ),
    24972307                    'test'  => 'ssl_support',
    24982308                ),
    2499                 'scheduled_events'             => array(
     2309                'scheduled_events'          => array(
    25002310                    'label' => __( 'Scheduled events' ),
    25012311                    'test'  => 'scheduled_events',
    25022312                ),
    2503                 'http_requests'                => array(
     2313                'http_requests'             => array(
    25042314                    'label' => __( 'HTTP Requests' ),
    25052315                    'test'  => 'http_requests',
    25062316                ),
    2507                 'rest_availability'            => array(
     2317                'rest_availability'         => array(
    25082318                    'label'     => __( 'REST API availability' ),
    25092319                    'test'      => 'rest_availability',
    25102320                    'skip_cron' => true,
    25112321                ),
    2512                 'debug_enabled'                => array(
     2322                'debug_enabled'             => array(
    25132323                    'label' => __( 'Debugging enabled' ),
    25142324                    'test'  => 'is_in_debug_mode',
    25152325                ),
    2516                 'file_uploads'                 => array(
     2326                'file_uploads'              => array(
    25172327                    'label' => __( 'File uploads' ),
    25182328                    'test'  => 'file_uploads',
    25192329                ),
    2520                 'plugin_theme_auto_updates'    => array(
     2330                'plugin_theme_auto_updates' => array(
    25212331                    'label' => __( 'Plugin and theme auto-updates' ),
    25222332                    'test'  => 'plugin_theme_auto_updates',
    2523                 ),
    2524                 'update_temp_backup_writable'  => array(
    2525                     /* translators: %s: temp-backup */
    2526                     'label' => sprintf( __( 'Updates %s directory access' ), 'temp-backup' ),
    2527                     'test'  => 'update_temp_backup_writable',
    2528                 ),
    2529                 'available_updates_disk_space' => array(
    2530                     'label' => __( 'Available disk space' ),
    2531                     'test'  => 'available_updates_disk_space',
    25322333                ),
    25332334            ),
  • 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&#8230;' );
    186168        $this->strings['maintenance_end']   = __( 'Disabling Maintenance mode&#8230;' );
    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
  • trunk/src/wp-admin/includes/file.php

    r52289 r52351  
    19451945
    19461946/**
    1947  * Moves a directory from one location to another via the rename() PHP function.
    1948  * If the renaming failed, falls back to copy_dir().
    1949  *
    1950  * Assumes that WP_Filesystem() has already been called and setup.
    1951  *
    1952  * @since 5.9.0
    1953  *
    1954  * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
    1955  *
    1956  * @param string $from        Source directory.
    1957  * @param string $to          Destination directory.
    1958  * @param string $working_dir Optional. Remote file source directory.
    1959  *                            Default empty string.
    1960  * @return true|WP_Error True on success, WP_Error on failure.
    1961  */
    1962 function move_dir( $from, $to, $working_dir = '' ) {
    1963     global $wp_filesystem;
    1964 
    1965     if ( 'direct' === $wp_filesystem->method ) {
    1966         $wp_filesystem->rmdir( $to );
    1967         if ( @rename( $from, $to ) ) {
    1968             return true;
    1969         }
    1970     }
    1971 
    1972     if ( ! $wp_filesystem->is_dir( $to ) ) {
    1973         if ( ! $wp_filesystem->mkdir( $to, FS_CHMOD_DIR ) ) {
    1974 
    1975             // Clear the working directory?
    1976             if ( ! empty( $working_dir ) ) {
    1977                 $wp_filesystem->delete( $working_dir, true );
    1978             }
    1979 
    1980             return new WP_Error( 'mkdir_failed_move_dir', __( 'Could not create directory.' ), $to );
    1981         }
    1982     }
    1983     $result = copy_dir( $from, $to );
    1984 
    1985     // Clear the working directory?
    1986     if ( ! empty( $working_dir ) ) {
    1987         $wp_filesystem->delete( $working_dir, true );
    1988     }
    1989 
    1990     return $result;
    1991 }
    1992 
    1993 /**
    19941947 * Initializes and connects the WordPress Filesystem Abstraction classes.
    19951948 *
  • trunk/src/wp-includes/update.php

    r52192 r52351  
    957957}
    958958
    959 /**
    960  * Deletes all contents of the temp-backup directory.
    961  *
    962  * @since 5.9.0
    963  *
    964  * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
    965  */
    966 function wp_delete_all_temp_backups() {
    967     /*
    968      * Check if there's a lock, or if currently performing an Ajax request,
    969      * in which case there's a chance we're doing an update.
    970      * Reschedule for an hour from now and exit early.
    971      */
    972     if ( get_option( 'core_updater.lock' ) || get_option( 'auto_updater.lock' ) || wp_doing_ajax() ) {
    973         wp_schedule_single_event( time() + HOUR_IN_SECONDS, 'wp_delete_temp_updater_backups' );
    974         return;
    975     }
    976 
    977     add_action(
    978         'shutdown',
    979         /*
    980          * This action runs on shutdown to make sure there's no plugin updates currently running.
    981          * Using a closure in this case is OK since the action can be removed by removing the parent hook.
    982          */
    983         function() {
    984             global $wp_filesystem;
    985 
    986             if ( ! $wp_filesystem ) {
    987                 include_once ABSPATH . '/wp-admin/includes/file.php';
    988                 WP_Filesystem();
    989             }
    990 
    991             $dirlist = $wp_filesystem->dirlist( $wp_filesystem->wp_content_dir() . 'upgrade/temp-backup/' );
    992 
    993             foreach ( array_keys( $dirlist ) as $dir ) {
    994                 if ( '.' === $dir || '..' === $dir ) {
    995                     continue;
    996                 }
    997 
    998                 $wp_filesystem->delete( $wp_filesystem->wp_content_dir() . 'upgrade/temp-backup/' . $dir, true );
    999             }
    1000         }
    1001     );
    1002 }
    1003 
    1004959if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) {
    1005960    return;
     
    1026981
    1027982add_action( 'init', 'wp_schedule_update_checks' );
    1028 
    1029 add_action( 'wp_delete_temp_updater_backups', 'wp_delete_all_temp_backups' );
Note: See TracChangeset for help on using the changeset viewer.