Index: filefield.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield.install,v retrieving revision 1.22 diff -u -r1.22 filefield.install --- filefield.install 16 Mar 2009 00:25:50 -0000 1.22 +++ filefield.install 18 Mar 2009 03:19:23 -0000 @@ -170,6 +170,59 @@ } /** + * Fix corrupted serialized data in the "data" column. + */ +function filefield_update_6102(&$sandbox) { + $ret = array(); + + // Gather list of fields that need tables updated. + if (!isset($sandbox['fields'])) { + $fields = content_fields(); + foreach($fields as $name => $field) { + if ($field['type'] == 'filefield') { + $field['db_info'] = content_database_info($field); + $sandbox['fields'][$name] = $field; + } + } + + $sandbox['count'] = count($sandbox['fields']); + $sandbox['current_node'] = 0; + } + + // Number of rows to fix at once: + $limit = 1000; + + // Start correcting data. + if ($field = array_shift($sandbox['fields'])) { + $table = $field['db_info']['table']; + $data_column = $field['db_info']['columns']['data']['column']; + + $result = db_query_range("SELECT * FROM {" . $table . "} WHERE vid > %d ORDER BY vid ASC", $sandbox['current_node'], 0, $limit); + + // Add the row back into the list of fields to be processed if rows remain. + if (db_affected_rows() == $limit) { + array_unshift($field, $sandbox['fields']); + } + + // Loop through the rows and start fixing. + while ($row = db_fetch_array($result)) { + $data = unserialize($row[$data_column]); + // At this point the data should be an array, if it's not then that means + // it's now a serialized array ready to be inserted. + if (!empty($data) && is_string($data)) { + db_query("UPDATE {" . $table . "} SET $data_column = '%s' WHERE vid = %d", $data, $row['vid']); + } + } + } + + if ($sandbox['count']) { + $ret['#finished'] = 1 - count($sandbox['fields']) / $sandbox['count']; + } + + return $ret; +} + +/** * Move the list and descriptions column into the serialized data column. */ function _filefield_update_6001_move_operation($field, &$context) { Index: filefield_field.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield_field.inc,v retrieving revision 1.18 diff -u -r1.18 filefield_field.inc --- filefield_field.inc 15 Mar 2009 06:21:21 -0000 1.18 +++ filefield_field.inc 18 Mar 2009 03:19:23 -0000 @@ -167,10 +167,6 @@ if (!empty($item['fid']) && empty($item['filepath'])) { $items[$delta] = array_merge($item, field_file_load($item['fid'])); } - // Extract data array from serialized string. - if (is_string($item['data'])){ - $items[$delta]['data'] = unserialize($item['data']); - } // Add nid so formatters can create a link to the node. $items[$delta]['nid'] = $node->nid; }