Converting Drupal into WordPress
WordPress has the ability to update automatically, while our existing Drupal systems require time to take care manually. This is the main reason for our switch.
So the first thing I did was to google for a plugin, I found about the fg-drupal2wordpress plugin however it only passes the posts, and doesn’t import users/media/tags unless you pay about 40€, so naturally I stayed off from it, my second intuition was to look it up on Github, and what I found it was also a plugin and it was open source, I used it, and it worked for almost anything except the images.
original website, even some images are missing now because the website is not on /
The gallery
Challenges
The thing with the images is that the Drupal that I was given used a very old version of the drupal “Images” add-on, so the plugin converts these images as “posts”, but they’re not actually converted as images.
as you can see, some posts are blank
In drupal, every blogpost and image are stored as a Node
sql query result of “SELECT nid,file_usage.fid,node.title,files.filepath FROM perspektive.node INNER JOIN perspektive.file_usage ON perspektive.node.nid = perspektive.file_usage.id INNER JOIN perspektive.files ON perspektive.file_usage.fid = perspektive.files.fid”, as you can see we can see where the images are stored, what node id do they have, and what file id they have according to Drupal.
In order to pass these images to wordpress you need a script that reads every image location, copies it into the correspondent wp-content/uploads/YYYY/MM/ directory, makes a thumbnail of every image, and you have to add around 5 columns to the wp_postmeta table, if you do that, you’ll effectively import all the images to the media file in wordpress, and that is without counting the tags, and the author of every image! It is not an easy task!
Proposals
One solution to this problem was to add an `img` tag for every of these posts so that every posts has their own image, and this works in principle, you might even add an “image” tag to every image post, however they’re not actually appended on the wordpress media library, so if you want a page to act as a gallery, it won’t work in that sense. What would you need to do is to add every image as a media gallery on wordpress, you can do this, but you have to convert a lot of images, and it’s not easy because you also have to create thumbnails, you could kind of automate this process using WP-CLI, and add a lot of images with it, the problem would be that the images keep their post id or node id on drupal, and copying the information that is contained on the drupal database, it’s not hard but it takes time to do.
Another one was to actually update the open source plugin myself which is what I started to do, so I started digging into its code to find out how it worked, I probably found some errors while investigating, and I also searched for forks of the project since apparently the original author was not replying to PRs or Issues, the project had been abandoned, so if I needed help, I could only help myself.
Thoughts
I always knew about CMS, and how they worked, but never got into them because I never felt I was fully of control or that I understood the website, however now that I investigated about this issue, I feel I have a more intrinsic understanding about Drupal and WordPress, and I might be more prompt to use them myself in the case that I need to.
I find it surprising that it is really hard to find converters or conversors for SQL to other formats (like JSON), there were some web converters but they were web only and couldn’t handle the data size. At the end I used PHPMyAdmin, which was probably what I was looking for, and I did learn a ton about SQL.
Resources
Author: Mario Behling, Website: https://web.archive.org/web/20060615070835/http://www.perspektive89.com:80, Title: Perspektive89
Author: Dries Buytaert, https://api.drupal.org/api/drupal, Title: Drupal API reference
Author: WordPress, Website: https://developer.wordpress.org/reference/, Title: WordPress Reference