? image.install_______________
? image.module____________
? 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	3 Jul 2007 15:13:42 -0000
@@ -69,3 +69,35 @@
   }
   return array();
 }
+
+/**
+ * Clean up all the records that aren't in the files directory.
+ */
+function image_update_4() {
+  $ret = array();
+
+  // Locate image files that aren't stored in the files directory.
+  $files_path = rtrim(file_directory_path(), '\\/');  
+  $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/%%'", $files_path);
+  while ($file = db_fetch_object($result)) {
+    $file->filepath = file_create_path($file->filepath);
+    if (file_exists($file->filepath)) {
+      // File exists, make sure there's not a duplicate record.
+      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);
+    }
+  }
+
+  // Delete rows from {file_revisions} that don't have matching {files}. 
+  $ret[] = update_sql("DELETE FROM {file_revisions} WHERE NOT EXISTS (SELECT * FROM {files} WHERE files.fid = file_revisions.fid)");
+
+  return $ret;
+}
