mutual_credit-5.0.x-dev/modules/clearingcentral/src/MigrationSubscriber.php
modules/clearingcentral/src/MigrationSubscriber.php
<?php namespace Drupal\mcapi_cc; use Drupal\migrate\Event\MigratePreRowSaveEvent; use Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Drupal\migrate\Event\MigrateImportEvent; /** * A hook to check the limits. */ class MigrationSubscriber implements EventSubscriberInterface { /** * {@inheritdoc} */ public static function getSubscribedEvents() : array { return [ 'migrate.pre_row_save' => [['migratePreRowSave']], 'migrate.post_import' => [['migratePostImport']] ]; } /** * * @param MigratePreRowSaveEvent $event * No ->arguments() are passed. getSubject() gives the transaction. * @param string $eventName * Which is always mcapi_transaction.assemble. * @param ContainerAwareEventDispatcher $container * The container. */ public function migratePreRowSave(MigratePreRowSaveEvent $event, $eventName, ContainerAwareEventDispatcher $container) { $migration = $event->getMigration(); if ($migration->id() == 'd7_mcapi_transaction') { $row = $event->getRow(); if ($row->getSourceProperty('type') == 'remote') { // retrive the extra transaction properties. $query = $migration->getSourcePlugin()->getDatabase() ->select('mcapi_cc', 'cc'); $query->addField('cc', 'xid', 'txid'); $query->addField('cc', 'remote_exchange_id', 'exchange_id'); $query->addField('cc', 'remote_user_id', 'user_id'); $query->addField('cc', 'remote_user_name', 'user_name'); $result = $query->condition('xid', $row->getSourceProperty('xid')) ->execute() ->fetch(); $row->setDestinationProperty('remote', $result); mcapi_cc_exchange_name_lookup($result->exchange_id); } } } /** * Notify clearing central - tim has provided a POST query. * * @param MigrateImportEvent $event */ public function migratePostImport(MigrateImportEvent $event) { // Finish the permission migration, because it didn't map 1:1 if ($event->getMigration()->id() == 'd7_user_roles') { foreach (Role::loadMultiple() as $role) { if ($role->hasPermission('create credit transaction')) { $role->grantPermission('create remote transactions'); $role->save(); } } } if ($event->getMigration()->id() == 'd7_mcapi_clearing_central_settings') { print "\nClearing Central needs to be notified of the new IP address.\n"; } } }