Working with the Video module, it tries to create a temporary files table entry with nid=0 and filename=whatever.mov. Then, as it thumbnails video and saves the thumbnail as an Image node, _image_remove_derivatives gets called in the process. One of the db queries it makes is this:

db_query("DELETE FROM {files} WHERE nid = %d AND filename <> '%s'", $node->nid, IMAGE_ORIGINAL);

if $node->nid is not set because the new node has not been fully saved yet, then the query looks like this:

DELETE FROM files WHERE nid = 0 AND filename <> '_original';

This deletes the temporary video files, which makes this a critical bug -- rule number one: don't delete other people's data.

It would be a better idea to replace the above query with something like this:

  $sizes = array('dummy'=>"'%s'");
  foreach (_image_get_sizes() as $size) {
  	$sizes[$size['label']] = "'%s'";
  }
  db_query("DELETE FROM {files} WHERE nid = %d AND filename IN (".implode(',', array_values($sizes)).")", array_merge(array($node->nid), array_keys($sizes)));

Comments

drewish’s picture

Status: Active » Closed (duplicate)

well there's not really ownership of the files table... it's kind of a big problem actually, i've been trying to get a core patch in for it: http://drupal.org/node/33482

in anycase this is really a duplicate of: http://drupal.org/node/133436