Problem/Motivation
(why the issue was filed, steps to reproduce the problem, etc.)
Setup - I used a patched development version of Media and Media Gallery - see steps here: http://drupal.org/node/1244204#comment-6678836
Recreating the problem:
Error message "Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (line 178 of [site_docroot]/includes/entity.inc)."
http://i50.tinypic.com/aetoqb.jpg
This occurred because I deleted 3 pictures. The error message is displayed for each picture deleted. It does not display if you don't delete any of your pictures after uploading them. The error is displayed for both the authenticated user that can upload the gallery and also visible to unauthenticated users.
Proposed resolution
(description of the proposed solution, the rationale behind it, and workarounds for people who cannot use the patch)
It appears that deleting an image from a media_gallery gallery is not handled properly - I am guessing that some database entries relating to the deleted image are not removed or "cleaned up".
Remaining tasks
(reviews needed, tests to be written or run, documentation to be written, etc.)
Repeat steps that reproduced the problem, to see that the error message does not now appear (once the fix is done.)
User interface changes
(new or changed features/functionality in the user interface, modules added or removed, changes to URL paths, changes to user interface text)
The user should not need to do anything different when deleting an image.
API changes
(API changes/additions that would affect module, install profile, and theme developers, including examples of before/after code if appropriate)
Wouldn't expect any API to change, unless it is something still under development in Media 2.x-dev or Media Gallery 1.x-dev
Original report by [username]
// Text of original report here.
(for legacy issues whose initial post was not the issue summary)
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | Snapshot-09-11-2012-1147.png | 218.52 KB | therobyouknow |
Comments
Comment #1
therobyouknow commentedJust some thoughts to help fix the problem:
Doing a search found a different problem but with a similar message, one of the remedies suggested may be useful for solving this issue: http://drupal.org/node/1811850#comment-6597686
Therefore, the thinking so far would be one or more of:
- to make code in entity.inc more defensive - such a fix being similar to the remedy in: http://drupal.org/node/1811850#comment-6597686
- to make sure that the parameters are valid that are passed by the calling code to entity.inc
Comment #2
moloc commentedAre you using media 2.x ? This issue sound like a duplicate of #1715422: Deleting a file without removing it from the gallery breaks that gallery. Can you confirm that?
Comment #3
therobyouknow commentedYes, media 2.x - 7.x-2.0-unstable6 to be exact. I will look at the issue you mention but perhaps it is not a duplicate as in my case the gallery is not broken as such, it's just that the error message is shown for each image that I have deleted via the delete option that the media gallery provides - the other images still display OK. Thanks for your suggestion.
By the way, I have been able to use the development version of media gallery to get it working with media 2.x - credit to those who worked on media gallery (rather than myself). I have documented my steps to get it working here - comment 102: http://drupal.org/node/1244204#comment-6678836
Comment #4
therobyouknow commentedDrupal user @leanderl confirms they can reproduce my same problem in this issue, their comment is made in this other issue here: http://drupal.org/node/1244204#comment-6708178
Comment #5
therobyouknow commentedI can confirm that the root cause is that the entry for the deleted image is not removed from field_data_media_gallery_media table in the Drupal MySQL database. This is the equivalent of a null/dangling pointer in other software. The remedy would be to add code to the media_gallery to remove the entry from the field_data_media_gallery_media table.
The root cause is illustrated in the following screen shot showing the relationship between the error, the Drupal MySQL tables including field_data_media_gallery_media, and the media files themselves.
(locally on drupal.org :- )
(same screenshot also available externally here:- )
http://i46.tinypic.com/b67mtx.jpg
A work around would be to do a standard MySQL delete/drop of the specific entries in field_data_media_gallery_media that refer now to the deleted files.
Comment #6
therobyouknow commentedComment #7
therobyouknow commentedI have tried this - my own suggestion - and it does not cause the error to no longer appear. Clean up to remove the deleted file references will also be necessary in the following database tables (but cleaning these up also still does not remedy the problem)
So although I was correct to point out that there were references to deleted files in some MySQL tables. I was incorrect to assume that these are the only cause of the error message.
Comment #8
therobyouknow commentedFurther update which eliminates the error message that this issue is about ("Delete image works but warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load()" )
Steps:
From this I'm wondering if it is necessary to clean up the entries myself in the database tables or just delete the images via the gallery, and then go into edit the gallery and just click save.
Comment #8.0
therobyouknow commentedClarified setup to recreate the problem
Comment #9
ivnish