Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I was hunting down an php-error message in my drupal site:
Warning: array_flip(): Can only flip STRING and INTEGER values! in DrupalDefaultEntityController->load() (Row 178 of ..../includes/entity.inc).
Finally I could get an stack-trace where the jplayer.module file was spotted as a caller of the file API which relies on the entity API.
The responsible code is in the function jplayer_file_download($uri)
:
...
$result = db_query("SELECT fid FROM {file_managed} WHERE uri = :uri", array(':uri' => $uri));
$file = file_load($result->fetchField());
...
If the query-result is empty the file_load function will get passed an argument "FALSE", which is invalid.
Hence a short check for a "FALSE"-field would fix this issue:
...
$result = db_query("SELECT fid FROM {file_managed} WHERE uri = :uri", array(':uri' => $uri));
$result_field = $result->fetchField();
if (!$result_field)
return NULL;
$file = file_load($result_field);
...
Cheers!
Comment | File | Size | Author |
---|---|---|---|
#3 | jplayer-1397242-ensure-fid-exists-3.patch | 1.28 KB | q0rban |
Comments
Comment #1
guedressel CreditAttribution: guedressel commentedJust discovered the same behaviour in the jplayer_protected (sub)module.
Same story to fix it:
In function jplayer_protect_file_download($uri):
at...
...add a check on the resulting value:
done.
Comment #2
guedressel CreditAttribution: guedressel commentedComment #3
q0rban CreditAttribution: q0rban commentedjplayer_file_download() no longer exists. Here's a patch for this! It should be noted, I did not try to replicate this bug.
Comment #4
deviantintegral CreditAttribution: deviantintegral commentedThanks! Committed as ef67dd8.