Blog entry

Drupal 7, IMCE and FileFields

As written in my previous post I decided to move the Origami Society website to Drupal 7.

One of the key features I need is a section for members only. At first I implemented this in Drupal 6 by using a single Page node protected by the Content Access module. All files were referenced as links on this page and put in a separate, private directory.

Or so I thought.

Turned out that the files were still directly accessible through the URL in the browser. Of course this showed up when I was asked to upload a file that was strictly forbidden to be publicly accessible. And of course this showed up in the last few days before my trip to Italy when I wanted to wrap up and clean up some of my todo lists.

I read that Drupal 7 was better capable of handling public and private files. So I had a long session ahead of me trying to figure out how things work.

First I needed to upgrade some special content types with CCK image fields.

My favorite combination of rich text editor and media browser are TinyMCE with the Wysiwyg and IMCE modules. I like the way I can press a little button right next to the URL field and a nice file browser opens so I can go and select the PDF or image I need. The file browser resembles Finder and Windows Explorer so my web team members quickly know their way around.

For all things public, this works very well. Well ...., after I found out that I had to upload my files through the IMCE file browser. I had never done that because it's quite tedious to upload a file at a time when you need to upload  multiple files. I usually started an ftp session and uploaded them that way. I had noticed before that I couldn't access these files in Drupal, but since I could still select them in the IMCE file browser and add them to the content I was writing at the moment, it wasn't such a problem.

The moment arrived I needed to update the 2500+ nodes with origami model references. I found out that IMCEImage was not ported to Drupal 7 and I was referred to the FileField module. Of course it was only AFTER I moved to Drupal 7 that I read that the transition was best done in Drupal 6. And of course FileField requires that the image is uploaded through the UI and is represented by a record in the database.

There were two problems:

  • No way was I going to edit all 2500+ nodes by hand and uploading all the images one by one.
  • Several nodes refer to the same images and the standard FileField widgets don't provide anything other than an upload for adding a file. This upload would result in several copies of the same image file. Big waste of disk space.

I manually edited a node and checked the database for the actions that were taking place. Turned out, that with some clever MySQL updates I was able to convert the IMCEImage information to FileField information.

With these MySQL queries I was able to move the files to a different location in one go.