I have a got feature setup that defines a migration. This works very well and I can succesfully run the migration after installing the feature.

I would like to automatically run the migration when the feature is being installed. I wrote the following install file for it:

/**
 * Implements hook_install().
 */
function feature_front_install() {
  MigrationBase::registerMigration('FrontBlocks', 'FrontBlocks', array('class_name' => 'FrontBlocks'));
  MigrationBase::registerMigration('FrontPageItems', 'FrontPageItems', array('class_name' => 'FrontPageItems'));
  
  $migration = Migration::getInstance('FrontBlocks');
  $migration->processImport();

  $migration = Migration::getInstance('FrontPageItems');
  $migration->processImport();
}

/**
 * Implements hook_uninstall().
 */
function feature_front_uninstall() {
  $migration = Migration::getInstance('FrontBlocks');
  MigrationBase::deregisterMigration('FrontBlocks');
  
  $migration = Migration::getInstance('FrontPageItems');
  MigrationBase::deregisterMigration('FrontPageItems');
}

The install hook runs and starts the migration. But the problem is that only the title field for the imported nodes gets saved. All other fields are ignored.

When I then run a "drush mr FrontBlocks" and "drush mi FrontBlocks" all the fields are there.

What am I doing wrong here?

Comments

mikeryan’s picture

Status: Active » Postponed (maintainer needs more info)

Tough to say - are the fields that are not being imported defined in the same feature? It may be that they haven't yet been set up when the install hook runs. Also, I don't think Drupal does a full bootstrap by default for install hooks - you might try a drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL).

weseze’s picture

I've tried moving the import to another feature so that I'm 100% sure the content type and fields were created in a feature installed before it. Didn't help...

I'll try the bootstrap suggestion, although I'm not getting my hopes up because the documentation states that:

...
Note that since this function is called from a full bootstrap, all functions (including those in modules enabled by the current page request) are available when this hook is called.
...

Have you personally done something like this before and succeeded?

mikeryan’s picture

I have not heard of anyone attempting to run migrations in an install hook before, you're a trailblazer;).

I would debug by running your module installs from drush, with some drush_print's and drush_print_r's in prepareRow, prepare, complete to figure out where the disconnect is - is the source row not getting properly populated? Are the field mappings not being applied? Are the field handlers not building the field arrays for them?

mikeryan’s picture

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

No further information provided.

mikeryan’s picture

Issue summary: View changes

typo