Index: mm_content.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/media_mover/mm_content/mm_content.module,v retrieving revision 1.1.2.9 diff -u -r1.1.2.9 mm_content.module --- mm_content.module 2 Nov 2007 14:56:26 -0000 1.1.2.9 +++ mm_content.module 5 Jun 2008 19:13:52 -0000 @@ -147,10 +147,89 @@ * Save to the CCK field */ function mm_content_node_save($file, $configuration) { - // @TODO: $fields = content_fields(); - $field_name = $configuration['mm_config_save_field']; - $db_info = content_database_info($fields[$field_name]); + $keys = array_keys($configuration['mm_config_save_field']); + $field_name = $keys[0]; + + if ($fields[$field_name]['type'] == 'image') { + $db_info = content_database_info($fields[$field_name]); + $path_parts = pathinfo($file['process_file']); + + // We need to load the entire node to get the 'vid' + $node = node_load(array('nid' => $file['nid'])); + + // We need the configuration to see what type of file the thumbnail is going to be. + $full_config = media_mover_get_configuration($configuration['cid']); + $file['mime'] = $full_config->process->configuration['thumb_format']; + + if (!$file['mime']) { + if (module_exists('mimedetect')) { + $file['mime'] = mimedetect_mime($file); + } + } + + $imagefield_file = array( + 'alt' => 'test', + 'title' => 'test', + 'session_id' => 0, + 'filename' => basename($file['process_file']), + 'filepath' => $file['process_file'], + 'preview' => $file['process_file'], + 'filesize' => filesize($file['process_file']), + ); + + $imagefield_file['fid'] = db_next_id('{files}_fid'); + db_query("INSERT into {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s','%s','%s',%d)", $imagefield_file['fid'], $file['nid'], $imagefield_file['filename'], $imagefield_file['filepath'], $imagefield_file['filemime'], $imagefield_file['filesize']); + + $column_names = array(); + $column_assignments = array(); + + foreach($db_info['columns'] as $column => $attributes) { + $column_names[] = $attributes['column']; + } + + foreach ($db_info['columns'] as $column => $attributes) { + $column_names[] = $attributes['column']; + if ($item[$column] == '' && !$attributes['not null'] && !$field['required']) { + $column_placeholders[] = '%s'; + $column_assignments[] = $attributes['column'] .' = %s'; + $item[$column] = 'NULL'; + } + else { + switch ($attributes['type']) { + case 'int': + case 'mediumint': + case 'tinyint': + case 'bigint': + $column_placeholders[] = '%d'; + $column_assignments[] = $attributes['column'] .' = %d'; + break; + case 'float': + $column_placeholders[] = '%f'; + $column_assignments[] = $attributes['column'] .' = %f'; + break; + default: + $column_placeholders[] = "'%s'"; + $column_assignments[] = $attributes['column'] ." = '%s'"; + } + } + $data[] = $imagefield_file[$column]; + } + $data[] = $node->vid; + $data[] = $node->nid; + + db_query('UPDATE {'. $db_info['table'] .'} SET '. implode(', ', $column_assignments) .' WHERE vid = %d AND nid = %d', $data); + cache_clear_all('content:'. $node->nid .':'. $node->vid, 'cache_content'); + + // add the storage data back to the file + $file['storage_file'] = $file['process_file']; + $file['storage_module'] = 'mm_content'; + $file['storage_action'] = '4'; + + watchdog('Media Mover Content', t('Added file to CCK field: !node', array('!node', l(t($node->title), 'node/'. $node->nid)))); + + return $file; + } } /**