? .image.install.swp ? contrib/image_import/image_import.module_____fixes Index: image.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/image/image.install,v retrieving revision 1.1.4.5 diff -u -r1.1.4.5 image.install --- image.install 2 Jul 2007 22:50:25 -0000 1.1.4.5 +++ image.install 2 Jul 2007 23:47:47 -0000 @@ -69,3 +69,29 @@ } return array(); } + +/** + * Clean up all the records that aren't in the files directory. + */ +function image_update_4() { + $ret = array(); + + $result = db_query("SELECT f.nid, f.fid, f.filename, f.filepath FROM {files} f INNER JOIN {node} n ON f.nid = n.nid WHERE n.type = 'image' AND f.filename = '_original' AND NOT f.filepath LIKE '%s/%%'", rtrim(file_directory_path(), '\\/')); + while ($file = db_fetch_object($result)) { + $file->filepath = file_create_path($file->filepath); + if (file_exists($file->filepath)) { + if (db_result(db_query("SELECT COUNT(*) FROM {files} f INNER JOIN {node} n ON f.nid = n.nid WHERE n.type = 'image' AND filepath = '%s' AND fid <> %d", $file->filepath, $file->fid))) { + $ret[] = update_sql("DELETE FROM {files} WHERE fid = ". (int)$file->fid); + $ret[] = update_sql("DELETE FROM {file_revisions} WHERE fid = ". (int)$file->fid); + } else { + $ret[] = update_sql("UPDATE {files} SET filepath = '". db_escape_string($file->filepath) ."' WHERE fid = ". (int)$file->fid); + } + } + else { + $ret[] = update_sql("DELETE FROM {files} WHERE fid = ". (int)$file->fid); + $ret[] = update_sql("DELETE FROM {file_revisions} WHERE fid = ". (int)$file->fid); + } + } + return $ret; +} +