Skip to content

Commit

Permalink
Fixes #3866 Update AZEnterpriseAttributesMigrationSync
Browse files Browse the repository at this point in the history
  • Loading branch information
Troy Dean committed Nov 5, 2024
1 parent 906fe14 commit d92668f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"drupal/metatag": "2.0.2",
"drupal/migrate_plus": "6.0.4",
"drupal/migrate_queue_importer": "2.1.1",
"drupal/migrate_tools": "6.0.4",
"drupal/migrate_tools": "6.0.5",
"drupal/optional_end_date": "1.4.0",
"drupal/paragraphs": "1.18.0",
"drupal/paragraphs_admin": "1.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
decorates: migrate_tools.migration_sync
arguments:
- '@event_dispatcher'
- '@state'
- '@migrate_tools.migrate_tools'
- '@entity_type.manager'
- '@logger.channel.az_enterprise_attributes_import'
logger.channel.az_enterprise_attributes_import:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Logger\LoggerChannel;
use Drupal\Core\State\StateInterface;
use Drupal\migrate\Event\MigrateImportEvent;
use Drupal\migrate_tools\EventSubscriber\MigrationImportSync;
use Drupal\migrate_tools\MigrateTools;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
Expand All @@ -31,17 +31,16 @@ final class AZEnterpriseAttributesMigrationSync extends MigrationImportSync {
*
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher
* The event dispatcher.
* @param \Drupal\Core\State\StateInterface $state
* The Key/Value Store to use for tracking synced source rows.
* @param \Drupal\migrate_tools\MigrateTools $migrateTools
* The MigrateTools helper for source id tracking.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager service.
* @param \Drupal\Core\Logger\LoggerChannel $logger
* The logger channel service.
*/
public function __construct(EventDispatcherInterface $dispatcher, StateInterface $state, EntityTypeManagerInterface $entityTypeManager, LoggerChannel $logger) {
public function __construct(EventDispatcherInterface $dispatcher, MigrateTools $migrateTools, EntityTypeManagerInterface $entityTypeManager, LoggerChannel $logger) {
$this->dispatcher = $dispatcher;
$this->state = $state;
$this->state->set('migrate_tools_sync', []);
$this->migrateTools = $migrateTools;
$this->entityTypeManager = $entityTypeManager;
$this->logger = $logger;
}
Expand All @@ -51,12 +50,18 @@ public function __construct(EventDispatcherInterface $dispatcher, StateInterface
*/
public function sync(MigrateImportEvent $event): void {
$migration = $event->getMigration();
$migrationId = $migration->getPluginId();
// If this isn't a migration we're concerned with, use the parent.
if ($migration->id() !== 'az_enterprise_attributes_import') {
if ($migrationId !== 'az_enterprise_attributes_import') {
parent::sync($event);
return;
}
if (!empty($migration->syncSource)) {
// Clear Sync IDs for this migration before starting preparing rows.
$this->migrateTools->clearSyncSourceIds($migrationId);
// Activate the syncing state for this migration, so
// migrate_tools_migrate_prepare_row() can record all IDs.
$this->migrateTools->setMigrationSyncingState($migrationId, TRUE);

// Loop through the source to register existing source ids.
// @see migrate_tools_migrate_prepare_row().
Expand All @@ -68,7 +73,12 @@ public function sync(MigrateImportEvent $event): void {
$source->next();
}

$source_id_values = $this->state->get('migrate_tools_sync', []);
// Deactivate the syncing state for this migration, so
// migrate_tools_migrate_prepare_row() does not record any further IDs
// during the actual migration process.
$this->migrateTools->setMigrationSyncingState($migrationId, FALSE);

$source_id_values = $this->migrateTools->getSyncSourceIds($migrationId);

$id_map = $migration->getIdMap();
$id_map->rewind();
Expand Down

0 comments on commit d92668f

Please sign in to comment.