I have a Node migration which depends on a File migration, because the nodes being migrated have file associations.

This works fine when I import Files, then import Nodes.

The Node migration has the subfield 'preserve_files' set to TRUE, as follows:

$this->addFieldMapping('field_file:preserve_files')->defaultValue(TRUE);

However, when I rollback the Node migration, the entries in the `file_managed` table in Drupal 7 are lost. The entries in the `migrate_map_file` table remain, so the subsequent import fails to associate files with nodes.

This works:

drush mi File
drush mi Node

Nodes are imported and all files which were associated in the source data are maintained and work as expected.

This works:

drush mi File
drush mi Node
drush mr Node
drush mr File
drush mi File
drush mi Node

This causes the nodes to have zero file associations:

drush mi File
drush mi Node
drush mr Node
drush mi Node

What could be causing this? Why doesn't the last set of operations import file association on nodes' file field?

Comments

nerdcore created an issue.

nerdcore’s picture

https://api.drupal.org/api/drupal/modules!file!file.field.inc/function/f...

Although I do not see a reference to `file_field_delete_file()` in the module, is it possible a similar function is being performed? I am concerned that despite setting

$this->addFieldMapping('field_file:preserve_files')->defaultValue(TRUE);

the file usage counter may decrement to zero on rollback, causing the record in the database table `file_managed` to be removed even though the file on disk is retained.