From 8fc4b666f49188450e6f188191dbc45b0adff3b4 Mon Sep 17 00:00:00 2001
From: Marco Villegas <marvil07@gmail.com>
Date: Fri, 27 Aug 2010 21:59:22 +0200
Subject: [PATCH] moshe patch + dereine little changes

---
 modules/system/system.install |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)

diff --git modules/system/system.install modules/system/system.install
index 2f3cf11..27155bf 100644
--- modules/system/system.install
+++ modules/system/system.install
@@ -2744,9 +2744,14 @@ function system_update_7060(&$sandbox) {
     }
   }
 
+  // Determine vids for this batch.
+  // Process all files attached to a given revision during same batch.
+  $limit = 100;
+  $vids = db_query_range('SELECT u.vid FROM {upload} u WHERE u.vid > :lastvid GROUP BY u.vid', 0, $limit, array(':lastvid' => $sandbox['last_vid_processed']))
+    ->fetchCol();
+
   // Migrate a batch of files from the upload table to the appropriate field.
-  $limit = 500;
-  $result = db_query_range('SELECT DISTINCT u.fid, u.vid, u.list, u.description, n.nid, n.type FROM {upload} u INNER JOIN {node_revision} nr ON u.vid = nr.vid INNER JOIN {node} n ON n.nid = nr.nid WHERE u.vid > :lastvid ORDER BY u.vid, u.weight', 0, $limit, array(':lastvid' => $sandbox['last_vid_processed']));
+  $result = db_query_range('SELECT u.fid, u.vid, u.list, u.description, n.nid, n.type FROM {upload} u INNER JOIN {node_revision} nr ON u.vid = nr.vid INNER JOIN {node} n ON n.nid = nr.nid WHERE u.vid IN (:vids) ORDER BY u.vid, u.weight', 0, $limit, array(':vids' => $vids));
   foreach ($result as $record) {
     // Note that we still reference the old files table here, since upload will
     // not know about the new FID in the new file_managed table.
-- 
1.7.1

