Index: mm_cck.module
===================================================================
--- mm_cck.module	(revision 163)
+++ mm_cck.module	(working copy)
@@ -157,7 +157,7 @@
       break;
 
       // handle image field case
-      case 'filefield':
+      case 'file':
       case 'image':
         // are file types being checked?
         if ($configuration['file_types']) {
@@ -176,7 +176,7 @@
           WHERE  (n.nid IS NOT NULL AND m.nid IS NULL) OR
             (n.nid IS NOT NULL AND n.nid = m.nid AND f.filepath <> m.harvest_file)
             '. $file_type_conditions .'
-          ORDER BY f.timestamp', $configuration['cid']);
+          ORDER BY n.nid', $configuration['cid']);
 
         // now build the out going file data
         while ($result = db_fetch_array($results)) {
@@ -215,6 +215,7 @@
 
   // get the field that we are using
   $field = content_fields($configuration['mm_cck_field_save_'. $action]);
+  $field = content_fields($configuration['mm_cck_field_save_'. $action],$field['type_name']);
   switch ($field['type']) {
     case 'text':
       $node->{$field['field_name']} = array(array('value' => $file_path));
@@ -228,13 +229,12 @@
     // handle image field case
     // @TODO merge this into filefield
   	case 'image':
-  	  $file = mm_cck_field_image($node, $field, $file_path, $configuration);
+  	  $file = mm_cck_field_image($node, $field, $file, $configuration);
     break;
 
-  	case 'filefield':
-  	  $file = mm_cck_field_filefield($node, $field, $file_path, $configuration);
-  	break;
-
+  	case 'file':
+  	  $file = mm_cck_field_filefield($node, $field, $file, $configuration);
+  	break;  	
   }
 
   // return the file
@@ -252,16 +252,19 @@
  *   path to file
  * @return unknown
  */
-function mm_cck_field_image(&$node, $field, $file_path, $configuration) {
-  // is there a specified directory to use with this field?
-  $destination_path = mm_cck_field_widget_files_directory($field);
+function mm_cck_field_image(&$node, $field, $file, $configuration) {
 
-  $validators = array_merge(filefield_widget_upload_validators($field), imagefield_widget_upload_validators($field));
+  // create a temporal file structure
+  $imagefield_file = array(
+   'filename' => basename($file['process_file']),
+   'filepath' => $file['process_file'],
+   'filesize' => filesize($file['process_file']),
+   'filemime' => mimedetect_mime($file['process_file']),
+  );
 
   // now get the new field
-  // @TODO  WHY THE HECK IS THIS NOT TAKING THE ABOVE FILE PATH ?!?!
-  if (! $file = field_file_save_file($file_path, $validators, 'sites/default/files')) {
-    watchdog('MM Content', 'Could not save file', null, WATCHDOG_ERROR);
+  if (! $file = imagefield_file_insert($node,$imagefield_file,$field)) {
+    watchdog('MM CCK', 'Could not save file', null, WATCHDOG_ERROR);
   }
 
   // we need to alter the file object slightly so it will display correctly
@@ -291,16 +294,18 @@
  * @param array $configuration
  * @return array
  */
-function mm_cck_field_filefield(&$node, $field, $file_path, $configuration) {
-  // is there a specified directory to use with this field?
-  $destination_path = mm_cck_field_widget_files_directory($field);
+function mm_cck_field_filefield(&$node, $field, $file, $configuration) {
 
-  // get the validators for this field
-  $validators = filefield_widget_upload_validators($field);
+  // create a temporal file structure
+  $filefield_file = array(
+   'filename' => basename($file['process_file']),
+   'filepath' => $file['process_file'],
+   'filesize' => filesize($file['process_file']),
+  );
 
   // now get the new field
-  if (! $file = field_file_save_file($file_path, $validators, $destination_path)) {
-    watchdog('MM Content', 'Could not save file', null, WATCHDOG_ERROR);
+  if (! $file = filefield_file_insert($node,$field, $filefield_file)) {
+    watchdog('MM CCK', 'Could not save file', null, WATCHDOG_ERROR);
   }
 
   // we need to alter the file object slightly so it will display correctly
@@ -309,7 +314,7 @@
   $file['list'] = $configuration['field_save_list'];
 
   // add the file on to the node
-  $node->{$field['field_name']}[] = $file;
+  $node->{$field['field_name']}[] = $filefield_file;
   // save the node
   node_save($node);
   // clear the cache
