Should I *always* import my file references into the database in drupal?

Posted by sprugman on Stack Overflow See other posts from Stack Overflow or by sprugman
Published on 2010-05-03T21:34:50Z Indexed on 2010/05/03 21:38 UTC
Read the original article Hit count: 187

Filed under:
|
|
|

I have a cck type with an image field, and a unique_id text field. The file name of the image is based on the unique_id. All of the content, including the image itself is being generated automatically via another process, and I'm parsing what that generates into nodes. Rather than creating separate fields for the id and the image, and doing an official import of the image into the files table, I'm tempted to only create the id field and create the file reference in the theme layer. I can think of pros and cons:

1) Theme Layer Approach

Pros:

  • makes the import process much less complex
  • don't have to worry about syncing the db with the file system as things change
  • more flexible -- I can move my images around more easily if I want

Cons:

  • maybe not as much The Drupal Way™
  • not as pure -- I'll wind up with more logic on the theme side.

2) Import Approach

Pros:

  • import method is required if we ever wanted to make the files private (we won't.)
  • safer? Maybe I'll know if there's a problem with the image at import time, rather than view time. Since I'll be bulk importing, that might make a difference.
  • if I delete a node through the admin interface, drupal might be able to delete the file for me, as well.

Con:

  • more complex import and maintenance

All else being equal, simpler is always better, so I'm leaning toward #1. Are there any other issues I'm missing?

(Since this is an open ended question, I guess I'll make it a community wiki, whatever that means.)

© Stack Overflow or respective owner

Related posts about drupal

Related posts about files