Drupal 6.17 / Migrate Extras 6.x.1-beta1 / Migrate 6.x.1.0 / FileField 6.x.3.3

I am trying to migrate nodes that have optional filefield (mp3) files. Nodes with the filefield path populated will migrate correctly, but nodes with an empty path fail with the following error:

"warning: filesize() [function.filesize]: stat failed for NULL in /Users/myname/Sites/acquia-drupal/modules/acquia/filefield/field_file.inc on line 154.
The selected file NULL could not be saved. Only files with the following extensions are allowed: mp3."

I tried the patch suggested in http://drupal.org/node/780920 (Node Not Saving When Filefields Are Empty or Null) but this has no effect.
I also tried removing the 'allowed filetypes' setting, which was set to allow MP3 files only. Again, no effect.

I have a massive migration task ahead of me, so would like to get this nailed if I can - any advice appreciated.

Thanks

JB

CommentFileSizeAuthor
#2 migrate_extras.patch2.36 KBrobertDouglass
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

quicksketch’s picture

Project: FileField » Migrate Extras
Version: 6.x-3.3 » 6.x-1.x-dev
Component: Code » Filefield

I'd be happy to accommodate for this in FileField if a patch is provided, but since I've never used Migrate Extras it's hard for me to know where to start. My feeling is that it's unlikely this is a problem with FileField, since I know you can node_save() and set FileField properties just fine in customized scripts. This is probably a problem with Migrate Extras not setting the properties correctly.

robertDouglass’s picture

Status: Active » Needs review
FileSize
2.36 KB

This is an easy fix. It just fails when there is no source file, whether that is because it isn't supposed to have one, or because the source file is missing. Both cases come up regularly in migrations. The code is just missing an if (file_exists()), which this patch provides. The added error message lets you go back and audit the migration and take remedial actions where files are missing.

robertDouglass’s picture

This is what the patch looks like ignoring whitespace:


+++ filefield.migrate.inc	22 Jul 2010 14:33:04 -0000
@@ -16,6 +16,7 @@ function filefield_migrate_prepare_node(
   foreach (filefield_migrate_fields_node($node->type) as $source_key => $label) {
     if (!empty($node->$source_key)) {
       $source_file = $node->$source_key;
+        if (file_exists($source_file)) {
       $field_name = preg_replace('/_sourcefile$/', '', $source_key);
 
       $field = content_fields($field_name, $tblinfo->desttype);
@@ -35,6 +36,10 @@ function filefield_migrate_prepare_node(
         $errors[] = migrate_message(t('File save failed for %file', array('%file' => $source_file)));
       }
     }
+      else {
+        $errors[] = migrate_message(t('Original data file doesn\'t exist: %file', array('%file' => $source_file)));
+      }
+    }
   }
   return $errors;
 }
wapnik’s picture

unfortunately i provided a duplicate at #867304 and i'm starting a poll about whose message is prettier? :)

tobiassjosten’s picture

Patch in #2 has been merged with patch for #731992: multi-value filefields and it's working like a charm. It's obviously not a duplicate issue but perhaps a duplicate fix is valid? :)

mikeryan’s picture

Status: Needs review » Closed (won't fix)

Migrate and Migrate Extras V1 are no longer supported.