From 9da79e8073d27ba49a06c4ae3334f6aa3b414214 Mon Sep 17 00:00:00 2001
From: Bradley M. Froehle <brad.froehle@gmail.com>
Date: Thu, 11 Nov 2010 13:49:03 -0800
Subject: [PATCH] 966238: WIP

---
 .../tests/upgrade/drupal-6.upload.database.php     |   30 +------------------
 .../simpletest/tests/upgrade/upgrade.upload.test   |   11 ++++---
 modules/system/system.install                      |    2 +-
 3 files changed, 9 insertions(+), 34 deletions(-)

diff --git modules/simpletest/tests/upgrade/drupal-6.upload.database.php modules/simpletest/tests/upgrade/drupal-6.upload.database.php
index 048aee0..261d0ce 100644
--- modules/simpletest/tests/upgrade/drupal-6.upload.database.php
+++ modules/simpletest/tests/upgrade/drupal-6.upload.database.php
@@ -22,16 +22,6 @@ db_insert('files')->fields(array(
   'timestamp' => '1285700240',
 ))
 ->values(array(
-  'fid' => '2',
-  'uid' => '1',
-  'filename' => 'powered-blue-80x15.png',
-  'filepath' => 'sites/default/files/powered-blue-80x15_0.png',
-  'filemime' => 'image/png',
-  'filesize' => '1011',
-  'status' => '1',
-  'timestamp' => '1285700317',
-))
-->values(array(
   'fid' => '3',
   'uid' => '1',
   'filename' => 'powered-blue-88x31.png',
@@ -182,8 +172,8 @@ db_insert('node_revisions')->fields(array(
   'vid' => '50',
   'uid' => '1',
   'title' => 'node title 38 revision 50',
-  'body' => "Attachments:\r\npowered-blue-80x15.png\r\npowered-blue-88x31.png\r\npowered-blue-135x42.png",
-  'teaser' => "Attachments:\r\npowered-blue-80x15.png\r\npowered-blue-88x31.png\r\npowered-blue-135x42.png",
+  'body' => "Attachments:\r\n", // There is a file attached to this node, but the entry is misssing in {files} so it will not be upgraded
+  'teaser' => "Attachments:\r\n",
   'log' => '',
   'timestamp' => '1285700487',
   'format' => '1',
@@ -286,22 +276,6 @@ db_insert('upload')->fields(array(
 ->values(array(
   'fid' => '3',
   'nid' => '38',
-  'vid' => '50',
-  'description' => 'powered-blue-88x31.png',
-  'list' => '1',
-  'weight' => '0',
-))
-->values(array(
-  'fid' => '4',
-  'nid' => '38',
-  'vid' => '50',
-  'description' => 'powered-blue-135x42.png',
-  'list' => '1',
-  'weight' => '0',
-))
-->values(array(
-  'fid' => '3',
-  'nid' => '38',
   'vid' => '51',
   'description' => 'powered-blue-88x31.png',
   'list' => '1',
diff --git modules/simpletest/tests/upgrade/upgrade.upload.test modules/simpletest/tests/upgrade/upgrade.upload.test
index efbff11..a000276 100644
--- modules/simpletest/tests/upgrade/upgrade.upload.test
+++ modules/simpletest/tests/upgrade/upgrade.upload.test
@@ -20,6 +20,7 @@ class UploadUpgradePathTestCase extends UpgradePathTestCase {
       drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.upload.database.php',
     );
     parent::setUp();
+    $this->variable_set('upload_update_batch_size', 2);
 
     $this->uninstallModulesExcept(array('upload'));
   }
@@ -36,8 +37,10 @@ class UploadUpgradePathTestCase extends UpgradePathTestCase {
     $query->fieldCondition('upload');
     $entities = $query->execute();
     $revisions = $entities['node'];
-    // Node revisions 50-52 should have uploaded files.
-    $this->assertTrue((isset($revisions[50]) && isset($revisions[51]) && isset($revisions[52])), 'Nodes with uploaded files now contain filefield data.');
+    // Node revision 50 should not have uploaded files, as the entry in {files} is corrupted.
+    $this->assertFalse((isset($revisions[50])), 'Nodes with missing files do not contain filefield data.');
+    // Node revisions 51-52 should have uploaded files.
+    $this->assertTrue((isset($revisions[51]) && isset($revisions[52])), 'Nodes with uploaded files now contain filefield data.');
     // The test database lists uploaded filenames in the body of each node with
     // uploaded files attached. Make sure all files are there in the same order.
     foreach ($revisions as $vid => $revision) {
@@ -58,9 +61,7 @@ class UploadUpgradePathTestCase extends UpgradePathTestCase {
       foreach ($files as $file) {
         $filenames[] = $file['filename'];
       }
-
-      $diff = array_diff($filenames, $recorded_filenames);
-      $this->assertTrue(empty($diff), 'The uploaded files are present in the same order after the upgrade.');
+      $this->assertIdentical($filenames, $recorded_filenames, 'The uploaded files are present in the same order after the upgrade.');
     }
   }
 }
diff --git modules/system/system.install modules/system/system.install
index f56ef40..4cbd081 100644
--- modules/system/system.install
+++ modules/system/system.install
@@ -2776,7 +2776,7 @@ function system_update_7061(&$sandbox) {
 
   // Determine vids for this batch.
   // Process all files attached to a given revision during the same batch.
-  $limit = 100;
+  $limit = variable_get('upload_update_batch_size', 100);
   $vids = db_query_range('SELECT vid FROM {system_update_7061} WHERE vid > :lastvid ORDER BY vid', 0, $limit, array(':lastvid' => $sandbox['last_vid_processed']))
     ->fetchCol();
 
-- 
1.7.0.4

