IMCE is recording each file uploaded through its interface both in the file_managed table (that's fine) and in the file_usage table. As a consequence, it is impossible, for instance, to subsequently delete a file through the Media user interface, because such file appears to be in use by some entity. For comparison, when a file is uploaded using the Media module (at admin/content/media), the file is registered in file_managed, but not in file_usage.

The documented purpose of file_usage is to “track where a file is used” (see also file_usage_add()). That is, to associate a file to another object (a node, a user, etc…). If the file is not used by another object, it should not be tracked there. As IMCE is not used to attach files to nodes it should never touch the file_usage table.

Comments

ufku’s picture

Status: Active » Closed (works as designed)

It is used to mark a file as an IMCE file and to prevent deletion of IMCE files using other interfaces.

haggins’s picture

Title: IMCE records uploaded files in file_usage table even if they are not in use » Record uploaded files in file_usage table only if they are in use
Category: bug » feature
Status: Closed (works as designed) » Active

How can I recognize if an image is unused (and can be deleted) without that feature? Setting the file used only if it gets inserted in any content would be perfectly fine. At the moment it would be only possible if there would be a IMCE specific tracking mechanism.

What about an option to let the site builder decide about this behavior?

ufku’s picture

Status: Active » Closed (won't fix)

There is no sane way to track if a file is inserted into or removed from node body. The site builder can undo the registration using file hooks in a module.

treksler’s picture

Status: Closed (won't fix) » Active

But there is a sane way to track insertion into the node body.
The media module has a patch in http://drupal.org/node/1268116

ufku’s picture

Status: Active » Closed (won't fix)

That solution is for media token which possesses a specific format. There is no sane way to decide about ownership of an image added as html markup.