Skip to content

Deactivating/Uninstalling BC4WP leaves stale database entries, which affect subsequent reinstallations #481

@bc-erich

Description

@bc-erich

Detailed Description
When the BC4WP plugin is installed and onboarded in Wordpress, it creates entries in several different tables in the Wordpress database. When it's uninstalled, it removes some of these entries, but not all of them. Some of the remaining entries reference the old channel, old products, old options, old images, etc. After reinstalling the plugin, If it is not connected to the same channel with the same products/options, then sync problems will occur.

Uninstalling and reinstalling the plugin is a frequent troubleshooting suggestion from support teams, so this could potentially be a widespread issue, especially if a merchant creates a new channel to "start fresh" during the reinstall process.

Steps to Reproduce
Install the BC4WP plugin in a fresh WP instance

Connect to a store and sync products

Uninstall the plugin

Use any method of SQL access, such as the phpMyadmin WP plugin to view the WP database, and run queries like the following:
SELECT * FROM wp_options where option_name LIKE '%bigcommerce%'

See that entries still exist for bigcommerce even though the plugin has been removed

*See workaround section below for full list of tables and criteria where these stale entries can be found

Expected Result
BC4WP uninstallation clears all database entries that might affect future installations

Actual Result
BC4WP uninstallation leaves some database entries

Workaround or possible solution
Give the user the option of wiping the database if they plan on connecting to a new channel.

Run the following DELETE queries in the WP database after BC4WP uninstallation and before reinstallation.
NOTE: this assumes the database is named "wordpress". This is the default name for most standard installations, but the database name could be different depending on circumstances.

remove options:
DELETE FROM wordpress.wp_options where option_name LIKE '%bigcommerce%'

remove posts:
DELETE wordpress.wp_posts.* FROM wordpress.wp_posts INNER JOIN wordpress.wp_postmeta ON wp_posts.id=wp_postmeta.post_id
where (post_title like '%source%' and post_type='attachment')
OR post_content LIKE '[bigcommerce%'
OR wp_postmeta.meta_value LIKE '%bigcommerce%'
OR post_type='bigcommerce_sync_log'

remove orphaned post meta:
DELETE wordpress.wp_postmeta.* FROM wordpress.wp_postmeta LEFT JOIN wordpress.wp_posts ON wp_posts.id=wp_postmeta.post_id where wp_posts.id is null

remove terms:
DELETE wordpress.wp_terms.*
FROM wordpress.wp_terms
INNER JOIN wordpress.wp_termmeta ON wp_terms.term_id=wp_termmeta.term_id
LEFT JOIN wordpress.wp_term_taxonomy ON wp_terms.term_id=wp_term_taxonomy.term_id
WHERE wp_termmeta.meta_key LIKE 'bigcommerce_%'
OR wp_term_taxonomy.taxonomy LIKE 'bigcommerce_%'

remove orphaned terms meta:
DELETE wordpress.wp_termmeta.*
FROM wordpress.wp_termmeta LEFT JOIN wordpress.wp_terms ON wp_terms.term_id=wp_termmeta.term_id
WHERE wp_terms.term_id is null

remove orphaned terms taxonomy:
DELETE wordpress.wp_term_taxonomy.*
FROM wordpress.wp_term_taxonomy LEFT JOIN wordpress.wp_terms ON wp_terms.term_id=wp_term_taxonomy.term_id
WHERE wp_terms.term_id is null

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions