Commit 226c3a13 authored by Derimagia's avatar Derimagia

Inital Commit

parents
# Migrate Devel
Adds new options to `drush migrate-import` which allows developers to debug their migrations.
`drush migrate-import` comes from either the [migrate_tools](https://www.drupal.org/project/migrate_tools) or the [migrate_run](https://www.drupal.org/project/migrate_run) modules.
Currently uses Kint (from devel) directly to print out debug information instead of devel in order to take advantage of cli coloring and named variable debugging.
Options are:
* `--migrate-debug` - Prints out rows as they run.
* `--migrate-debug-pre` - Same as above, but before the migration is run on the row.
<?php
/**
* Implements hook_drush_help_alter().
*/
function migrate_devel_drush_help_alter(&$command) {
if ($command['command'] == 'migrate-import') {
$command['options']['migrate-debug'] = 'Enable Debug Mode';
$command['options']['migrate-debug-pre'] = 'Enable Debug Mode (Before Row Save)';
}
}
name: Migrate Devel
description: Migrate Development Tools
package: Migrate
type: module
core: 8.x
dependencies:
- devel
- migrate
- kint
services:
migrate_devel.migrate_event_subscriber:
class: Drupal\migrate_devel\EventSubscriber\MigrationEventSubscriber
tags:
- { name: event_subscriber }
\ No newline at end of file
<?php
namespace Drupal\migrate_devel\EventSubscriber;
use Drupal\migrate\Event\MigrateEvents;
use Drupal\migrate\Event\MigratePostRowSaveEvent;
use Drupal\migrate\Event\MigratePreRowSaveEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/**
* MigrationEventSubscriber for Debugging Migrations
*/
class MigrationEventSubscriber implements EventSubscriberInterface {
/**
* Pre Row Save Function
* @param \Drupal\migrate\Event\MigratePreRowSaveEvent $event
*/
public function debugRowPreSave(MigratePreRowSaveEvent $event) {
$row = $event->getRow();
if (function_exists('drush_get_option') && drush_get_option('migrate-debug-pre')) {
$Source = $row->getSource();
$Destination = $row->getDestination();
kint_require();
\Kint::dump($Source, $Destination);
}
}
/**
* Post Row Save Function
* @param \Drupal\migrate\Event\MigratePostRowSaveEvent $event
*/
public function debugRowPostSave(MigratePostRowSaveEvent $event) {
$row = $event->getRow();
if (function_exists('drush_get_option') && drush_get_option('migrate-debug')) {
$Source = $row->getSource();
$Destination = $row->getDestination();
$DestinationIDValues = $event->getDestinationIdValues();
kint_require();
\Kint::dump($Source, $Destination, $DestinationIDValues);
}
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events[MigrateEvents::PRE_ROW_SAVE][] = ['debugRowPreSave'];
$events[MigrateEvents::POST_ROW_SAVE][] = ['debugRowPostSave'];
return $events;
}
}
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