diff --git a/core/modules/migrate/src/MigrateExecutable.php b/core/modules/migrate/src/MigrateExecutable.php index 440ce8ea281..eacf9ae1df6 100644 --- a/core/modules/migrate/src/MigrateExecutable.php +++ b/core/modules/migrate/src/MigrateExecutable.php @@ -232,6 +232,9 @@ class MigrateExecutable implements MigrateExecutableInterface { if ($e->getSaveToMap()) { $id_map->saveIdMapping($row, [], MigrateIdMapInterface::STATUS_IGNORED); } + if ($message = trim($e->getMessage())) { + $this->saveMessage($message, MigrationInterface::MESSAGE_INFORMATIONAL); + } $save = FALSE; } diff --git a/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php b/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php index 45e2be5e0bf..6eebdeac0be 100644 --- a/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php +++ b/core/modules/migrate/src/Plugin/migrate/source/SourcePluginBase.php @@ -207,6 +207,9 @@ abstract class SourcePluginBase extends PluginBase implements MigrateSourceInter catch (MigrateSkipRowException $e) { $skip = TRUE; $save_to_map = $e->getSaveToMap(); + if ($message = trim($e->getMessage())) { + $this->idMap->saveMessage($row->getSourceIdValues(), $message, MigrationInterface::MESSAGE_INFORMATIONAL); + } } // We're explicitly skipping this row - keep track in the map table. diff --git a/core/modules/migrate/tests/modules/migrate_prepare_row_test/migrate_prepare_row_test.module b/core/modules/migrate/tests/modules/migrate_prepare_row_test/migrate_prepare_row_test.module index 66f1bd9370f..1da25f5a6d5 100644 --- a/core/modules/migrate/tests/modules/migrate_prepare_row_test/migrate_prepare_row_test.module +++ b/core/modules/migrate/tests/modules/migrate_prepare_row_test/migrate_prepare_row_test.module @@ -18,9 +18,11 @@ function migrate_prepare_row_test_migrate_prepare_row(Row $row, MigrateSourceInt // Test both options for save_to_map. $data = $row->getSourceProperty('data'); if ($data == 'skip_and_record') { + // Record mapping but don't record a message. throw new MigrateSkipRowException('', TRUE); } elseif ($data == 'skip_and_dont_record') { - throw new MigrateSkipRowException('', FALSE); + // Don't record mapping but record a message. + throw new MigrateSkipRowException('skip_and_dont_record message', FALSE); } } diff --git a/core/modules/migrate/tests/src/Kernel/MigrateSkipRowTest.php b/core/modules/migrate/tests/src/Kernel/MigrateSkipRowTest.php index 44df50178ed..3b0091d9250 100644 --- a/core/modules/migrate/tests/src/Kernel/MigrateSkipRowTest.php +++ b/core/modules/migrate/tests/src/Kernel/MigrateSkipRowTest.php @@ -54,13 +54,24 @@ class MigrateSkipRowTest extends KernelTestBase { $result = $executable->import(); $this->assertEqual($result, MigrationInterface::RESULT_COMPLETED); + /** @var \Drupal\migrate\Plugin\MigrateIdMapInterface $id_map_plugin */ $id_map_plugin = $migration->getIdMap(); // The first row is recorded in the map as ignored. $map_row = $id_map_plugin->getRowBySource(['id' => 1]); $this->assertEqual(MigrateIdMapInterface::STATUS_IGNORED, $map_row['source_row_status']); + // Check that no message has been logged for the first exception. + $messages = $id_map_plugin->getMessageIterator(['id' => 1])->fetchAll(); + $this->assertEmpty($messages); + // The second row is not recorded in the map. $map_row = $id_map_plugin->getRowBySource(['id' => 2]); $this->assertFalse($map_row); + // Check that the correct message has been logged for the second exception. + $messages = $id_map_plugin->getMessageIterator(['id' => 2])->fetchAll(); + $this->assertCount(1, $messages); + $message = reset($messages); + $this->assertEquals('skip_and_dont_record message', $message->message); + $this->assertEquals(MigrationInterface::MESSAGE_INFORMATIONAL, $message->level); // Insert a custom processor in the process flow. $definition['process']['value'] = [