Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment #2
sjpeters79 CreditAttribution: sjpeters79 commentedComment #3
mikeryanI 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.
Comment #4
japo32 CreditAttribution: japo32 at Catalyst IT commented\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.
Comment #5
heddnSeems fixed to me?