summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-08-18 06:10:30 (GMT)
committerNathaniel Catchpole2017-08-18 06:10:30 (GMT)
commit9cf72c6086e8b5d2fcfb6a3968a5f615d0af2038 (patch)
treec8ab9b922a7510954843edc5501d5e63dac36e33
parent82284fa0bbc8deb689bad2c652902e8f9525bc87 (diff)
Issue #2864563 by Jo Fitzgerald, NickWilde, larowlan, gaurav.kapoor, heddn: Migration lookup process plugin doesn't call setMessage on the migration idMap
-rw-r--r--core/modules/migrate/src/MigrateExecutable.php2
-rw-r--r--core/modules/migrate/src/Plugin/MigrateIdMapInterface.php4
-rw-r--r--core/modules/migrate/src/Plugin/migrate/id_map/Sql.php4
-rw-r--r--core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php5
-rw-r--r--core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php39
5 files changed, 48 insertions, 6 deletions
diff --git a/core/modules/migrate/src/MigrateExecutable.php b/core/modules/migrate/src/MigrateExecutable.php
index e8316e4..8a593f2 100644
--- a/core/modules/migrate/src/MigrateExecutable.php
+++ b/core/modules/migrate/src/MigrateExecutable.php
@@ -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.
*
diff --git a/core/modules/migrate/src/Plugin/MigrateIdMapInterface.php b/core/modules/migrate/src/Plugin/MigrateIdMapInterface.php
index 7ba0168..ad57a80 100644
--- a/core/modules/migrate/src/Plugin/MigrateIdMapInterface.php
+++ b/core/modules/migrate/src/Plugin/MigrateIdMapInterface.php
@@ -268,10 +268,10 @@ interface MigrateIdMapInterface extends \Iterator, PluginInspectionInterface {
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);
diff --git a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
index 27b7569..6bdd51e 100644
--- a/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
+++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
@@ -6,6 +6,7 @@ use Drupal\Component\Utility\Unicode;
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 @@ class Sql extends PluginBase implements MigrateIdMapInterface, ContainerFactoryP
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->migration = $migration;
$this->eventDispatcher = $event_dispatcher;
+ $this->message = new MigrateMessage();
}
/**
diff --git a/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php b/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php
index 835fd69..5f144a4 100644
--- a/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php
+++ b/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php
@@ -222,15 +222,16 @@ class MigrationLookup extends ProcessPluginBase implements ContainerFactoryPlugi
// 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) {
diff --git a/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php b/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php
index f30c184..dd18928 100644
--- a/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php
+++ b/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php
@@ -199,4 +199,43 @@ class MigrationLookupTest extends MigrateProcessTestCase {
];
}
+ /**
+ * 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, '');
+ }
+
}