I have a MigrateDestinationTable migration that is set up to pull in image field focus settings from a CSV for use with the imagefield_focus module.

The migration runs and successfully populates the imagefield_focus_file table with the proper values from the CSV associated with the appropriate fid based on a look up performed in the prepareRow function. However, when the migration finishes there's an error in the log for each row in the CSV such as:

An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows. Path: /batch?id=1199&op=do StatusText: OK ResponseText: Undefined property: stdClass::$fid File /home/user/public_html/sites/all/modules/migrate/plugins/sources/sqlmap.inc, line 296(file: /home/user/public_html/sites/all/modules/migrate/plugins/sources/sqlmap.inc, line 296){"status":true,"percentage":"100","message":"Undefined property: stdClass::$fid\nFile \/home\/user\/public_html\/sites\/all\/modules\/migrate\/includes\/source.inc, line 256(file: \/home\/user\/public_html\/sites\/all\/modules\/migrate\/includes\/source.inc, line 256)\u003Cbr \/\u003ECould not save to map table due to NULL value for key field fid\u003Cbr \/\u003EProcessed 1 (1 created, 0 updated, 0 failed, 0 ignored) in 0 sec (4612\/min) - done with \u0027GalleryImageFocus\u0027\u003Cbr \/\u003E"}

Here is my migration code. I'm not sure what to check or what to do next. It's working as designed, but doesn't think it is for some reason. I have to manually truncate the imagefield_focus_file table before retrying the migration to prevent duplicate primary key errors.


class GalleryImageFocusMigration extends TUGalleriesMigration {
  public function __construct() {
    parent::__construct();

    $this->description = t('Migrate TU photo gallery image field focus settings');
    $this->softDependencies = array('GalleryImages');

    $table_name = 'imagefield_focus_file';

    $this->map = new MigrateSQLMap($this->machineName,
      array('fid' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        )
      ),
      MigrateDestinationTable::getKeySchema($table_name)
    );

    $columns = array(
        array('focus_id', 'Primary key'),
        array('value', 'Field focus data'),
        array('filename', 'Image filename'),
    );

    $this->source = new MigrateSourceCSV(DRUPAL_ROOT . '/' . drupal_get_path('module', 'tu_migrate') . '/gallery_image_focus.csv', $columns, array('header_rows' => 1));

    $this->destination = new MigrateDestinationTable($table_name);

    $this->addFieldMapping('fid', 'focus_id');
    $this->addFieldMapping('focus_rect', 'value');
    $this->addFieldMapping('crop_rect', NULL)->defaultValue(NULL);
    $this->addFieldMapping(NULL, 'filename');

  }

  public function prepareRow($row) {
    $fid = db_query('SELECT fid FROM {file_managed} WHERE filename = :fn', array(':fn' => $row->filename))->fetchField();
    if (empty($fid)) {
      return false;
    } else {
      $row->focus_id = $fid;
    }
  }
}


Comments

cameron prince’s picture

Status: Active » Closed (duplicate)

This is essentially the same issue as #1536722: "Could not save to map table" for every item. Marking as duplicate/closed.

clemens.tolboom’s picture

I had to read the issue twice :(

$this->map = new MigrateSQLMap($this->machineName,
      array('fid' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        )
      ),
      MigrateDestinationTable::getKeySchema($table_name)
    );

This suggest fid is the source key field but that is probably focus_id according to the field list.

$columns = array(
        array('focus_id', 'Primary key'),
        array('value', 'Field focus data'),
        array('filename', 'Image filename'),
    );