Commit 32a53442 authored by webchick's avatar webchick

Issue #2559571 by mikeryan, benjy, phenaproxima, quietone: Handle...

Issue #2559571 by mikeryan, benjy, phenaproxima, quietone: Handle MigrateException consistently during import
parent 24e346cc
......@@ -255,6 +255,11 @@ public function import() {
$this->processRow($row);
$save = TRUE;
}
catch (MigrateException $e) {
$this->migration->getIdMap()->saveIdMapping($row, array(), $e->getStatus(), $this->rollbackAction);
$this->saveMessage($e->getMessage(), $e->getLevel());
$save = FALSE;
}
catch (MigrateSkipRowException $e) {
$id_map->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_IGNORED, $this->rollbackAction);
$save = FALSE;
......@@ -283,7 +288,6 @@ public function import() {
catch (MigrateException $e) {
$this->migration->getIdMap()->saveIdMapping($row, array(), $e->getStatus(), $this->rollbackAction);
$this->saveMessage($e->getMessage(), $e->getLevel());
$this->message->display($e->getMessage(), 'error');
}
catch (\Exception $e) {
$this->migration->getIdMap()->saveIdMapping($row, array(), MigrateIdMapInterface::STATUS_FAILED, $this->rollbackAction);
......
......@@ -227,9 +227,10 @@ public function testImportWithValidRowNoDestinationValues() {
}
/**
* Tests the import method with a MigrateException being thrown.
* Tests the import method with a MigrateException being thrown from the
* destination.
*/
public function testImportWithValidRowWithMigrateException() {
public function testImportWithValidRowWithDestinationMigrateException() {
$exception_message = $this->getRandomGenerator()->string();
$source = $this->getMockSource();
......@@ -268,10 +269,6 @@ public function testImportWithValidRowWithMigrateException() {
$this->idMap->expects($this->once())
->method('saveMessage');
$this->message->expects($this->once())
->method('display')
->with($exception_message);
$this->idMap->expects($this->once())
->method('lookupDestinationId')
->with(array('id' => 'test'))
......@@ -280,6 +277,53 @@ public function testImportWithValidRowWithMigrateException() {
$this->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable->import());
}
/**
* Tests the import method with a MigrateException being thrown from a process
* plugin.
*/
public function testImportWithValidRowWithProcesMigrateException() {
$exception_message = $this->getRandomGenerator()->string();
$source = $this->getMockSource();
$row = $this->getMockBuilder('Drupal\migrate\Row')
->disableOriginalConstructor()
->getMock();
$row->expects($this->once())
->method('getSourceIdValues')
->willReturn(array('id' => 'test'));
$source->expects($this->once())
->method('current')
->willReturn($row);
$this->executable->setSource($source);
$this->migration->expects($this->once())
->method('getProcessPlugins')
->willThrowException(new MigrateException($exception_message));
$destination = $this->getMock('Drupal\migrate\Plugin\MigrateDestinationInterface');
$destination->expects($this->never())
->method('import');
$this->migration->expects($this->once())
->method('getDestinationPlugin')
->willReturn($destination);
$this->idMap->expects($this->once())
->method('saveIdMapping')
->with($row, array(), MigrateIdMapInterface::STATUS_FAILED, NULL);
$this->idMap->expects($this->once())
->method('saveMessage');
$this->idMap->expects($this->never())
->method('lookupDestinationId');
$this->assertSame(MigrationInterface::RESULT_COMPLETED, $this->executable->import());
}
/**
* Tests the import method with a regular Exception being thrown.
*/
......
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