Snippets

Oleksiy Kalinichenko Custom fix for the "migration" core module to add option "debug" property to migrate process plugin

Created by Oleksiy Kalinichenko
diff -rupN a/modules/migrate/src/MigrateExecutable.php b/modules/migrate/src/MigrateExecutable.php
--- a/modules/migrate/src/MigrateExecutable.php	2018-10-18 01:19:50.000000000 +0300
+++ b/modules/migrate/src/MigrateExecutable.php	2018-11-04 21:30:29.576123973 +0200
@@ -379,7 +379,9 @@ class MigrateExecutable implements Migra
         }
         else {
           try {
+            $plugin->debugBeforeOut($value);
             $value = $plugin->transform($value, $this, $row, $destination);
+            $plugin->debugAfterOut($value);
           }
           catch (MigrateSkipProcessException $e) {
             $value = NULL;
diff -rupN a/modules/migrate/src/ProcessPluginBase.php b/modules/migrate/src/ProcessPluginBase.php
--- a/modules/migrate/src/ProcessPluginBase.php	2018-10-18 01:19:50.000000000 +0300
+++ b/modules/migrate/src/ProcessPluginBase.php	2018-11-04 21:30:29.592123796 +0200
@@ -45,4 +45,43 @@ abstract class ProcessPluginBase extends
     return FALSE;
   }
 
+  /**
+   * @param $value
+   */
+  public function debugBeforeOut($value) {
+    $debug = $this->configuration['debug'] ?? false;
+    $configuration = $this->configuration;
+    unset($configuration['debug']);
+    unset($configuration['plugin']);
+    if (PHP_SAPI === 'cli' && $debug ) {
+      drush_print('Plugin ID: ' . $this->getPluginId());
+      drush_print('In: ', 0, null, false );
+      $this->printValue($value);
+    }
+  }
+
+  /**
+   * @param $value
+   */
+  public function debugAfterOut($value) {
+    $debug = $this->configuration['debug'] ?? false;
+    if (PHP_SAPI === 'cli' && $debug ) {
+      drush_print('Out: ', 0, null, false );
+      $this->printValue($value);
+      drush_print_r('====================');
+    }
+  }
+
+  /**
+   * @param $value
+   */
+  private function printValue($value) {
+    if (is_string($value)) {
+      drush_print('\'' . $value . '\'');
+    }
+    else {
+      drush_print_r($value);
+    }
+  }
+
 }

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.