Hello guys. I don't know exactly if my problem is caused by the fact I'm trying to get Media working with Field Collection module, but I believe it's so. I have a node with a Field Collection field (audio file and description in one bundle). I've added a file to my node through this Field Collection field. After a while I wanted to delete this file and removed it from the node but no matter what I do I can't get it deleted on admin/content/media page. It always says "The file is in use and cannot be deleted". My node has no versions that can be using this file. How do I handle that? If there is no way to do it through code I want at least some db workaround, or a detailed explanation of how exactly Media determines whether there are dependencies on files to correct them manually.

Comments

ParisLiakos’s picture

hmm seems that this file has references in file_usage table.
You could use
http://api.drupal.org/api/drupal/includes!file.inc/function/file_usage_d...

Ari Linn’s picture

Yes, right you are - this goddamned Field Collection creates links to its entities in file_usage and when it comes to deletion the whole mechanism suddenly overlooks the fact these links need to be deleted too. Seems I'll have to create a small module that erases the links on hook_file_delete.

Update: I've investigated hook_file_delete and found that it fires after file has been deleted, but I need it to fire before deletion. Oh damn. Guess I'll have to hack either Field Collection or Media on my drupal installation to remove unwanted links to files before deleting them.

ParisLiakos’s picture

Project: D7 Media » Field collection
Version: 7.x-1.2 » 7.x-1.x-dev
Component: Media Browser » Code

Hmm that sounds more of a field_collection bug i think, right?
if it creates file_usage entries it should delete them as well