1

I was given 'temporary' images for a number of bio pages, and now have better quality images to replace them with. Removing or replacing the old images in the Admin UI is failing (without giving me any error messages or indications of anything wrong: the old image is just there no matter what I do). If I connect to the server by SSH and rm CEO.jpeg from bash, then the database is out of sync with the file system, and when I upload the new version of CEO.jpeg, I get an error because that is already in the database.

If I just edit the file_usage table and set count to 0, will that have any nasty side effects? (I will also, of course, manually delete the file from the file system.) Do I have to manually track down each node and edit it too? Or can I just go to those nodes in the Admin UI after manual removal and add the new versions of the images?

(I've checked answers to this question and this question but the situation in those is very different.)

1

This is probably more of a comment but the code won't fit in...there should be no reason for the UI to fail on the file delete, unless the web server daemon doesn't have write permission to the files folder. That would be the first thing I'd check, then try again.

If that fails, you might want to give it a go manually:

$nids = db_query("SELECT nid FROM {node} WHERE type = 'the_type'")->fetchCol();

foreach (node_load_multiple($nids) as $node) {
  $node->field_name[LANGUAGE_NONE] = array();
  node_save($node);
}

That will take care of the whole lot (removing the data from file_managed, file_usage, and deleting the file from the disk if it exists and is writeable).

  • I checked the permissions, and the files are owned by apache, so (unless I'm missing something, which is possible) I don't think that's where the problem is. – iconoclast Dec 11 '12 at 16:19
  • Can I just edit the file_usage table, or do I need to track down each node too? – iconoclast Dec 11 '12 at 16:20
  • 1
    I've updated the answer, I just tested it and the short version is the way to go. It's just 'magic' :) – Clive Dec 11 '12 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.