jax.be

Often wrong, never in doubt

Testing a Drupal site without the production images

July11th

When a client needs changes to his Drupal site I always ask a recent DB dump and the files they use in production. With this files bundle comes the files directory which usually contains the imagecache directories. With this last client that files directory was more than 6G and that was impractical to copy.

Now, testing a site without the images doesn't seem right and when the client needs to test the changes the testers won't have the same "feel" as with the original site. To solve this I was wondering if it would be possible to use mod_rewrite to pickup the files that don't exist and inject a dummy image that imagecache will process.

This is what I came up with:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/sites/default/files/(.*/)*([^/]+)$
RewriteCond %{DOCUMENT_ROOT}/sites/default/files/%2 !-f
RewriteRule ^sites/default/files/imagecache/(.*)/(.*)$ sites/default/files/imagecache/$1/missing.png

These rules must be placed before the Drupal rules. Here's what happens:

  1. If the requested file exists, do nothing
  2. Get the requested filename (without the path)
  3. If the file (retrieved in the previous rule) exists at the root, do nothing
  4. Replace the image filename with missing.png

The result is that for existing files in the files directory nothing will happen but when a imagecache path is retrieved for files that have no source in the files directory it will use missing.png. This is a file that I created myself and manually placed in the files directory.

Now when I browse the site with an incomplete files directory at least the layout looks right and there are images where there are supposed to be!

AttachmentSize
missing.png2.12 KB