The issue I am having is image cache is not updated when an image with the same name is uploaded. The module includes code to clear caches, but it is commented out in lines 107-128 of upload_replace.module.
Is there a reason why this code was commented out and if so is there a way to still provide that functionality?
Lines 107-128:
//Have to clear the cache because the revision data is cached somewhere
/*
* Find the nids where this file is used
$query = "SELECT DISTINCT nid FROM {files} WHERE fid=%d";
$result = db_query($query, $new_file->fid);
while($data = db_fetch_object($result)) {
cache_clear_all("content:$data->nid");
}
*/
//This is inefficent, but how can we determine what nodes use this file?
// cache_clear_all('*', 'cache_content', TRUE);
}
/**
* HOOK_file_delete, update the filepath in the file object before deleting as we may have altered it above
* @param object $new_file
*/
/*
function upload_replace_file_delete(&$file) {
$file->filepath = db_result(db_query("SELECT filepath FROM {files} WHERE fid = %d", $file->fid));
}
*/
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | upload_replace-2037295-7.patch | 1017 bytes | elijah lynn |
| #5 | upload_replace-2037295-5.patch | 601 bytes | elijah lynn |
| #5 | interdiff-2037295-2-5.txt | 907 bytes | elijah lynn |
| #2 | upload_replace-image_style_cache_fix-2037295-2.patch | 583 bytes | ladybug_3777 |
Comments
Comment #1
capellicLooks like the code was commented out during the port from Drupal 6 to Drupal 7 query code and call to cache_clear_all aren't correct for Drupal 7. It simply looks like the module maintainer never got around to it. I did some digging and I've come up with some code that is working on my end and even works fine with Acquia Purge and Cache Expiration on the Acquia hosting platform.
Right below the comment, "//Have to clear the cache because the revision data is cached somewhere" (line 107), add this:
Leave the code that is commented out in the module as is.
Comment #2
ladybug_3777 commentedAdding an actual .patch file for this issue so the change above can be applied and rolled back out easier, as well as enabling it to be include in .make files.
Comment #3
elijah lynnComment #4
elijah lynnComment #5
elijah lynnIt appears this also needs to flush the cache of the file that was being replaced, the new _X.ext.
I have attached a patch that adds this although, maybe it could be more robust?
This is dependent on https://www.drupal.org/node/1115484#comment-11308321 being applied first.
Comment #6
elijah lynnMy patch is incorrect, it should be $old_destination, not $original_destination. I don't have time to re-roll right now but it is here if anyone needs it https://www.drupal.org/node/1115484#comment-11325069. If someone could re-roll that would be great!
Comment #7
elijah lynnI just committed #57 from #1115484: Parameter 1 to upload_replace_file_update() expected to be a reference, value given in module_invoke_all() which includes #2 here. Here is latest patch re-rolled against HEAD with the improvements to flush out the image style of the replaced image.
Comment #9
elijah lynnCommitted #7.
Comment #12
elijah lynnLol, I turned on testing but the error that came back was "no valid tests specified". Looks like I will turn off testing for now.
Comment #13
elijah lynn