Last active
December 16, 2015 02:49
-
-
Save technosailor/5365754 to your computer and use it in GitHub Desktop.
When moving a WordPress Multisite blog to a standalone WordPress install that will then be converted to Multisite with new subsites... we can't have users having capabilities and other usermeta that are iodentified for a particular blog id that will change in the future. So this monstrosity selects everything except options that are prefixed wp_…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE | |
VIEW v AS | |
SELECT DISTINCT(meta_key) | |
FROM wp_usermeta | |
WHERE NOT( meta_key REGEXP '^wp_5_{1}') | |
AND (meta_key REGEXP '^wp_(.)+'); | |
DELETE FROM wp_usermeta | |
WHERE meta_key IN | |
(SELECT * FROM v); | |
UPDATE wp_usermeta | |
SET meta_key = REPLACE( | |
meta_key, | |
'wp_5_', | |
'wp_' | |
); | |
DROP VIEW v; | |
DROP TABLE IF EXISTS | |
wp_commentmeta, | |
wp_comments, | |
wp_links, | |
wp_options, | |
wp_popularpostsdata, | |
wp_popularpostscache, | |
wp_postmeta, | |
wp_posts, | |
wp_term_relationships, | |
wp_term_taxonomy, | |
wp_terms; | |
RENAME TABLE | |
wp_5_commentmeta TO wp_commentmeta, | |
wp_5_links TO wp_links, | |
wp_5_comments TO wp_comments, | |
wp_5_options TO wp_options, | |
wp_5_popularpostsdata TO wp_popularpostsdata, | |
wp_5_popularpostsdatacache TO wp_popularpostsdatacache, | |
wp_5_postmeta TO wp_postmeta, | |
wp_5_posts TO wp_posts, | |
wp_5_term_relationships to wp_term_relationships, | |
wp_5_term_taxonomy TO wp_term_taxonomy, | |
wp_5_terms TO wp_terms; | |
UPDATE wp_options SET | |
option_name = REPLACE( | |
option_name, | |
'wp_5_', | |
'wp_' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment