Migrate sync delete existing items. Not update item.
Issue #3110335 on drupal.org by keopx.
Problem/Motivation
Sync option delete all existing items.
Sync not update items.
use Drupal\migrate_tools\MigrateExecutable;
function _custom_migrate_main_update($migration_group = '') {
$migration_group = 'main';
/** @var \Drupal\migrate\Plugin\MigrationPluginManager $migration_plugin_manager */
$migration_plugin_manager = \Drupal::service('plugin.manager.migration');
$migrations = $migration_plugin_manager->getDefinitions();
foreach ($migrations as $migration) {
if (isset($migration['migration_group']) && $migration['migration_group'] === $migration_group) {
/** @var \Drupal\migrate\Plugin\Migration $migration */
$migration = \Drupal::service('plugin.manager.migration')->createInstance($migration['id']);
if ($migration) {
try {
$migration->set('syncSource', TRUE);
$migration->getIdMap()->prepareUpdate();
$executable = new MigrateExecutable($migration, new MigrateMessage());
$executable->import();
}
catch (MigrateException $exception) {
watchdog_exception('Migration Main', $exception, $exception->getMessage());
}
}
}
}
}
I tried doing the same using options but that's not works:
$executable = new MigrateExecutable($migration, new MigrateMessage(), ['sync' => TRUE]);
Proposed resolution
Sync option: delete and update import items.
Using this command not update existing or creating new values.
drush mim --group=main --update --sync