Loading core/modules/migrate/src/MigrateExecutable.php +8 −1 Original line number Diff line number Diff line Loading @@ -425,6 +425,7 @@ protected function processPipeline(Row $row, string $destination, array $plugins } $break = FALSE; foreach ($value as $scalar_value) { $plugin->reset(); try { $new_value[] = $plugin->transform($scalar_value, $this, $row, $destination); } Loading @@ -437,6 +438,9 @@ protected function processPipeline(Row $row, string $destination, array $plugins $message = sprintf("%s: %s", $plugin->getPluginId(), $e->getMessage()); throw new MigrateException($message); } if ($plugin->isPipelineStopped()) { $break = TRUE; } } $value = $new_value; if ($break) { Loading @@ -444,6 +448,7 @@ protected function processPipeline(Row $row, string $destination, array $plugins } } else { $plugin->reset(); try { $value = $plugin->transform($value, $this, $row, $destination); } Loading @@ -456,7 +461,9 @@ protected function processPipeline(Row $row, string $destination, array $plugins $message = sprintf("%s: %s", $plugin->getPluginId(), $e->getMessage()); throw new MigrateException($message); } if ($plugin->isPipelineStopped()) { break; } $multiple = $plugin->multiple(); } } Loading core/modules/migrate/src/Plugin/MigrateProcessInterface.php +13 −0 Original line number Diff line number Diff line Loading @@ -52,4 +52,17 @@ public function transform($value, MigrateExecutableInterface $migrate_executable */ public function multiple(); /** * Determines if the pipeline should stop processing. * * @return bool * A boolean value indicating if the pipeline processing should stop. */ public function isPipelineStopped(): bool; /** * Resets the internal data of a plugin. */ public function reset(): void; } core/modules/migrate/src/Plugin/migrate/process/SkipOnEmpty.php +2 −2 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ namespace Drupal\migrate\Plugin\migrate\process; use Drupal\migrate\MigrateSkipProcessException; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; Loading Loading @@ -131,7 +130,8 @@ public function row($value, MigrateExecutableInterface $migrate_executable, Row */ public function process($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { if (!$value) { throw new MigrateSkipProcessException(); $this->stopPipeline(); return NULL; } return $value; } Loading core/modules/migrate/src/ProcessPluginBase.php +28 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,13 @@ */ abstract class ProcessPluginBase extends PluginBase implements MigrateProcessInterface { /** * Determines if processing of the pipeline is stopped. * * @var bool */ protected bool $stopPipeline = FALSE; /** * {@inheritdoc} */ Loading @@ -53,4 +60,25 @@ public function multiple() { return FALSE; } /** * {@inheritdoc} */ public function isPipelineStopped(): bool { return $this->stopPipeline; } /** * {@inheritdoc} */ public function reset(): void { $this->stopPipeline = FALSE; } /** * Stops pipeline processing after this plugin finishes. */ protected function stopPipeline(): void { $this->stopPipeline = TRUE; } } core/modules/migrate/tests/src/Kernel/MigrateProcessErrorMessagesTest.php +1 −0 Original line number Diff line number Diff line Loading @@ -150,6 +150,7 @@ protected function setPluginManagers() { $error_plugin_prophecy = $this->prophesize(MigrateProcessInterface::class); $error_plugin_prophecy->getPluginDefinition()->willReturn(['plugin_id' => 'test_error']); $error_plugin_prophecy->getPluginId()->willReturn('test_error'); $error_plugin_prophecy->reset()->shouldBeCalled(); $error_plugin_prophecy->transform(Argument::cetera())->willThrow(new MigrateException('Process exception.')); $this->processPluginManager->createInstance('get', Argument::cetera()) Loading Loading
core/modules/migrate/src/MigrateExecutable.php +8 −1 Original line number Diff line number Diff line Loading @@ -425,6 +425,7 @@ protected function processPipeline(Row $row, string $destination, array $plugins } $break = FALSE; foreach ($value as $scalar_value) { $plugin->reset(); try { $new_value[] = $plugin->transform($scalar_value, $this, $row, $destination); } Loading @@ -437,6 +438,9 @@ protected function processPipeline(Row $row, string $destination, array $plugins $message = sprintf("%s: %s", $plugin->getPluginId(), $e->getMessage()); throw new MigrateException($message); } if ($plugin->isPipelineStopped()) { $break = TRUE; } } $value = $new_value; if ($break) { Loading @@ -444,6 +448,7 @@ protected function processPipeline(Row $row, string $destination, array $plugins } } else { $plugin->reset(); try { $value = $plugin->transform($value, $this, $row, $destination); } Loading @@ -456,7 +461,9 @@ protected function processPipeline(Row $row, string $destination, array $plugins $message = sprintf("%s: %s", $plugin->getPluginId(), $e->getMessage()); throw new MigrateException($message); } if ($plugin->isPipelineStopped()) { break; } $multiple = $plugin->multiple(); } } Loading
core/modules/migrate/src/Plugin/MigrateProcessInterface.php +13 −0 Original line number Diff line number Diff line Loading @@ -52,4 +52,17 @@ public function transform($value, MigrateExecutableInterface $migrate_executable */ public function multiple(); /** * Determines if the pipeline should stop processing. * * @return bool * A boolean value indicating if the pipeline processing should stop. */ public function isPipelineStopped(): bool; /** * Resets the internal data of a plugin. */ public function reset(): void; }
core/modules/migrate/src/Plugin/migrate/process/SkipOnEmpty.php +2 −2 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ namespace Drupal\migrate\Plugin\migrate\process; use Drupal\migrate\MigrateSkipProcessException; use Drupal\migrate\ProcessPluginBase; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\Row; Loading Loading @@ -131,7 +130,8 @@ public function row($value, MigrateExecutableInterface $migrate_executable, Row */ public function process($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) { if (!$value) { throw new MigrateSkipProcessException(); $this->stopPipeline(); return NULL; } return $value; } Loading
core/modules/migrate/src/ProcessPluginBase.php +28 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,13 @@ */ abstract class ProcessPluginBase extends PluginBase implements MigrateProcessInterface { /** * Determines if processing of the pipeline is stopped. * * @var bool */ protected bool $stopPipeline = FALSE; /** * {@inheritdoc} */ Loading @@ -53,4 +60,25 @@ public function multiple() { return FALSE; } /** * {@inheritdoc} */ public function isPipelineStopped(): bool { return $this->stopPipeline; } /** * {@inheritdoc} */ public function reset(): void { $this->stopPipeline = FALSE; } /** * Stops pipeline processing after this plugin finishes. */ protected function stopPipeline(): void { $this->stopPipeline = TRUE; } }
core/modules/migrate/tests/src/Kernel/MigrateProcessErrorMessagesTest.php +1 −0 Original line number Diff line number Diff line Loading @@ -150,6 +150,7 @@ protected function setPluginManagers() { $error_plugin_prophecy = $this->prophesize(MigrateProcessInterface::class); $error_plugin_prophecy->getPluginDefinition()->willReturn(['plugin_id' => 'test_error']); $error_plugin_prophecy->getPluginId()->willReturn('test_error'); $error_plugin_prophecy->reset()->shouldBeCalled(); $error_plugin_prophecy->transform(Argument::cetera())->willThrow(new MigrateException('Process exception.')); $this->processPluginManager->createInstance('get', Argument::cetera()) Loading