10up / wpsnapshots

(DEPRECATED) A project sharing tool for WordPress.
MIT License
215 stars 22 forks source link

Use the correct user table names when on multisite #66

Closed felipeelia closed 3 years ago

felipeelia commented 3 years ago

Description of the Change

Multisite: User and User Meta Table Names

This PR changes the way we are generating the wp_users and wp_usermeta table names. Instead of $GLOBALS['table_prefix'] . 'users' the code would use $wpdb->users. As table_prefix varies in multisite installations depending on the main blog, this seems to a safer way to identify the correct table name.

Multisite: Table Names

I don't know if I got an edge case but the script wasn't finding all tables, just the tables related to the main blog (that was not the original main one). Changing $GLOBALS['table_prefix'] to $wpdb->base_prefix we can get all tables with the "original" prefix set in the wp-config.php file.

As stated in the $wpdb documentation here:

$base_prefix — The original prefix as defined in wp-config.php. For multi-site: Use if you want to get the prefix without the blog number appended.

Column Statistics

Again, I don't know if it was a misconfiguration of my part but I ran into an Unknown table 'COLUMN_STATISTICS' in information_schema error. Adding --column-statistics=0 to all mysqldump calls fixed the issue.

More info in this Server Fault question.

Tablespaces

As per cbfa791, this PR also fixes the mysqldump: Error: 'Access denied; you need (at least one of) the PROCESS privilege(s) for this operation' when trying to dump tablespaces errors adding a --no-tablespaces parameter to the mysqldump calls.

Data Escape

As related on #64, there is a lack of escaping in the current code. Commit f7f75cd tries to fix it.

Alternate Designs

I'm open to suggestions.

Benefits

WP Snapshots working good with multi-sites that changed the main blog id :)

Possible Drawbacks

n/a

Verification Process

I've cloned the repository locally and changed it as needed to generate a snapshot for my project.

Checklist:

Applicable Issues

Fixes #65 and #64

Changelog Entry

Fixed user scrubbing on multisites.

tlovett1 commented 3 years ago

This looks solid @felipeelia !