Repeatable: Always
Steps to repeat:
1. Upload an image via the media browser and insert into the body of a content item.
2. Via Content -> Files - use the media browser to delete the image from the site.
3. Re-vist the content item that was using the image - you'll see the image missing icon (grey with a broken white box - image-x-generic.png).
4. Remove the missing image from the content body, and click save.

Expected Results:
An updated content item (node) without the image (or missing image icon).

Actual Results:
Recoverable fatal error: Argument 1 passed to file_usage_delete() must be an instance of stdClass, boolean given, called in /Users/tony/Projects/Drupal/public/sites/all/modules/media/includes/media.filter.inc on line 72 and defined in file_usage_delete() (line 689 of /Users/tony/Projects/Drupal/public/includes/file.inc).

Note: If the missing image (image-x-generic.png) is left in the body of the content item, the text of the item, and other elements in the body can be saved and updated okay. The error above only occurs when you try to remove the missing image placeholder.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ParisLiakos’s picture

Priority: Normal » Major
Issue tags: +7.x-2.0 alpha blocker
slashrsm’s picture

Status: Active » Needs review
FileSize
695 bytes

Attached patch kinda fixes it....

I am thinking... Is it OK to allow delete of a file that is in use on an entity? Shouldn't we prevent people from doing this?

azinck’s picture

This pattern is very common in Drupal. You can delete a taxonomy term even if other entities reference it, etc. The file deletion form does warn you if the file's in use. It could be nicer and give you a list of all the places it's in use but to me that's a different question. Your patch looks sensible to me though I haven't yet tested it.

slashrsm’s picture

You are right. Maybe we should at least make this warning more visible, as it can be easily overlooked now.

Entities that use a given file can be seen at Usage tab (file/FID/usage).

azinck’s picture

I agree with making the warning more noticeable. And thanks for the tip about the usage tab; I guess I've always overlooked that one.

slashrsm’s picture

Actually... We could make it more visible AND link to usage list. What do you think about that?

azinck’s picture

Very smart.

I don't have a good sandbox environment in front of me: is the usage list subject to node_access limitations (in other words, do nodes that you don't have permission to see get listed here)? If not, then I'd advise adding something to the usage page that says something like "plus 42 pieces of content you don't have access to".

slashrsm’s picture

I believe that all entities are listed there (not only nodes), even the ones you do not have access to.

slashrsm’s picture

Confirmation message is part of file_entity so I created another patch there to make it more visible: #1949462: Make usage info on file delete confirmation more visible.

Dave Reid’s picture

Can we have a test to confirm this behavior at all?

slashrsm’s picture

Sure thing. Test added.

Murz’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, this patch fix problem for me, will be good to see it in HEAD

aaron’s picture

Status: Reviewed & tested by the community » Fixed

I have committed this patch. Thanks for the great work.

Automatically closed -- issue fixed for 2 weeks with no activity.