class MigrationImportSync in Migrate Tools 8.4
Same name and namespace in other branches
- 8.5 src/EventSubscriber/MigrationImportSync.php \Drupal\migrate_tools\EventSubscriber\MigrationImportSync
Import and sync source and destination.
Hierarchy
- class \Drupal\migrate_tools\EventSubscriber\MigrationImportSync implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
Expanded class hierarchy of MigrationImportSync
1 string reference to 'MigrationImportSync'
1 service uses MigrationImportSync
File
- src/
EventSubscriber/ MigrationImportSync.php, line 17
Namespace
Drupal\migrate_tools\EventSubscriberView source
class MigrationImportSync implements EventSubscriberInterface {
/**
* The event dispatcher.
*
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
*/
protected $dispatcher;
/**
* MigrationImportSync constructor.
*
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
* The event dispatcher.
*/
public function __construct(EventDispatcherInterface $dispatcher) {
$this->dispatcher = $dispatcher;
}
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
$events = [];
$events[MigrateEvents::PRE_IMPORT][] = [
'sync',
];
return $events;
}
/**
* Event callback to sync source and destination.
*
* @param \Drupal\migrate\Event\MigrateImportEvent $event
* The migration import event.
*/
public function sync(MigrateImportEvent $event) {
$migration = $event
->getMigration();
if (!empty($migration->syncSource)) {
$id_map = $migration
->getIdMap();
$id_map
->prepareUpdate();
$source = $migration
->getSourcePlugin();
$source
->rewind();
$source_id_values = [];
while ($source
->valid()) {
$source_id_values[] = $source
->current()
->getSourceIdValues();
$source
->next();
}
$id_map
->rewind();
$destination = $migration
->getDestinationPlugin();
while ($id_map
->valid()) {
$map_source_id = $id_map
->currentSource();
if (!in_array($map_source_id, $source_id_values, TRUE)) {
$destination_ids = $id_map
->currentDestination();
$this
->dispatchRowDeleteEvent(MigrateEvents::PRE_ROW_DELETE, $migration, $destination_ids);
$this
->dispatchRowDeleteEvent(MigratePlusEvents::MISSING_SOURCE_ITEM, $migration, $destination_ids);
$destination
->rollback($destination_ids);
$this
->dispatchRowDeleteEvent(MigrateEvents::POST_ROW_DELETE, $migration, $destination_ids);
$id_map
->delete($map_source_id);
}
$id_map
->next();
}
$this->dispatcher
->dispatch(MigrateEvents::POST_ROLLBACK, new MigrateRollbackEvent($migration));
}
}
/**
* Dispatches MigrateRowDeleteEvent event.
*
* @param string $event_name
* The event name to dispatch.
* @param \Drupal\migrate\Plugin\MigrationInterface $migration
* The active migration.
* @param array $destination_ids
* The destination identifier values of the record.
*/
protected function dispatchRowDeleteEvent($event_name, MigrationInterface $migration, array $destination_ids) {
// Symfony changing dispatcher so implementation could change.
$this->dispatcher
->dispatch($event_name, new MigrateRowDeleteEvent($migration, $destination_ids));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrationImportSync:: |
protected | property | The event dispatcher. | |
MigrationImportSync:: |
protected | function | Dispatches MigrateRowDeleteEvent event. | |
MigrationImportSync:: |
public static | function | Returns an array of event names this subscriber wants to listen to. | |
MigrationImportSync:: |
public | function | Event callback to sync source and destination. | |
MigrationImportSync:: |
public | function | MigrationImportSync constructor. |