Perl script to migrate from SPGM to Zenphoto
I’m rather proud of myself, because, in something like two hours, I created a first perl script since, well, maybe 6 years.
The point of the script is to copy data (gallery and image description) from my current gallery called SPGM, to the new one called Zenphoto. SPGM stores data in plain text files, while ZP keeps in the database.
Got it working, and then found out that Zenphoto doesn’t integrate with wordpress so well. And that it is much less pretty inside, that I had thought. Eh.
Anyway, below is the script and some details in case someone might find it useful.
Some introduction
SPGM stores data for each gallery (which have separate folders) in files called gal-desc.txt and pic-desc.txt. The first file contains just one entry, while the second uses one line per image file, like this:
2005-05_Baltic_countries-001.jpg | Castle in Grodno
ZP stores everything in mysql, namely in tables called zp_albums and zp_images.
My goal was to easily transfer all description data for spgm gallery folder to ZP. The script is meant just for updating description data (for one folder at a time), and not for copying files themselves.
Procedure
The approach would be the following:
- Upload the script somewhere to your host (on which you need access to shell)
- Fill your database credentials in the top of the script
- Copy one gallery folder from spgm/gal to zenphoto/albums
- Delete all thumbnails from the folder (ZP creates them automatically)
- Run ZP from the browser over the new gallery, so that all images get reflected in mysql
- Execute the script from within the gallery folder (e.g. zenphoto/albums/gallery1/)
Note! Since script contains your database credentials it is not really safe to put it in the folder that is accessible from the browser (and albums folder is).
If all goes as planned, the script will update albums table with gallery description from gal-desc.txt, and update descriptions and titles for all images listed in pic-desc.txt. Provided, that images exist in the folder and in the database.
Ah yes and the script is here.
I’m not a programmer and especially perl programmer, so take it easy.
I think it can be easily adapted to other flat file based galleries.
Epilogue
Having made the script, I examined how to integrate ZP into Wordpress. And it looks like a no-go for now, because ZP seems to have much more difficult code than I expected. It’s hardly OO, rather a mix of functions and some classes, controller, processing and views are here and there, so the re-use of components from within wordpress is rather tricky. There is no straightforward solution for wordpress at the moment.
Given that it is unlikely that I will have time to create one myself (based on the first impression of the code), the migration script was a bit of a waste of time, but there.


