Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Way to delete old core files after core update #141

Open
1 task done
wojsmol opened this issue Nov 13, 2019 · 5 comments
Open
1 task done

Way to delete old core files after core update #141

wojsmol opened this issue Nov 13, 2019 · 5 comments

Comments

@wojsmol
Copy link
Contributor

wojsmol commented Nov 13, 2019

Feature Request

Describe your use case and the problem you are facing
Currently there is no way to delete old core files if during the update checksums for target WP version and locale aren't available.
Describe the solution you'd like
Command or a flag to delete old core files.
A clear and concise description of what you want to happen.
A way to delete old core files after core update exists.

@schlessera
Copy link
Member

WP-CLI currently diffs the old checksums against the new checksums to decide what left-overs to purge in

private function cleanup_extra_files( $version_from, $version_to, $locale ) {
if ( ! $version_from || ! $version_to ) {
WP_CLI::warning( 'Failed to find WordPress version. Please cleanup files manually.' );
return;
}
$old_checksums = self::get_core_checksums( $version_from, $locale ?: 'en_US' );
if ( ! is_array( $old_checksums ) ) {
WP_CLI::warning( "{$old_checksums} Please cleanup files manually." );
return;
}
$new_checksums = self::get_core_checksums( $version_to, $locale ?: 'en_US' );
if ( ! is_array( $new_checksums ) ) {
WP_CLI::warning( "{$new_checksums} Please cleanup files manually." );
return;
}
$files_to_remove = array_diff( array_keys( $old_checksums ), array_keys( $new_checksums ) );
if ( ! empty( $files_to_remove ) ) {
WP_CLI::log( 'Cleaning up files...' );
$count = 0;
foreach ( $files_to_remove as $file ) {
// wp-content should be considered user data
if ( 0 === stripos( $file, 'wp-content' ) ) {
continue;
}
if ( file_exists( ABSPATH . $file ) ) {
unlink( ABSPATH . $file );
WP_CLI::log( "File removed: {$file}" );
$count++;
}
}
if ( $count ) {
WP_CLI::log( number_format( $count ) . ' files cleaned up.' );
} else {
WP_CLI::log( 'No files found that need cleaning up.' );
}
}
}

However, for combinations of locales & versions that we don't have checksums available, this just fails with a message that cleaning up by hand is required.

However, WordPress provides a list of files that are supposed to be deleted and deletes them by default on update: https://github.com/WordPress/wordpress-develop/blob/a216b6d83845dc4cdd01ff517cdf36b72043b6b3/src/wp-admin/includes/update-core.php#L20-L791

We should combine this data with the checksums, to use the checksums to only delete old files when they have not been modified, and to unconditionally delete old files when we don't have checksums to verify for modifications.

@Aaron-Ritter
Copy link

I assume my problem goes in the same direction Warning: Checksums not available for WordPress 5.9/de_DE. Please cleanup files manually. Is this still something to be considered fixing as the issue is open since 2 years?

@wojsmol
Copy link
Contributor Author

wojsmol commented Jan 25, 2022

@Aaron-Ritter Message posted by you is caused by the same issue. AFAIK the issue is still considered to be fixed.

@Aaron-Ritter
Copy link

thanks @wojsmol at least that confirms my finding :) I was wondering if there is an alternative solutions, the Wordpress Updates are in the meantime often scheduled for fully automatic upgrades too, so maybe I could trigger that particular job through wp cli instead avoiding the wp core update all together.

@schlessera
Copy link
Member

@Aaron-Ritter This is indeed still an issue. The latest update for this is that release 5.9 showed that the WordPress update process is broken as well and will be rethought for 6.0. Hopefully, that rethinking can also include WP-CLI-usable logic that just works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants