-
Notifications
You must be signed in to change notification settings - Fork 156
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
Fix: Uninstall distributor #540
base: develop
Are you sure you want to change the base?
Conversation
Moving this to |
@peterwilsoncc, Can you provide a list of data we should remove when someone installs a plugin? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data deletion function will leave a bunch of caches in place for posts and post meta that doesn't exist, so we'll need to get the post IDs to be deleted, delete them and flush the caches. This is because the individual posts & post meta don't use the last changed time.
As distributor makes use of site options and site transients, we'll also need to delete the options differently depending on the type of install. Since WordPress 6.6 the autoloading of options depends on the options size, so we'll need to check for additional values to determine if the option is cached in all options or as an individual option.
As my suggested changes are quite a lot, I've put together a gist with the items split out in to multiple functions to allow for the cache to be deleted.
https://gist.github.com/peterwilsoncc/286025a3ca49b90c4d4f2e06741396a2
Warning
Please review my code carefully and check the queries generated.
Much of the code was written by Copilot so could do with some tidy-up, for one. Secondly, it uses some WPDB methods that are quite rare so it would be good to have a logic check
If you think deleting the options via the option ID will be faster (it's the primary key, then feel free to update the code to do so.
uninstall.php
Outdated
); | ||
|
||
// Flush the options cache. | ||
wp_cache_delete_multiple( $options_to_delete, 'options' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is being called with the option ID but the cache uses the option_name
uninstall.php
Outdated
); | ||
|
||
// Flush the site options cache. | ||
wp_cache_delete_multiple( $sitemeta_to_delete, 'site-options' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is using the option ID for the cache names, but it's cached using the pattern $network_id:$option_name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is using meta_id
from the sitemeta
table, do you mean we should pass $network_id:{sitemeta.meta_key}
? Where we can use sitemeta.site_id
as a $network_id
. So something like this?:
wp_cache_delete_multiple( [Array of {sitemeta.site_id:sitemeta.meta_key}], 'site-options' );
Co-authored-by: Peter Wilson <[email protected]>
@jeffpaul This still needs a little more from the previous review: fixing the options cache IDs, site options and adding the line phpcs notes for each line. |
Correct @peterwilsoncc This was dropped to pick some other work. I will drop a comment once this is ready for review. Thanks! |
@peterwilsoncc I've added a few commits and included a couple of questions for confirmation. Could you please take a look at #540 (comment) and #540 (comment)? |
@peterwilsoncc I’m now retrieving both the option IDs and names. IDs to delete the records, and names to clear the caches. For multisite, I’m using |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good but some odd behaviour when I try to delete the plugin
- the dist/css file can't be deleted.
- The database queries on a single site were failing. Not sure why.
To test I've been running the release script and unzipping and activating a duplicate copy to make sure I don't delete the git repo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File needs to be added to this block of code
distributor/webpack.config.release.js
Lines 11 to 29 in c27d99a
patterns: [ | |
{ from: 'readme.txt', to: './' }, | |
{ from: 'README.md', to: './' }, | |
{ from: 'CHANGELOG.md', to: './' }, | |
{ from: 'composer.json', to: './' }, | |
{ from: 'distributor.php', to: './' }, | |
{ from: '.github/workflows/*', to: './' }, | |
{ from: '.gitattributes', to: './' }, | |
{ from: 'assets/img/*', to: './' }, | |
{ from: 'dist/**/*', to: './' }, | |
{ from: 'includes/**/*', to: './' }, | |
{ from: 'lang/**/*', to: './' }, | |
{ from: 'templates/**/*', to: './' }, | |
{ | |
from: 'vendor/yahnis-elsts/plugin-update-checker/**/*', | |
to: './', | |
}, | |
], | |
} ), |
Hey @peterwilsoncc, I tested again on both a multisite network and a single site, but I didn’t encounter any odd behavior when deleting the plugin.
I also ran the release script and used the zip to test. Can you please check again? Or @qasumitbagthariya if you have some time to test this, that would be great. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@faisal-alvi Looks like it was file permission error between my local and virtual environments. Once I ran chmod it worked as expected.
@qasumitbagthariya over to you for QA |
Description of the Change
uninstall.php
script to delete distributor data from the database.DT_REMOVE_ALL_DATA
constant to prevent accidental data deletion.A modal will display when deactivating the plugin. This modal does not display in sub-sites.
Benefits
Delete distributor data on uninstalling.
Possible Drawbacks
n/a
Verification Process
Check the database manually.
Checklist:
Applicable Issues
Closes #349
Changelog Entry