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!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

guedressel’s picture

Just discovered the same behaviour in the jplayer_protected (sub)module.
Same story to fix it:

In function jplayer_protect_file_download($uri):
at...

  $result = db_query("SELECT fid FROM {file_managed} WHERE uri = :uri", array(':uri' => $uri));
  $file = file_load($result->fetchField());

...add a check on the resulting value:

  $result = db_query("SELECT fid FROM {file_managed} WHERE uri = :uri", array(':uri' => $uri));
  $fid = $result->fetchField();
  if ( ! $fid)  {
    return NULL;
  }
  $file = file_load($fid);

done.

guedressel’s picture

Status: Active » Needs review
q0rban’s picture

jplayer_file_download() no longer exists. Here's a patch for this! It should be noted, I did not try to replicate this bug.

deviantintegral’s picture

Status: Needs review » Fixed

Thanks! Committed as ef67dd8.

Status: Fixed » Closed (fixed)

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