Closed (fixed)
Project:
Drupal core
Version:
8.2.x-dev
Component:
migration system
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
11 Jul 2016 at 15:30 UTC
Updated:
11 Apr 2024 at 12:27 UTC
Jump to comment: Most recent
Comments
Comment #2
cilefen commentedSupport requests are Normal priority.
Comment #3
mikeryanThe basic principle is to create an instance of your migration via the plugin manager, construct a MigrateExecutable object from that migration, and call $executable->import(). E.g.
Full real-world examples can be found in core and contrib.
Comment #4
sgurlt commentedThis is perfect, thanks a lot :)
Comment #6
andres.torres commentedHi all,
I'm having a hard time trying to have the code above to work on a hook_cron on D8, but I'm always getting the following error when running cron:
TypeError: Argument 1 passed to Drupal\migrate_tools\Controller\MigrationController::__construct() must be an instance of Drupal\migrate_plus\Plugin\MigrationConfigEntityPluginManager, none given, .......
Ideally i'd like to run a migration and add additional operations through this hook.
Here's my sample code, hope anyone can take a look and point me in the right direction.
Thanks in advance!
<?php
/**
* @file
*/
use Drupal\migrate\Row;
use Drupal\migrate\MigrateExecutable;
use Drupal\migrate\MigrateMessageInterface;
use Drupal\migrate\MigrateMessage;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Event\MigrateEvents;
use Drupal\migrate_plus\Entity\Migration;
use Drupal\migrate_plus\Entity\MigrationGroup;
use Drupal\migrate_plus\Plugin\MigrationConfigEntityPluginManager;
use Drupal\migrate_tools\Controller\MigrationController;
/**
* Implementation of hook_cron().
*/
function my_module_cron() {
// Get migration object
$migration_id = 'my_migration_name';
/** @var \Drupal\migrate\Plugin\Migration $migration */
$migration = \Drupal::service('plugin.manager.migration')->createInstance($migration_id);
$executable = new MigrateExecutable($migration, new MigrateMessage());
$ex = $executable->import();
//drupal_set_message('');
}
Comment #7
sjpeters79 commentedAndres, you may want to try the following:
Comment #8
saranya ashokkumar commentedHi,
I have created a form with file field.
On submit I have to run migration programmatically.
By passing migration_id, I have created the instance. but the problem is that, I need to change the source.urls dynamically by getting the file path from form.
I have set the source url by config set before importing migration, but on create instance the url is not getting change.
Can anyone suggest me, how to change the migration url dynamically before import.
Thanks,
Saranya.P
Comment #9
sleopold commentedsaranya, you can override the source config when you create the plugin instance:
Comment #10
punamshelkeHi,
I have imported migration in the same way and its working for me.
now i have to print the report like total counts etc.
like response printing after drush command..
is their any way to print?
Comment #11
sgurlt commentedHey,
I would try it like this:
https://stackoverflow.com/a/6674348/1565249
Cheers
Comment #12
punamshelkeHi,
Can we add limit to execute the migration as i have to import content in batch of 100...
I am executing migration through programmatically...
Thanks
Comment #13
drikc commentedFound that, by using the migrate_tools module you can re-write the example in #3 as follow which allows to pass some options:
Comment #14
aperedos commentedThere are any way to execute an update of a migrate programmatically?
Comment #15
jackbravo commentedThe way shown here helped me a lot. And combined with the embbeded_data plugin I found that you can execute a migration with a data array if you already have the data in PHP.
Comment #16
jackbravo commentedJust don't use this approach to do a migration inception (launching a migration from inside another migration) because at least on the ProcessPlugin where I tried doing that it ended up breaking the --limit parameter when launching a migration from drush that was using another migration inside of it.
Comment #17
jnrmprd commentedI wanted to launch a migration with an update option, so I've use that (taken from the Drush Command migrate_tools.drush.inc):
Comment #18
seth.e.shaw commented@jackbravo, where did you find the embedded_data plugin you mentioned in #15? That would be really useful right now.
Edit: never mind; I found it. It is a core plugin.
Comment #19
tiagopastor commented#17 works for me, thanks
Comment #20
annie2512 commented#15 worked well for me.
I wanted to change the source plugin urls dynamically( the changed part of the urls is the API version which is imported in a previous migration, and stored in a config field).
I implemented it using an event subscriber on migration pre-import event, but somehow the first time I ran the import the API version values were not being changed. This method works all the time. Thanks @jackbravo
Comment #21
buenos commentedIs it possible to execute a group migration in a similar way?
With Drush we would do smth like "drush migrate:import --group=my_group".
How would one execute that from code when there is no migration id to be passed?