Hello!
I have found that
- cached image with custom action is not updated when
- we edit an CCK node with image field.

Custom action can use $node and for example render $node->title on the image. When we edit and change a node (e.g. the title) cached image should be deleted and createted once again when a imagecache preset contains a custom action.

Maybe it is an issue of imagecache, but I'm not good enough to fix it. Any help would be appreciated.

Thanks!

Comments

dman’s picture

Category: bug » feature
Status: Active » Postponed

This is a known issue, with no tidy solution.
There currently is no per-image trigger, or no way to feed a refresh signal back up the pipeline to imagecache file storage, short of rebuilding all images all the time.
#642048: No, you can't pass 'arguments' to imagecache_actions. Here's why
Someone may eventually build a mechanism that does this, but it doesn't exist at the moment. Imagecache currently doesn't even provide a per-image rebuild, only a per-preset one.
#746982: Trigger a flush when imagefield's title is changed
#876674: Dynamic Watermark

My money is on a different system - still using imageapi as an engine, but a different pipeline - one without cache in the name - if you want generated images to respond to changes in data.
A new, different module that doesn't yet exist. - imageGen

bartmichael’s picture

I have solved this problem writing a custom module implementing hook_nodeapi

function MODULE_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
if ($op =='update'){
if ($node contains CCK image field with Custom action){
imagecache_image_flush(PATH TO ORIGINAL IMAGE - for example $node->field_photo[0][filepath]);
}
}
}

This approach can be implemented in ImageCache Actions module, but generalization may be difficult:
the if() condition
and PATH TO ORIGINAL IMAGE

Thanks!

dman’s picture

imagecache_image_flush() ? that's new!
That is one part of the puzzle!

so, yes ... do-able. Good suggestion

fietserwin’s picture

Version: 6.x-2.0 » 7.x-1.x-dev

Can we flush 1 image or only the whole style directory? Or is this the requested functionality? I guess we can add that function if it is not there in core, we already augment core (image handling) with some features: module:// file wrapper, copy/import/export style. Leaving at postponed, as we first want to clean up the bug reports in the issue queue.

dman’s picture

Need to see if there is an equivalent to imagecache_image_flush() in new D7 core.

I don't really think it's imagecache_actions job to go adding a nodeapi type hook just to capture this situation - but based on this use-case request, it's the only way.
Still, I guess hook_node_update is now a lot less overhead than hook_nodeapi, so it's the correct design for this...

fietserwin’s picture

I think it is up to the image system to provide the API interface to such an action. I am not sure about the actual hook_node_update though, because this won't be needed in all situations, not even for each update, if e.g. it is about the title and the title has not changed. So that could mean deleting many images without the need for it. Anyway, we will see about that when we pick up this issue.

dman’s picture

Yeah precisely.
I don't see the need for it in the majority of cases, but it's impractical to calculate which cases it *may* be needed for.
If implemented, it would need some highly sensitive switch - which I can't calibrate.

Or - just turn it on for global cases (hook_node_update) - by choice - and allow the admin to take the hit of regenerating when not strictly needed. If it can be per-node (which it will be) then it's not too painful.
No other optimal solution I can see.

fietserwin’s picture

Status: Postponed » Closed (won't fix)

D7 image core module contains what is asked for:

/**
 * Clear cached versions of a specific file in all styles.
 *
 * @param $path
 *   The Drupal file path to the original image.
 */
function image_path_flush($path)

When to call this function is so system dependent that we can't do that. So create your own hook to listen to the change that raises the need for flushing and call the above mentioned function.