Upgrade/Install: Correct the weekly cron event for clearing the `temp-backup` directory:
* Make sure the `wp_delete_temp_updater_backups` event has an action associated with it when it runs. * Check if the cron event already exists before scheduling it, to avoid scheduling duplicate events. * Move the code for clearing the `temp-backup` directory to a standalone function. Follow-up to [51815], [51898], [51899]. Props pbiron, johnbillion. See #51857. Built from https://develop.svn.wordpress.org/trunk@52192 git-svn-id: http://core.svn.wordpress.org/trunk@51784 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
a9da3e2474
commit
8a5e1aa0b3
|
@ -150,8 +150,9 @@ class WP_Upgrader {
|
|||
* @since 5.9.0
|
||||
*/
|
||||
protected function schedule_temp_backup_cleanup() {
|
||||
wp_schedule_event( time(), 'weekly', 'delete_temp_updater_backups' );
|
||||
add_action( 'delete_temp_updater_backups', array( $this, 'delete_all_temp_backups' ) );
|
||||
if ( false === wp_next_scheduled( 'wp_delete_temp_updater_backups' ) ) {
|
||||
wp_schedule_event( time(), 'weekly', 'wp_delete_temp_updater_backups' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1107,51 +1108,6 @@ class WP_Upgrader {
|
|||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all contents of the temp-backup directory.
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
|
||||
*/
|
||||
public function delete_all_temp_backups() {
|
||||
/*
|
||||
* Check if there's a lock, or if currently performing an Ajax request,
|
||||
* in which case there's a chance we're doing an update.
|
||||
* Reschedule for an hour from now and exit early.
|
||||
*/
|
||||
if ( get_option( 'core_updater.lock' ) || get_option( 'auto_updater.lock' ) || wp_doing_ajax() ) {
|
||||
wp_schedule_single_event( time() + HOUR_IN_SECONDS, 'delete_temp_updater_backups' );
|
||||
return;
|
||||
}
|
||||
|
||||
add_action(
|
||||
'shutdown',
|
||||
/*
|
||||
* This action runs on shutdown to make sure there's no plugin updates currently running.
|
||||
* Using a closure in this case is OK since the action can be removed by removing the parent hook.
|
||||
*/
|
||||
function() {
|
||||
global $wp_filesystem;
|
||||
|
||||
if ( ! $wp_filesystem ) {
|
||||
include_once ABSPATH . '/wp-admin/includes/file.php';
|
||||
WP_Filesystem();
|
||||
}
|
||||
|
||||
$dirlist = $wp_filesystem->dirlist( $wp_filesystem->wp_content_dir() . 'upgrade/temp-backup/' );
|
||||
|
||||
foreach ( array_keys( $dirlist ) as $dir ) {
|
||||
if ( '.' === $dir || '..' === $dir ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$wp_filesystem->delete( $wp_filesystem->wp_content_dir() . 'upgrade/temp-backup/' . $dir, true );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/** Plugin_Upgrader class */
|
||||
|
|
|
@ -956,6 +956,51 @@ function wp_clean_update_cache() {
|
|||
delete_site_transient( 'update_core' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all contents of the temp-backup directory.
|
||||
*
|
||||
* @since 5.9.0
|
||||
*
|
||||
* @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass.
|
||||
*/
|
||||
function wp_delete_all_temp_backups() {
|
||||
/*
|
||||
* Check if there's a lock, or if currently performing an Ajax request,
|
||||
* in which case there's a chance we're doing an update.
|
||||
* Reschedule for an hour from now and exit early.
|
||||
*/
|
||||
if ( get_option( 'core_updater.lock' ) || get_option( 'auto_updater.lock' ) || wp_doing_ajax() ) {
|
||||
wp_schedule_single_event( time() + HOUR_IN_SECONDS, 'wp_delete_temp_updater_backups' );
|
||||
return;
|
||||
}
|
||||
|
||||
add_action(
|
||||
'shutdown',
|
||||
/*
|
||||
* This action runs on shutdown to make sure there's no plugin updates currently running.
|
||||
* Using a closure in this case is OK since the action can be removed by removing the parent hook.
|
||||
*/
|
||||
function() {
|
||||
global $wp_filesystem;
|
||||
|
||||
if ( ! $wp_filesystem ) {
|
||||
include_once ABSPATH . '/wp-admin/includes/file.php';
|
||||
WP_Filesystem();
|
||||
}
|
||||
|
||||
$dirlist = $wp_filesystem->dirlist( $wp_filesystem->wp_content_dir() . 'upgrade/temp-backup/' );
|
||||
|
||||
foreach ( array_keys( $dirlist ) as $dir ) {
|
||||
if ( '.' === $dir || '..' === $dir ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$wp_filesystem->delete( $wp_filesystem->wp_content_dir() . 'upgrade/temp-backup/' . $dir, true );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if ( ( ! is_main_site() && ! is_network_admin() ) || wp_doing_ajax() ) {
|
||||
return;
|
||||
}
|
||||
|
@ -980,3 +1025,5 @@ add_action( 'update_option_WPLANG', 'wp_clean_update_cache', 10, 0 );
|
|||
add_action( 'wp_maybe_auto_update', 'wp_maybe_auto_update' );
|
||||
|
||||
add_action( 'init', 'wp_schedule_update_checks' );
|
||||
|
||||
add_action( 'wp_delete_temp_updater_backups', 'wp_delete_all_temp_backups' );
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.9-alpha-52191';
|
||||
$wp_version = '5.9-alpha-52192';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue