global_settings); if (!isset($field_settings['list_default']) || !is_numeric($field_settings['list_default'])) { $field_settings['list_default'] = 1; $updated = TRUE; } // set behavior to match old force_list behavior. if (!empty($field_settings['force_list'])) { $field_settings['list_default'] = 1; $field_settings['force_list_default'] = 1; $updated = TRUE; } if ($updated) { db_query("UPDATE {content_node_field} SET global_settings = '%s' WHERE field_name = '%s'", serialize($field_settings), $field->field_name); } } // add data column to filefields. $fields = content_fields(); foreach ($fields as $field) { if ($field['type'] != 'filefield') continue; $new_field = $field; $new_field['columns']['data'] = array('type' => 'text'); content_alter_db($field, $new_field); } // Build a batch that migrates the data in each filefield $batch = array( 'title' => t('Migrating filefield values'), 'operations' => array(), 'file' => drupal_get_path('module', 'filefield') .'/filefield.install', ); $content_info = _content_type_info(); foreach ($content_info['content types'] as $node_type => $node_info) { foreach ($node_info['fields'] as $field_name => $field) { if ($field['type'] == 'filefield') { $batch['operations'][] = array('_filefield_update_6001_move_operation', array($field)); $batch['operations'][] = array('_filefield_update_6001_drop_operation', array($field)); } } } batch_set($batch); // clear them caches. cache_clear_all('*', content_cache_tablename(), TRUE); cache_clear_all('*', 'cache', TRUE); return $ret; } /** * Migrate field settings from 'force_list_default' and 'show_description'. */ function filefield_update_6100() { $ret = array(); module_load_include('inc', 'content', 'includes/content.crud'); $fields = content_fields(); foreach ($fields as $field) { if ($field['type'] == 'filefield') { $field['list_field'] = empty($field['force_list_default']); $field['description_field'] = $field['show_description']; _content_field_write($field); $ret[] = array('success' => TRUE, 'query' => t('The File field %field has been updated with new settings.', array('%field' => $field['field_name']))); } } return $ret; } /** * Set fid to NULL where files have been deleted. * * This is a double-cleanup from Drupal 5 versions, where fid used to be 0 for * empty rows or sometimes referred to a nonexistent FID altogether. */ function filefield_update_6101() { $ret = array(); module_load_include('inc', 'content', 'includes/content.crud'); $fields = content_fields(); foreach ($fields as $field) { if ($field['type'] == 'filefield') { $db_info = content_database_info($field); if (isset($db_info['columns']['fid'])) { $table = $db_info['table']; $fid_column = $db_info['columns']['fid']['column']; $list_column = $db_info['columns']['list']['column']; $ret[] = update_sql("UPDATE {" . $table . "} SET $fid_column = NULL, $list_column = NULL WHERE $fid_column NOT IN (SELECT fid FROM {files})"); } } } return $ret; } /** * Fix corrupted serialized data in the "data" column. */ function filefield_update_6102(&$sandbox) { // Update removed. This turned out to be a bug in CCK core, so it is being // fixed directly in CCK rather than in FileField. // See http://drupal.org/node/407446. return array(); } /** * Convert "Extensible File" to a normal "File" widget. */ function filefield_update_6103() { $ret = array(); $ret[] = update_sql("UPDATE {". content_instance_tablename() ."} SET widget_type = 'filefield_widget' WHERE widget_type = 'filefield_combo'"); cache_clear_all('*', content_cache_tablename(), TRUE); cache_clear_all('*', 'cache', TRUE); return $ret; } /** * Move the list and descriptions column into the serialized data column. */ function _filefield_update_6001_move_operation($field, &$context) { // Setup the first through if (!isset($context['sandbox']['progress'])) { $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; } // 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); while ($row = db_fetch_array($result)) { // Try to unserialize the data column. if (!empty($row[$context['sandbox']['col_data']])) { $data = unserialize($row[$context['sandbox']['col_data']]); } if (empty($data)) { $data = array(); } // Copy move the values from the columns into the array... $data['description'] = $row[$context['sandbox']['col_desc']]; // ...serialize it and store it back to the db. 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']['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']; } } /** * Drop the list and description columns. */ function _filefield_update_6001_drop_operation($field, &$context) { $ret = array(); $db_info = content_database_info($field); // TODO: Now that the data has been migrated we can drop the columns. db_drop_field($ret, $db_info['table'], $db_info['columns']['description']['column']); $context['finished'] = 1; }