Skip to content
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

CMB2 data messed up after migration because full file url containing old domain is stored in serialized array. #1476

Open
InstrukturRGI opened this issue Dec 6, 2022 · 2 comments

Comments

@InstrukturRGI
Copy link

Is your feature request related to a problem? Please describe.
I recently moved my website to another domain and found out that during the migration process, CMB2 data which is stored as serialized array in prefix_options table got messed up. Mainly for things related to field type "file" and "file_list" because those fields keep the entire file URLs (containing old domain) inside the serialized array, and when I'm replacing every instances of $old_url with $new_url in my database, I broke the serialized array because the number of characters failed to match now.

If CMB2 actually has 'proper' method for domain migration and I missed it, I apologize.

Describe the solution you'd like
Limit "file" and "file_list" to the wp's library maybe? so the only data stored inside the serialized string is the attachment id, without any mention of the site's domain, thus avoiding this entire debacle.
Then add another field type specifically for external file(s). or simply use 'text_url', but the file preview feature is too good to let go.

Describe alternatives you've considered
I was lucky because there aren't really a lot of CMB2 options saved in my site, so I simply re-input them manually, so brute-forcing is still an option.
I'm just throwing idea here... but how about replacing instances of domain name with shortcode? It feels doable but, I'm not too sure about it...

Additional context
here's an example of the difference of data before and after replacing instances of old_url with new_url:

$old = 'a:2:{s:12:"test_file_id";s:2:"41";s:9:"test_file";s:63:"https://old-domain.com/wp-content/uploads/2022/11/TRIXIE-3.webp";}';
$new = 'a:2:{s:12:"test_file_id";s:2:"41";s:9:"test_file";s:63:"https://brandnew-domain.com/wp-content/uploads/2022/11/TRIXIE-3.webp";}';

the new serialized string is broken because number of characters for file URL mismatched.

@tw2113
Copy link
Contributor

tw2113 commented Dec 6, 2022

Not sure we'd be able to change this behavior without breaking all the already existing sites out there, to be honest.

The more important thing to do would be to not do standard find/replace on db exports, because you will run into the issues above with any plugin/theme that stores any urls in serialized data. It's definitely not exclusive to CMB2.

I know that WP Migrate can do URL switches and handles serialized data, I also believe that WP-CLI and the search-replace command handles it as well. "Better Search Replace" I know does as well, and that's from the same people as WP Migrate.

Typically whenever I'm moving an install, especially if I'm refreshing a local copy of a site with a recent backup, I'll change the siteurl and home database values manually since those aren't serialized, then import the SQL export and then use WP-CLI's search-replace to handle the rest of them.

@maxyudin
Copy link

maxyudin commented Jan 3, 2023

Another option, in addition to the " WP Migrate" plugin mentioned by @tw2113, is to install "Search Replace Database for WordPress". Read its description before using it, because careless use can be dangerous from a security point of view.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants