Commit 7ca0caf4 authored by catch's avatar catch

Issue #2818799 by claudiu.cristea: MigrateSkipRowException being TRUE, does...

Issue #2818799 by claudiu.cristea: MigrateSkipRowException  being TRUE, does not skip silently as should
parent 94a397af
......@@ -229,7 +229,9 @@ public function import() {
$save = FALSE;
}
catch (MigrateSkipRowException $e) {
$id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_IGNORED);
if ($e->getSaveToMap()) {
$id_map->saveIdMapping($row, [], MigrateIdMapInterface::STATUS_IGNORED);
}
$save = FALSE;
}
......
<?php
namespace Drupal\migrate_prepare_row_test\Plugin\migrate\process;
use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\MigrateSkipRowException;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;
/**
* Provides a testing process plugin that skips rows.
*
* @MigrateProcessPlugin(
* id = "test_skip_row_process"
* )
*/
class TestSkipRowProcess extends ProcessPluginBase {
/**
* {@inheritdoc}
*/
public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
// Test both options for save_to_map.
$data = $row->getSourceProperty('data');
if ($data == 'skip_and_record (use plugin)') {
throw new MigrateSkipRowException('', TRUE);
}
elseif ($data == 'skip_and_dont_record (use plugin)') {
throw new MigrateSkipRowException('', FALSE);
}
return $value;
}
}
......@@ -62,6 +62,30 @@ public function testPrepareRowSkip() {
$map_row = $id_map_plugin->getRowBySource(['id' => 2]);
$this->assertFalse($map_row);
// Insert a custom processor in the process flow.
$definition['process']['value'] = [
'source' => 'data',
'plugin' => 'test_skip_row_process',
];
// Change data to avoid triggering again hook_migrate_prepare_row().
$definition['source']['data_rows'] = [
['id' => '1', 'data' => 'skip_and_record (use plugin)'],
['id' => '2', 'data' => 'skip_and_dont_record (use plugin)'],
];
$migration = \Drupal::service('plugin.manager.migration')->createStubMigration($definition);
$executable = new MigrateExecutable($migration, new MigrateMessage());
$result = $executable->import();
$this->assertEquals($result, MigrationInterface::RESULT_COMPLETED);
$id_map_plugin = $migration->getIdMap();
// The first row is recorded in the map as ignored.
$map_row = $id_map_plugin->getRowBySource(['id' => 1]);
$this->assertEquals(MigrateIdMapInterface::STATUS_IGNORED, $map_row['source_row_status']);
// The second row is not recorded in the map.
$map_row = $id_map_plugin->getRowBySource(['id' => 2]);
$this->assertFalse($map_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