diff --git a/filefield.install b/filefield.install index f4d35780577ffba2cc76e38d063990191d503dfb..9cafe2881151d6f478fe463f0482b0057ebc83b4 100644 --- a/filefield.install +++ b/filefield.install @@ -295,21 +295,28 @@ function filefield_update_6104() { */ function _filefield_update_6001_move_operation($field, &$context) { // Setup the first through - if (!isset($context['sandbox']['progress'])) { + if (!isset($context['sandbox']['processed_files'])) { $db_info = content_database_info($field); $context['sandbox']['db_info'] = $db_info; $context['sandbox']['table'] = $db_info['table']; $context['sandbox']['col_data'] = $db_info['columns']['data']['column']; $context['sandbox']['col_desc'] = $db_info['columns']['description']['column']; $context['sandbox']['max'] = db_result(db_query("SELECT COUNT(*) FROM {". $db_info['table'] ."}")); - $context['sandbox']['progress'] = 0; $context['sandbox']['current_node'] = 0; + $context['sandbox']['processed_files'] = array(); } // Work our way through the field values 50 rows at a time. $limit = 50; - $result = db_query_range("SELECT * FROM {{$context['sandbox']['table']}} WHERE vid > %d ORDER BY nid ASC", $context['sandbox']['current_node'], 0, $limit); + $result = db_query_range("SELECT * FROM {{$context['sandbox']['table']}} WHERE vid >= %d ORDER BY vid ASC", $context['sandbox']['current_node'], 0, $limit); while ($row = db_fetch_array($result)) { + // Do not process the same file twice. This may happen when a node's files + // are split across two separate batch update HTTP requests. + $delta = isset($row['delta']) ? $row['delta'] : 0; + if (isset($context['sandbox']['processed_files'][$row['vid'] . '_' . $delta])) { + continue; + } + // Try to unserialize the data column. if (!empty($row[$context['sandbox']['col_data']])) { $data = unserialize($row[$context['sandbox']['col_data']]); @@ -325,14 +332,15 @@ function _filefield_update_6001_move_operation($field, &$context) { db_query("UPDATE {{$context['sandbox']['table']}} SET {$context['sandbox']['col_data']} = '%s' WHERE vid = %d", serialize($data), $row['vid']); // Update our progress information. - $context['sandbox']['progress']++; + $context['sandbox']['processed_files'][$row['vid'] . '_' . $delta] = TRUE; $context['sandbox']['current_node'] = $row['vid']; } // Inform the batch engine that we are not finished, // and provide an estimation of the completion level we reached. - if ($context['sandbox']['progress'] != $context['sandbox']['max']) { - $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; + $processed_count = count($context['sandbox']['processed_files']); + if ($processed_count != $context['sandbox']['max']) { + $context['finished'] = $processed_count / $context['sandbox']['max']; } }