summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathaniel Catchpole2017-05-26 11:00:06 +0100
committerNathaniel Catchpole2017-05-26 11:00:06 +0100
commit0bff624582a09345937f3cf5c7d8bf89c8123e4d (patch)
tree405aa687a6ea0b756a37608cf733585cb256b5b8
parent68d8cd2608ce6421f396f4a7081ec60e0c38a803 (diff)
Issue #2872812 by rakesh.gectcr, cosmicdreams, mikeryan: Create process plugin to log a message
-rw-r--r--core/modules/migrate/src/Plugin/migrate/process/Log.php42
-rw-r--r--core/modules/migrate/tests/src/Kernel/Plugin/LogTest.php36
2 files changed, 78 insertions, 0 deletions
diff --git a/core/modules/migrate/src/Plugin/migrate/process/Log.php b/core/modules/migrate/src/Plugin/migrate/process/Log.php
new file mode 100644
index 0000000..af262ff
--- /dev/null
+++ b/core/modules/migrate/src/Plugin/migrate/process/Log.php
@@ -0,0 +1,42 @@
+<?php
+
+namespace Drupal\migrate\Plugin\migrate\process;
+
+use Drupal\migrate\MigrateExecutableInterface;
+use Drupal\migrate\ProcessPluginBase;
+use Drupal\migrate\Row;
+
+
+/**
+ * Logs values without changing them.
+ *
+ * The log plugin will log the values that are being processed by other plugins.
+ *
+ * Example:
+ * @code
+ * process:
+ * bar:
+ * plugin: log
+ * source: foo
+ * @endcode
+ *
+ * @see \Drupal\migrate\Plugin\MigrateProcessInterface
+ *
+ * @MigrateProcessPlugin(
+ * id = "log"
+ * )
+ */
+class Log extends ProcessPluginBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
+ // Log the value.
+ $migrate_executable->saveMessage($value);
+
+ // Pass through the same value we received.
+ return $value;
+ }
+
+}
diff --git a/core/modules/migrate/tests/src/Kernel/Plugin/LogTest.php b/core/modules/migrate/tests/src/Kernel/Plugin/LogTest.php
new file mode 100644
index 0000000..d861d6d
--- /dev/null
+++ b/core/modules/migrate/tests/src/Kernel/Plugin/LogTest.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace Drupal\Tests\migrate\Kernel\Plugin;
+
+use Drupal\KernelTests\KernelTestBase;
+use Drupal\migrate\MigrateExecutableInterface;
+use Drupal\migrate\Row;
+
+/**
+ * Tests the Log process plugin.
+ *
+ * @group migrate
+ */
+class LogTest extends KernelTestBase {
+
+ /**
+ * {@inheritdoc}
+ */
+ public static $modules = ['migrate'];
+
+ /**
+ * Test the Log plugin
+ */
+ public function testLog() {
+ $plugin = \Drupal::service('plugin.manager.migrate.process')
+ ->createInstance('log');
+ $executable = $this->prophesize(MigrateExecutableInterface::class)->reveal();
+ $row = new Row();
+ $log_message = "Testing the log message";
+
+ //Ensure the log is getting saved
+ $saved_message = $plugin->transform($log_message, $executable, $row, 'buffalo');
+ $this->assertSame($log_message, $saved_message);
+ }
+
+}