Just had a user that had 15 videos in one node. He would delete the 5th video, then try and upload new videos again. This would cause a whole lot of problems with indexes not being correct when using the [video: index=x]
Tracked it down to the fact that the indexes are not updated, once a file is deleted.
so below is the patch that worked for me.. just put an else statement in near the bottom to update the index.
function _flashvideo_update_files($node) {
$video_index = 0;
if(count($node->files)) {
foreach ($node->files as $file) {
$file = (object)$file;
if ($file->remove) {
$files = db_query("SELECT * FROM {files} f LEFT JOIN {flashvideo} fv ON f.fid = fv.fid WHERE fv.oid = %d", $file->fid);
db_query("DELETE FROM {ffmpeg_data} WHERE fid = %d", $file->fid);
db_query("DELETE FROM {flashvideo} WHERE oid = %d", $file->fid);
while($oldfile = db_fetch_object($files)) {
db_query("DELETE FROM {files} WHERE fid = %d", $oldfile->fid);
db_query("DELETE FROM {file_revisions} WHERE fid = %d", $oldfile->fid);
file_delete($oldfile->filepath);
module_invoke_all('flashvideo_delete_file', $oldfile);
}
}
else {
$found = db_result(db_query("SELECT count(*) FROM {flashvideo} WHERE fid=%d", $file->fid));
$extension = _flashvideo_get_filetype($file->filepath);
if(_flashvideo_get_mime_type($extension, TRUE)) { // Only add if the file is a video and is not already in our flashvideo table.
if(!$found) {
$size = flashvideo_get_size($node, $file);
// Rename the original file.
$filepath = substr( $file->filepath, 0, (strrpos($file->filepath, '/') + 1) );
$base_name = preg_replace("/[^a-zA-Z0-9_\.]/", "_", $node->nid . "_" . basename($file->filepath, "." . $extension));
$filepath .= $base_name . "." . $extension;
if(rename( (getcwd() . '/' . $file->filepath), (getcwd() . '/' . $filepath) )) {
db_query("UPDATE {files} SET filepath='%s' WHERE fid=%d", $filepath, $file->fid);
}
db_query("INSERT INTO {flashvideo} (fid, nid, oid, status, video_index, width, height, flags) VALUES (%d, %d, %d, %d, %d, %d, %d, %d)",
$file->fid, $node->nid, $file->fid, FLASHVIDEO_STATUS_OK, $video_index, $size['width'], $size['height'], 0);
// If we don't want to wait for cron, call it immediately.
if (flashvideo_variable_get($node->type, 'convert', 0)) {
flashvideo_cron();
}
}
else
{
//update our index so its the correct offset.
db_query("UPDATE {flashvideo} SET video_index = %d WHERE oid=%d", $video_index, $file->fid);
}
$video_index++;
}
}
}
}
Comments
Comment #1
attheshow commentedNo activity in over a year. Closing issue.