Issue #2818871 by claudiu.cristea, mikeryan: Allow logging skip row exception messages
parent
bd4f17921f
commit
bc7dcc916e
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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'] = [
|
||||
|
|
Loading…
Reference in New Issue