=== modified file 'modules/audio/audio.install' --- modules/audio/audio.install 2010-03-13 20:53:37 +0000 +++ modules/audio/audio.install 2010-03-13 21:34:39 +0000 @@ -282,21 +282,13 @@ ); db_add_field($ret, 'audio', 'remote_size', array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ) - ); - db_add_field($ret, 'audio', 'remote_size', - array( 'type' => 'int', 'size' => 'medium', 'not null' => TRUE, 'default' => 0, ) ); - $ret[] = update_sql("UPDATE {audio} a INNER JOIN {audio_file} af ON a.vid = af.vid SET a.file_name = af.filename, a.file_path = af.filepath, a.file_mime = af.filemime, a.file_size = af.filesize"); + $ret[] = update_sql("UPDATE {audio} a SET file_name = af.filename, file_path = af.filepath, file_mime = af.filemime, file_size = af.filesize FROM {audio_file} af WHERE a.vid = af.vid"); db_drop_table($ret, 'audio_file'); // Build an array of renamed tokens. @@ -407,8 +399,8 @@ $fid_field = array( 'type' => 'int', 'unsigned' => TRUE, - 'not null' => TRUE, - 'description' => t('Primary Key: The {files}.fid.'), + 'not null' => FALSE, + 'description' => t('Foreign Key: The {files}.fid.'), ); db_add_field($ret, 'audio', 'fid', $fid_field); db_add_index($ret, 'audio', 'audio_fid', array('fid')); @@ -419,9 +411,16 @@ while ($file = db_fetch_object($result)) { // Then move the data into the files table. db_query("INSERT INTO {files} (uid, filename, filepath, filemime, filesize, status, timestamp) SELECT n.uid, '%s', ai.file_path, ai.file_mime, ai.file_size, 1, n.created AS timestamp FROM {node} n INNER JOIN {audio} ai ON n.vid = ai.vid WHERE ai.file_path = '%s' LIMIT 1", array(basename($file->file_path), $file->file_path)); - db_query("UPDATE {audio} SET fid = %d WHERE file_path = '%s'", db_last_insert_id('files', 'fid'), $file->file_path); + if(db_affected_rows()) { + db_query("UPDATE {audio} SET fid = %d WHERE file_path = '%s'", db_last_insert_id('files', 'fid'), $file->file_path); + } } + // Now that fid is populated, set it to NOT NULL + db_query("DELETE FROM {audio} WHERE fid IS NULL"); + $fid_field['not null'] = TRUE; + db_change_field($ret, 'audio', 'fid', 'fid', $fid_field); + // Drop the old fields. db_drop_field($ret, 'audio', 'file_mime'); db_drop_field($ret, 'audio', 'file_name'); @@ -438,4 +437,4 @@ db_change_field($ret, 'audio', 'file_format', 'format', $format_field); return $ret; -} \ No newline at end of file +}