Index: image.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/image/image.install,v retrieving revision 1.18 diff -u -p -r1.18 image.install --- image.install 17 Jan 2009 21:02:07 -0000 1.18 +++ image.install 17 Jan 2009 23:55:48 -0000 @@ -255,10 +255,17 @@ function image_update_5200() { // Copy image files records into the new table. $args = array_map('db_escape_string', array_keys(image_get_sizes())); $cond = " IN ('". implode("', '", $args) ."')"; - $ret[] = update_sql("INSERT INTO {image} SELECT DISTINCT f.nid, f.fid, f.filename FROM {files} f INNER JOIN {node} n ON f.nid = n.nid WHERE n.type='image' AND f.filename". $cond); - // Remove old file_revision records. - $ret[] = update_sql("DELETE FROM {file_revisions} WHERE EXISTS (SELECT * FROM {image} WHERE {image}.fid = {file_revisions}.fid)"); + // Upgrade from 5.x-1.x to 5.x-2.x. + if (db_table_exists('file_revisions')) { + $ret[] = update_sql("INSERT INTO {image} SELECT DISTINCT f.nid, f.fid, f.filename FROM {files} f INNER JOIN {node} n ON f.nid = n.nid WHERE n.type = 'image' AND f.filename" . $cond); + $ret[] = update_sql("DELETE FROM {file_revisions} WHERE EXISTS (SELECT * FROM {image} WHERE {image}.fid = {file_revisions}.fid)"); + } + // Upgrade from 5.x-1.x to 6.x-1.x. + else { + $ret[] = update_sql("INSERT INTO {image} SELECT DISTINCT u.nid, f.fid, f.filename FROM {upload} u INNER JOIN {files} f ON u.fid = f.fid INNER JOIN {node} n ON u.nid = n.nid WHERE n.type = 'image' AND f.filename" . $cond); + $ret[] = update_sql("DELETE FROM {upload} WHERE EXISTS (SELECT * FROM {image} WHERE {image}.fid = {upload}.fid)"); + } return $ret; }