site-kit-wp: Reset infinite loop

Bug Description

When trying to reset Site Kit either on the setup screen or via wp google-site-kit reset, nothing happens. It’s just stuck.

Steps to reproduce

  1. Try to reset Site Kit
  2. Wait forever

Additional Context

  • PHP Version: 7.2
  • Server: nginx, with Memcached object cache dropin
  • Browser: Chrome on macOS
  • Plugin Version 1.0.1

Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • Ensure that reset and uninstall are working correctly, and optimize them to consume less memory & time.

Implementation Brief

  • To ensure there are no side effects for uninstallation, let’s replace our uninstall hook with an uninstall.php file. This file should then include the new reset/uninstall logic (see below), with the following condition at the top:
    if ( ! defined( WP_UNINSTALL_PLUGIN ) && empty( $googlesitekit_reset ) ) {
    	return;
    }
    
  • Then, in the Reset::all(), set a $googlesitekit_reset variable to true and require the uninstall.php file.
  • Instead of the other private methods in Reset, the uninstall.php file should include simple and optimized DB queries using $wpdb which delete the data in a more efficient way:
    • $wpdb->query( $wpdb->prepare( "DELETE * from {$wpdb->options} WHERE option_name LIKE %s OR option_name LIKE %s OR option_name LIKE %s", $prefix, '_transient_' . $prefix, '_transient_timeout_' . $prefix ) )
    • $wpdb->query( $wpdb->prepare( "DELETE * from {$wpdb->usermeta} WHERE meta_key LIKE %s", $user_prefix ) )
    • The $prefix should be googlesitekit_% and the $user_prefix should be $context->is_network_mode() ? $prefix : $wpdb->get_blog_prefix() . $prefix.
    • To setup a Context class instance (for the above check), the file should check if the class does not exist, and if so load the file manually. It can then create an instance of it.
  • After the DB queries, the file should call wp_cache_flush().

Changelog entry

  • Fix reset and uninstall data removal by optimizing database queries.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (5 by maintainers)

Most upvoted comments

Will do more testing this week. @swissspidy stop checking your work emails during your vacation 😉

On Sun, Nov 17, 2019 at 10:38 PM Pascal Birchler notifications@github.com wrote:

As previously mentioned I‘ll have to test again after my vacation. Since it might be specific to my setup, I am still happy with it being closed for now.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/google/site-kit-wp/issues/809?email_source=notifications&email_token=AA3KLWQSBT2CTTCGOYSIXDDQUG2V7A5CNFSM4JKELIF2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEEIW2HY#issuecomment-554790175, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA3KLWWWZJZ4QFFYSHGMZULQUG2V7ANCNFSM4JKELIFQ .

[image: Google Logo] Thierry Muller Developer Relations Program Manager Engineering - News & Content Ecosystem thierrymuller@google.com