If I use filefield to upload files and filefield_meta module is enabled too, when I upload a file a record with some informations is written in {filefield_meta} table
When we convert a video or delete a video/node this information are not updated.
I don't know if is a good thing to add this feature in this module but line 60->63 works for me

function _flashvideo_perform_postop($oldfile, $newfile, $node_type, $create_thumbnail = FALSE) { 
2 
3   $timestamp = time(); 
4 
5   if ((_flashvideo_get_filetype($oldfile->filepath) == 'flv') && !$create_thumbnail) { 
6     db_query("UPDATE {files} SET filepath='%s', filename='%s', filesize=%d WHERE fid=%d", $newfile->filepath, $newfile->filename, $newfile->filesize, $newfile->fid); 
7 
8     // Insert this video into the flashvideo table if it is not already in there. 
9     if (!db_result(db_query("SELECT COUNT(*) FROM {flashvideo} WHERE oid=%d AND fid=%d AND nid=%d", $newfile->fid, $newfile->fid, $newfile->nid))) { 
10       // Insert this video into the flashvideo table. 
11       db_query("INSERT INTO {flashvideo} (fid, nid, oid, status, video_index, width, height, flags) VALUES (%d, %d, %d, %d, %d, %d, %d, 0)", $newfile->fid, $newfile->nid, $oldfile->fid, FLASHVIDEO_STATUS_CONVERTED, $params->video_index, $params->width, $params->height); 
12       db_query("INSERT INTO {ffmpeg_data} (fid, created, input_file, output_file, status) VALUES (%d, %d, '%s', '%s', %d)", $oldfile->fid, $timestamp, $oldfile->filepath, $newfile->filepath, 1); 
13     } 
14   } 
15   else { 
16     // Create a temporary file for the new file. 
17     db_query("INSERT INTO {files} (uid, filename, filepath, filemime, filesize, status, timestamp) VALUES (%d, '%s', '%s', '%s', %d, %d, %d)", $newfile->uid, $newfile->filename, $newfile->filepath, $newfile->filemime, $newfile->filesize, FILE_STATUS_TEMPORARY, time()); 
18 
19     // Get the new File ID 
20     $newfile->fid = db_last_insert_id('files', 'fid'); 
21 
22     // Look to make sure that the File ID doesn't already exists in the files table. 
23     $found = db_result(db_query("SELECT COUNT(*) FROM {files} WHERE filepath='%s' AND status=%d", $newfile->filepath, FILE_STATUS_PERMANENT)); 
24 
25     // If the file isn't already in the files table... 
26     if ($found == 0) { 
27 
28       // Grab the width, height, and video_index from the original video to copy over to the new video, then insert the new video in the flashvideo table. 
29       $params = db_fetch_object(db_query("SELECT video_index, width, height FROM {flashvideo} WHERE fid = %d", $oldfile->fid)); 
30 
31       // Create the appropriate database entry for the newly converted video file. 
32       if (module_exists('filefield') && flashvideo_variable_get(NULL, 'flashvideo_filefield', 0)) { // Using FileField 
33         // Names of the different video fields? Let's find out. 
34         $cck_original_video_field = flashvideo_variable_get($node_type, 'cck_original_video_field', ''); 
35         $cck_finished_video_field = flashvideo_variable_get($node_type, 'cck_finished_video_field', ''); 
36         $cck_finished_thumbnail_field = flashvideo_variable_get($node_type, 'cck_finished_thumbnail_field', ''); 
37         $cck_table = 'content_type_'. $node_type; 
38         if ($create_thumbnail) { // This is for the finished thumbnail. 
39           // For single-upload file fields 
40           if (db_column_exists($cck_table, $cck_original_video_field .'_fid')) { 
41             db_query("UPDATE {". $cck_table ."} SET ". $cck_finished_thumbnail_field ."_fid = %d, ". $cck_finished_thumbnail_field ."_list = 0 WHERE nid = %d", $newfile->fid, $newfile->nid); 
42           } 
43           else { // For multi-upload file fields 
44             // Get rid of the initial NULL entry. 
45             db_query("DELETE FROM {content_". $cck_finished_thumbnail_field ."} WHERE nid = %d AND ". $cck_finished_thumbnail_field ."_fid IS NULL", $newfile->nid); 
46             db_query("INSERT INTO {content_". $cck_finished_thumbnail_field ."} (vid, nid, delta, ". $cck_finished_thumbnail_field ."_fid, ". $cck_finished_thumbnail_field ."_list) VALUES (%d, %d, %d, %d, 0)", $newfile->nid, $newfile->nid, $params->video_index, $newfile->fid); 
47           } 
48         } 
49         else { // This is for the finished video. 
50           // For single-upload file fields 
51           if (db_column_exists($cck_table, $cck_original_video_field .'_fid')) { 
52             db_query("UPDATE {". $cck_table ."} SET ". $cck_finished_video_field ."_fid = %d, ". $cck_finished_video_field ."_list = 0 WHERE nid = %d", $newfile->fid, $newfile->nid); 
53           } 
54           else { // For multi-upload file fields 
55             // Get rid of the initial NULL entry. 
56             db_query("DELETE FROM {content_". $cck_finished_video_field ."} WHERE nid = %d AND ". $cck_finished_video_field ."_fid IS NULL", $newfile->nid); 
57             db_query("INSERT INTO {content_". $cck_finished_video_field ."} (vid, nid, delta, ". $cck_finished_video_field ."_fid, ". $cck_finished_video_field ."_list) VALUES (%d, %d, %d, %d, 0)", $newfile->nid, $newfile->nid, $params->video_index, $newfile->fid); 
58           } 
59           // write meta data for new file and delete for old. 
60           if (module_exists('filefield_meta')) { 
61             filefield_meta_file_delete($oldfile); 
62             filefield_meta_file_insert($newfile); 
63           } 
64         } 

Hope this helps.

Comments

attheshow’s picture

Status: Active » Postponed (maintainer needs more info)

Can you please explain what you're trying to accomplish by adding this code?

tagliavinid’s picture

Ok.
Me and I suppose the great majority of people use Filefield in conjunction with Filefield_meta (parts of filefield module and not a third parts plugin) for file upload.

Filefield should work in this way:
When I upload a file, Upload module write a record in {files} table, Filefield hook writes a related record in {content_my_cck_field_name} and Filefield_meta hook writes another related record in {filefield_meta}.

When a file is converted with flashvideo the old file is delete from {content_". $cck_original_video_field . "}.
The converted video is inserted in {content_". $cck_finished_video_field ."} and in {files} table.

This operation broke the relationship between the uploaded file and it's metadata.

For this reason for each video I upload my {filefield_meta} grow up and lose importance after conversion.
If I delete a node with converted video in {filefield_meta} no records (obviously, they're not related) are deleted.

So, my add help to mantain consistency between these tables.

tagliavinid’s picture

Status: Postponed (maintainer needs more info) » Active
attheshow’s picture

Status: Active » Closed (won't fix)

I don't use the FileField Meta module myself, and I'm not familiar with the usage statistics on that portion of the module package (not sure how many others make use of it). For that reason, I'm marking this as "won't fix", but please feel free to submit any patches to the FlashVideo module if you figure out a good way to adapt the code and make it work better with FileField Meta.