Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save brooke-heaton/09c702f4f1b02fd0fb54011ecd648432 to your computer and use it in GitHub Desktop.
Save brooke-heaton/09c702f4f1b02fd0fb54011ecd648432 to your computer and use it in GitHub Desktop.
Drupal 8 Event Subscriber to trigger a function to drop a mySql table and import data from a file
<?php
/**
* @file
* Contains \Drupal\migrate\Event\MigrateEvent.
*/
namespace Drupal\my_migration\Event;
use Drupal\migrate\Event\MigrateEvents;
use Drupal\migrate\Event\MigrateImportEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MyMigrationMigrationEventSubscriber implements EventSubscriberInterface {
/**
* {@inheritdoc}
*/
static function getSubscribedEvents() {
$events[MigrateEvents::PRE_IMPORT][] = ['preImport'];
return $events;
}
public function preImport(MigrateImportEvent $event) {
if ($event->getMigration()->getPluginId() === 'section' || 'subject') {
my_migration_refresh_tables();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment