Skip to content

Commit

Permalink
Merge pull request #8 from jhu-idc/batch-migration-replacement
Browse files Browse the repository at this point in the history
Batch migration replacement to fix a bad workflow for us where log messages were getting lost.
  • Loading branch information
bseeger authored Jul 20, 2021
2 parents 185ee10 + 488f184 commit d6b5a24
Show file tree
Hide file tree
Showing 7 changed files with 582 additions and 2 deletions.
3 changes: 2 additions & 1 deletion idc_migration.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ type: module
description: 'Custom migration plugins supporting IDC ingest'
core: 8.x
dependencies:
- migrate
- drupal:migrate
- migrate_source_csv:migrate_source_csv
2 changes: 1 addition & 1 deletion idc_migration.module
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/**
* @file
* A description of what your module does.
*/
*/
6 changes: 6 additions & 0 deletions idc_migration.services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
services:
idc_defaults.route_subscriber:
class: Drupal\idc_migration\Routing\RouteSubscriber
tags:
- name: event_subscriber
50 changes: 50 additions & 0 deletions src/Form/MigrateSourceUiForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Drupal\idc_migration\Form;

use Drupal\Core\Form\FormStateInterface;

use Drupal\idc_migration\MigrateBatchExecutable;
use Drupal\migrate\Plugin\MigrationInterface;
use Drupal\migrate_source_ui\Form\MigrateSourceUiForm as MigrateSourceUiFormBase;
use Drupal\migrate_source_ui\StubMigrationMessage;

/**
* Slightly extended migration execution form.
*/
class MigrateSourceUiForm extends MigrateSourceUiFormBase {

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$migration_id = $form_state->getValue('migrations');
/** @var \Drupal\migrate\Plugin\Migration $migration */
$migration = $this->pluginManagerMigration->createInstance($migration_id);

// Reset status.
$status = $migration->getStatus();
if ($status !== MigrationInterface::STATUS_IDLE) {
$migration->setStatus(MigrationInterface::STATUS_IDLE);
$this->messenger()->addWarning($this->t('Migration @id reset to Idle', ['@id' => $migration_id]));
}

$options = [];

// Prepare the migration with the path injected.
$definition = $this->pluginManagerMigration->getDefinition($migration_id);
// Override the file path.
$definition['source']['path'] = $form_state->getValue('file_path');
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */
$migration = $this->pluginManagerMigration->createStubMigration($definition);

// Force updates or not.
if ($form_state->getValue('update_existing_records')) {
$migration->getIdMap()->prepareUpdate();
}

$executable = new MigrateBatchExecutable($migration, new StubMigrationMessage(), $options);
batch_set($executable->prepareBatch());
}

}
Loading

0 comments on commit d6b5a24

Please sign in to comment.