I just noticed that imagecache is trying to display a deleted image.

This was deleted using the imagefield Delete checkbox, and as far as imagefield processing is concerned, the image appears deleted.

However, the content_field_news_image record for the node still has the deleted fid of the image, and imagecache still tries to display this.

Setup was using the latest CCK v5.x-1.9, Imagefield v5.x-2.1, and imagecache v5.x-2.1

Two custom content types, using the shared field: E.g.

Field name               Field type   Used in
field_news_image    image         Award, News item

I initially tried using a default image, but this was removed as the default didn't match the two different fields, and it was at this point that I noticed that imagecache was formatting the empty image path.

A hack to imagecache was required to stop it formatting an empty field:

<?php
/**
 * Implementation of hook_field_formatter().
 */
function imagecache_field_formatter($field, $item, $formatter, $node) {
  if (empty($item['fid']) && $field['use_default_image']) {
    $item = $field['default_image']; 
  }
  // Views does not load the file for us, while CCK display fields does.
  if (empty($item['filepath'])) {
    $file = _imagefield_file_load($item['fid']);
    if(empty($file)) {
      return '';
    }
    $item = array_merge($item, $file);
  }
....
?>

Cheers

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hanoii’s picture

Status: Active » Needs review
FileSize
1.27 KB

This is related to something I already noticed in both imagefield and imagecache. I did a similar hack and posted the proper patch. The hack on this issue, however, belongs to the imagecache module and should be referenced there.

My proposed patch on the imagecache queue (very similar to this one) is on #260669: Imagecache field formatter is generating broken output when no actual image (or default) is available..
This should be fix as well on the formatter function for the imagefield module as I explained in #260672: Imagefield field formatter is generating broken output when no actual image (or default) is available..

Now this issue refers to a problem I also found but not on the content_field_XXX but rather on the content_type_XXX when the imagefield is not multiple.

@Alan, is this your same case or you are using a multiple imagefield and it doesn't remove the files from the content_field_XXX when you remove the images? I have tested this and it seems to be removing the entries from that table fine, but certainly not when the imagefield is not multiple.

So back to this problem I am submitting a patch that cleans the imagefield data on the content_type_XXX when the file is removed, meaning that when you have a single imagefield and you remove the file you don't want the content to refer to that file that no longer exists.

This patch also fixes the formatter which should not try to display a non existing or empty or 0 fid which is related to the hack Alan posted and to the one I also submitted some time ago in my other issue.

Alan D.’s picture

Hi hanoii

The field was definitely a multiple / shared imagefield.

The problem has not appeared in any other project, although this was one of the first projects that has used the default image option. Normally we do default images in code, with a file_exists check as standard. As stated above, the problem only seemed to appear after removing the default image option and formatting the imagefield container with padding. As Firefox doesn't show broken images, it may have occurred prior to this point.

The project with the issue is now stable and in production, by using the above code. I will keep a closer eye on future projects and report back if there are any issues.

Thanks

Alan

gollyg’s picture

I can confirm that this behaviour is occurring for me on a fresh install of drupal 5 with imagecache and imagefield installed.

The issue seems to occur with single and shared fields - the deletion seems to work, but the record is left in the database.

Patch has resolved the issue on both single and multiple fields. It does, however, leave a record in the table. Is this the standard method of removing a cck field (it well may be, just curious why the row is not deleted)

quicksketch’s picture

Status: Needs review » Fixed

Thanks for the great patch hanoii (although applied 6 months too late). Sorry for the huge delay in getting this fixed. :(

I've applied a slightly modified version where I set each field to NULL instead of ''. Also I put the fid == 0 check in hook_field() instead of in the formatters, so it should the default image setting should now work even in ImageCache presets. These fixes will be included in the 2.5 version.

quicksketch’s picture

FileSize
1.65 KB

Oh, here's the patch I applied.

quicksketch’s picture

Also applied an update function to correct rows that are currently incorrect for existing users.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.