I have a configuration that harvests files from a particular filefield, and then moves the file to s3.
I checked the box "delete local file".

Question #1
After the file is moved to s3, the local copy gets deleted. However, it is still listed in the 'files' database table, as though it were still a local file.
Is this a bug? Once mm_s3 deletes the local file, should it also delete the entry for this file in the 'files' database table?

Question #2
After the user deletes the file, it is still listed in the 'files' table.
Is this a bug? Once the user deletes a file, should should media_mover_api delete its entry in the 'files' database table?

Comments

kobnim’s picture

Issue summary: View changes

simplified the question

kobnim’s picture

With regard to question #1:

I tried modifying mm_s3 to delete the entry in the 'files' table, when the local file was deleted. Specifically, inside the function mm_s3_send(), I replaced:
unlink($delete_file);
with:

$success = file_delete($delete_file); // Calls unlink(), then returns SUCCESS
if ($success){  //If the file was successfully deleted, update the database
  db_query('DELETE FROM {files} WHERE filepath = "%s"', $delete_file);
}

Unfortunately, I now get this warning message on the node-form:

warning: array_merge() [function.array-merge]: Argument #2 is not an array in /mysite/sites/all/modules/filefield/filefield_widget.inc on line 255.

Presumably, mm_s3 was doing the right thing by not deleting the entry in the 'files' table, even though the local file had been deleted.

kobnim’s picture

Again with regard to question #1

I just thought of another reason not to delete the entry in the files table, when a file is moved to s3. Filefield uses the 'files' table to handle potential file-name collisions. For example, if a user uploads 'test.mp3', but a file with the same name (and path) was previously uploaded, then filefield renames the second file to 'test_0.mp3'. If the files on s3 were not listed in the 'files' table, then filefield wouldn't know when two different files had the same name.

kobnim’s picture

With regard to question #2

I modified the function media_mover_api_node_update($node), in media_mover_api.module, to delete the file-listing from the 'files' table, when the user has deleted a media-mover file.

I replaced:
media_mover_api_file_delete_call($mm_file);

with:

media_mover_api_file_delete_call($mm_file);
// patch:  delete listing from 'files' table
$fid = $mm_file['fid'];
db_query('DELETE FROM {files} WHERE fid = "%d"', $fid);

Note:
I submitted a patch that includes this fix. See http://drupal.org/node/1478246

arthurf’s picture

On question #1

With drupal 6 this is a hard one- because the files table cannot store non-local files it presents issues. I think people have been using the option of deleting the source material when they don't want to have the file stored in the files table and the media mover files table

As per #2

Question #2
After the user deletes the file, it is still listed in the 'files' table.

Do you mean delete from the node or delete from media mover here?

kobnim’s picture

Regarding #2:
I am storing files in a multi-valued filefield. The user edits the node, deletes the file from the filefield, and then saves the node. The file the user just deleted is still listed in the 'files' table.

Does that answer your question?

kobnim’s picture

The patch here fixes this problem: http://drupal.org/node/1478246#comment-5893866

kobnim’s picture

Issue summary: View changes

clarification