Commit 9cf72c60 authored by catch's avatar catch

Issue #2864563 by Jo Fitzgerald, NickWilde, larowlan, gaurav.kapoor, heddn:...

Issue #2864563 by Jo Fitzgerald, NickWilde, larowlan, gaurav.kapoor, heddn: Migration lookup process plugin doesn't call setMessage on the migration idMap
parent 82284fa0
......@@ -96,7 +96,7 @@ class MigrateExecutable implements MigrateExecutableInterface {
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The migration to run.
* @param \Drupal\migrate\MigrateMessageInterface $message
* The message to record.
* The migrate message service.
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
* The event dispatcher.
*
......
......@@ -268,10 +268,10 @@ public function destroy();
public function getQualifiedMapTableName();
/**
* Sets the migrate message.
* Sets the migrate message service.
*
* @param \Drupal\migrate\MigrateMessageInterface $message
* The message to display.
* The migrate message service.
*/
public function setMessage(MigrateMessageInterface $message);
......
......@@ -6,6 +6,7 @@
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\migrate\MigrateMessage;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate\Event\MigrateIdMapMessageEvent;
use Drupal\migrate\MigrateException;
......@@ -55,7 +56,7 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
protected $messageTableName;
/**
* The migrate message.
* The migrate message service.
*
* @var \Drupal\migrate\MigrateMessageInterface
*/
......@@ -156,6 +157,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migration = $migration;
$this->eventDispatcher = $event_dispatcher;
$this->message = new MigrateMessage();
}
/**
......
......@@ -222,15 +222,16 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
// Do a normal migration with the stub row.
$migrate_executable->processRow($stub_row, $process);
$destination_ids = [];
$id_map = $migration->getIdMap();
try {
$destination_ids = $destination_plugin->import($stub_row);
}
catch (\Exception $e) {
$migration->getIdMap()->saveMessage($stub_row->getSourceIdValues(), $e->getMessage());
$id_map->saveMessage($stub_row->getSourceIdValues(), $e->getMessage());
}
if ($destination_ids) {
$migration->getIdMap()->saveIdMapping($stub_row, $destination_ids, MigrateIdMapInterface::STATUS_NEEDS_UPDATE);
$id_map->saveIdMapping($stub_row, $destination_ids, MigrateIdMapInterface::STATUS_NEEDS_UPDATE);
}
}
if ($destination_ids) {
......
......@@ -199,4 +199,43 @@ public function successfulLookupDataProvider() {
];
}
/**
* Tests that a message is successfully created if import fails.
*/
public function testImportException() {
$migration_plugin = $this->prophesize(MigrationInterface::class);
$migration_plugin_manager = $this->prophesize(MigrationPluginManagerInterface::class);
$process_plugin_manager = $this->prophesize(MigratePluginManager::class);
$destination_id_map = $this->prophesize(MigrateIdMapInterface::class);
$destination_migration = $this->prophesize('Drupal\migrate\Plugin\Migration');
$destination_migration->getIdMap()->willReturn($destination_id_map->reveal());
$migration_plugin_manager->createInstances(['destination_migration'])
->willReturn(['destination_migration' => $destination_migration->reveal()]);
$destination_id_map->lookupDestinationId([1])->willReturn(NULL);
$destination_id_map->saveMessage(Argument::any(), Argument::any())->willReturn(NULL);
$destination_id_map->saveIdMapping(Argument::any(), Argument::any(), Argument::any())->shouldNotBeCalled();
$configuration = [
'no_stub' => FALSE,
'migration' => 'destination_migration',
];
$destination_migration->id()->willReturn('destination_migration');
$destination_migration->getDestinationPlugin(TRUE)->shouldBeCalled();
$destination_migration->getProcess()->willReturn([]);
$destination_migration->getSourceConfiguration()->willReturn([]);
$source_plugin = $this->prophesize(MigrateSourceInterface::class);
$source_plugin->getIds()->willReturn(['nid']);
$destination_migration->getSourcePlugin()->willReturn($source_plugin->reveal());
$destination_plugin = $this->prophesize(MigrateDestinationInterface::class);
$e = new \Exception();
$destination_plugin->import(Argument::any())->willThrow($e);
$destination_migration->getDestinationPlugin(TRUE)->willReturn($destination_plugin->reveal());
$migration = new MigrationLookup($configuration, '', [], $migration_plugin->reveal(), $migration_plugin_manager->reveal(), $process_plugin_manager->reveal());
$migration->transform(1, $this->migrateExecutable, $this->row, '');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment