Forums | Mahara Community
Developers
/
Mahara Database update and restore issue
09 August 2016, 20:25
Dear Mahara Developers,
Our University is using Mahara as one of the most important systems. We've used Mahara for 2 years. Teachers and students love this system. We really appreciate your great contributions.
I've encountered a issue about database. We want to change the old domain name to a new domain name for our mahara site. For example, the old domain name is "http://A.xjtlu.edu.cn", now we want to change it to "http://B.xjtlu.edu.cn".
But the historical files and pictures are stored with the old url in database, so under the new url, the pictures and files cannot be found.
Then I dumped the database file and opened the .sql database file with text wrangler(a text editor) and replaced all the old url "http://A.xjtlu.edu.cn" with the new url "http://B.xjtlu.edu.cn".
After the changes, I restored the database back to the server. What I want to see is that all the files and pictures can display properly with the updated url in database. But what I found is that the whole content of the text block was gone. Is that because the database is hashed?
Can you help me with this issue? Is there any other way to make the historical files and pictures still display well after the url be changed?
Many thanks.
Best wishes,
Lina
10 August 2016, 18:28
Hi Lina,
The problem you're having is because Mahara stores block configurations as PHP-serialized data: http://php.net/manual/en/function.serialize.php
In this format, strings are printed with an integer that shows how long the string is. For instance, "test" gets serialized as: s:4:"test";
So, if your old URL and your new URL are different lengths, then all the serialized strings now have incorrect lengths, and PHP will refuse to unserialize them. There are a couple of other fields in the database that also contain serialized data (I think the skins config, and the Leap2a import/export queue) but none of those are as likely to need a URL rewrite as the block config.
From time to time we've had to deal with this in the Mahara core code, when a Mahara upgrade requires blocks to be updated. The only way I've been able to make it work, is to write a PHP script that locates the blocks that need to be updated, then pulls out their data from the "block_instance.configdata" field in the database, unserializes it into a PHP object, makes the necessary changes, re-serializes the updated data and then writes it back into the database. You can see a sample of this in the file htdocs/blocktype/externalvideo/db/upgrade.php
That said, there are a few shortcuts that can let you avoid having to write an upgrade script:
1. Keep your old domain active, and have it redirect to your new domain. Then you don't need to update the database at all.
2. Pick a new domain that's exactly the same length as your old domain, and then do the find-replace.
3. Create a third domain exactly the same length as your old domain, and set it up to redirect to your new domain. Then find-and-replace your old domain with this third domain, instead of with your new domain directly.
4. Update the SQL file by hand to fill in the correct string length numbers. I'd only recommend this if it's a tiny handful of records to correct, though.
I hope that helps!
Cheers,
Aaron
10 August 2016, 20:14
Hi Aaron,
Thanks a lot for your kind help and detail information. That's really helpful. You are my hero!
It's really good to know the PHP-serialized data is the root reason for this and your detail explanations are really clear. Thanks for you recommendations, since we can only keep one domain name, I cannot go with the easier approaches. I will try to write a PHP script to update the length. It seems very complicate, but I will try make efforts to study and hopefully I can make it. Finger crossed.
Many thanks for taking your time to help me. Really appreciate it.
Best wishes,
Lina
11 August 2016, 10:38
I should probably mention, another option is to hire my employer Catalyst IT (the primary maintainer of Mahara) to write the script for you. :) If you're interested in that option, here's a link to our support packages: https://www.catalyst.net.nz/what-we-offer/learning-and-development/mahara-support-packages
Cheers,
Aaron
11 August 2016, 14:20
Hi Aaron,
Thanks for your information about the support packages, I will discuss with my boss about this.
Thanks a lot.
Best wishes,
Lina
12 August 2016, 14:11
Hi Aaron,
I've found a tool which can help me fix this issue. I used this tool successfully replaced the url. Here is the link of this tool:
https://interconnectit.com/products/search-and-replace-for-wordpress-databases/
Thanks a lot for you kind help.
Best wishes,
Lina