Hello, I do not know whether this post should go to d2d migrate module, but i think it is a global issue. Or just my lack of skill(?).

I have imported 30k files from my D6 sites separately into D7. Works fine.

I have to import my nodes with filefield now. Fids I want to import are not present in the nodes, so I decided to extend DrupalNode6Migration and get them from legacy DB manually as follows:

class MyNodeMigration extends DrupalNode6Migration {
  public function __construct(array $arguments) {
    parent::__construct($arguments);

    $this->addFieldMapping('field_image', 'old_fids')
      ->sourceMigration('DiitFile');
    $this->addFieldMapping('field_image:file_class')
      ->defaultValue('MigrateFileFid');
    $this->addFieldMapping('field_image:preserve_files')
      ->defaultValue(TRUE);
  }

  public function prepareRow($row) {
    if (parent::prepareRow($row)  === FALSE) {
      return FALSE;
    }

    $query = Database::getConnection('default', $this->sourceConnection)
      ->select('content_field_primary_image', 'cfi');
    $query->innerJoin('content_type_image', 'ci', 'ci.nid = cfi.field_primary_image_nid');
    $query->fields('ci', array('field_file_image_fid'))
      ->condition('cfi.nid', $row->nid);

    $row->old_fids = array_keys($query->execute()->fetchAllAssoc('field_file_image_fid'));
  }
}

Works fine! But... After going to EDIT tab in the migration admin and hitting save (even without any configuration) importing of the filefield stop working. Nodes are imported, but the field is empty. However everything looks fine in the editation and the filefield is correctly set up as in my code.

I tried to delete migration settings and start over. It works again till save button is pressed. $row->old_fids is filled properly with array of fids from legacy DB and the imported file exists in time of node imports.

Do I do something wrong? Can I comine code and UI? What am I missing?

Many thanks for (I hope fast) help :)

Gary

Comments

mikeryan’s picture

Category: Bug report » Support request
Status: Active » Postponed (maintainer needs more info)

Sorry the help wasn't fast... It's tough to say why saving the field mappings in the UI would have prevented the file fields from working - did you review the field_image mappings in the UI after that to make sure they still matched what you had in the code?

When you say you deleted migration settings - exactly which ones did you delete? If you deleted the DiitFile migration settings, you would have lost the data in the map table that's used to translate old fids to new.

mikeryan’s picture

Status: Postponed (maintainer needs more info) » Closed (cannot reproduce)