-
Notifications
You must be signed in to change notification settings - Fork 1
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/55 Fix anonymize functionality from CLI #77
base: trunk
Are you sure you want to change the base?
Conversation
@bernattorras I'm running into an issue running the testing steps at point 9. Output:
|
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.
Great work! Left some comments on bits that jumped out at me.
includes/admin.php
Outdated
@@ -45,14 +44,14 @@ function enqueue_scripts( string $hook_suffix ) { | |||
return; | |||
} | |||
|
|||
wp_enqueue_script( 'safety-net-admin', SAFETY_NET_URL . 'assets/js/safety-net-admin.js', [ 'jquery' ], '1.0', true ); | |||
wp_enqueue_script( 'safety-net-admin', SAFETY_NET_URL . 'assets/js/safety-net-admin.js', array( 'jquery' ), '1.0', true ); |
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.
Could we tie asset version numbers to the plugin version, or maybe a constant defined in the main plugin file? Hard-coded version numbers may get forgotten.
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.
I'm not 100% sure which would be the best way to version this script... Linking it to the plugin version seems too strict (as I understand that minor changes could be applied without updating the plugin version number).
I kinda feel the same way about generic asset versioning...
For now, I've decided to use the filemtime
of the file. I know that this can generate false updates when using multiple servers though...
@tommusrhodus which approach would you recommend for this specific case?
function store_anonymized_user_data() { | ||
global $wpdb; | ||
|
||
$wpdb->query( "INSERT INTO $wpdb->users (SELECT * FROM {$wpdb->users}_temp WHERE id NOT IN (SELECT ID FROM $wpdb->users))" ); |
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.
Error handling needed for non-standard table that might not exist.
WP_CLI::confirm( 'Are you sure you want to do this?' ); | ||
|
||
WP_CLI::log( '- Copying users to temporary tables ...' ); | ||
copy_and_clear_user_tables(); |
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.
Do any of these functions return data that could be shown to the user? e.g error handling, success message, count of changes rows etc?
} ?> | ||
|
||
<?php if ( 'checkbox' === $args['type'] ) : | ||
<?php |
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.
Closing and opening PHP tags aren't needed here.
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.
^ nitpicking 🤣
anonymize_users(); | ||
|
||
WP_CLI::log( '- Storing the anonymized users to the default tables ... ' ); | ||
store_anonymized_user_data(); |
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.
Each of these steps definitely needs some more verbosity. A nice success message if everything goes to plan, and a detailed error output if not ideally.
Description of the issue
In #55 we decided to remove the anonymization functionality from the plugin, leaving only the CLI command to anonymize the users, orders, and customers.
When I tried the
wp safety-net anonymize
CLI command it got stuck and didn't anonymize any user data.After taking a look at it, I've found that the problem was that the temporary tables weren't being used for copying, processing and storing the user details. These DB operations were only used for the background processes (which the CLI isn't using).
Changes proposed in this PR
Steps to test
wp user generate 100
)wp safety-net anonymize
command[It should get stuck without anonymizing any user]
wp safety-net anonymize
command againn
.y
.Notes
wp_ajax_safety_net_anonymize_users
hook (not needed since this functionality was removed from the admin in Added actions toggle, removed anonymize #62.includes/amin.php
to fix some phpcs issues (mostly related to shorthand syntax)Fixes #55