I'm running a migration programmability via form submit submit and running into an issue where by on first run, the migration works fine and imports all users specified in a csv file.

However on subsequent file imports, the migration does not run for some reason. However if I manually roll back the migration and then try the form again it does do the import.

Below is my code which actually run the migration:

    $migration = Migration::load($migration_name);
    if ($migration) {
      if (isset($values['cmi_csv_file']) && is_array($values['cmi_csv_file'])) {
        $fid = array_pop($values['cmi_csv_file']);
        $file = File::load($fid);
        $file = file_move($file, 'public://temp.csv', FILE_EXISTS_REPLACE);
        if ($file) {
          $migration = \Drupal::service('plugin.manager.config_entity_migration')->createInstance($migration_name);

          $executable = new MigrateExecutable($migration, new MigrateMessage());

          try {
            $migration_status = $executable->import();
          }
          catch (\Exception $e) {
            \Drupal::logger('migrate_drupal_ui')->error($e->getMessage());
            $migration_status = MigrationInterface::RESULT_FAILED;
          }
          if ($migration_status) {
            drupal_set_message($this->t('Import Successful'));
          }
          else {
            drupal_set_message($migration_status, 'error');
          }
        }
      }
    }

As such I have two questions:

1) Is there anyway to force migration to rerun?
2) Is there anyway to override the source file path for the migration to use a different file?

Thanks.

Comments

sjpeters79 created an issue. See original summary.

sjpeters79’s picture

Issue summary: View changes
mikeryan’s picture

Project: Migrate Tools » Migrate Plus
Status: Active » Postponed (maintainer needs more info)

I don't see anything about migrate_tools as far as I can tell, migrate_plus is probably the closest place since you're using its configuration entities (but this is the sort of question, not specific to a module, that might be best on https://drupal.stackexchange.com/).

Anyway, this looks like a problem just discovered yesterday on a project I worked on - when you upload a file through a form and create a file entity, the entity status is set to 0 (temporary). This means that on a cron run, it may get cleaned up. You need to get in their and change file.managed to 1 (permanent) to prevent this.

japo32’s picture

\Drupal::service('plugin.manager.config_entity_migration') is now \Drupal::service('plugin.manager.migration') in the 8.x-4.x version of Migrate Tools reference.

And I used this answer which changes source.path to fix the re-importing issue.

heddn’s picture

Status: Postponed (maintainer needs more info) » Fixed

Seems fixed to me?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.