Last active
October 27, 2020 16:43
-
-
Save hamrant/e7e4ca1054be5e850acc598aea0b6a39 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From b1a51b15c6a1ccd924553d23505a45e95bf29666 Mon Sep 17 00:00:00 2001 | |
From: Igor Karpilenko <[email protected]> | |
Date: Mon, 26 Oct 2020 20:34:17 +0200 | |
Subject: [PATCH 1/4] Backport from 5.x branch | |
--- | |
src/MigrateBatchExecutable.php | 18 +++++++++++++++++- | |
1 file changed, 17 insertions(+), 1 deletion(-) | |
diff --git a/src/MigrateBatchExecutable.php b/src/MigrateBatchExecutable.php | |
index 03e1b40..fa1ed52 100644 | |
--- a/src/MigrateBatchExecutable.php | |
+++ b/src/MigrateBatchExecutable.php | |
@@ -30,6 +30,13 @@ class MigrateBatchExecutable extends MigrateExecutable { | |
*/ | |
protected $checkDependencies = 0; | |
+ /** | |
+ * Indicates if synchronization is needed. | |
+ * | |
+ * @var bool | |
+ */ | |
+ protected $syncSource = FALSE; | |
+ | |
/** | |
* The current batch context. | |
* | |
@@ -57,7 +64,13 @@ class MigrateBatchExecutable extends MigrateExecutable { | |
$this->checkDependencies = $options['force']; | |
} | |
+ if (isset($options['sync'])) { | |
+ $this->syncSource = $options['sync']; | |
+ } | |
+ | |
parent::__construct($migration, $message, $options); | |
+ | |
+ | |
$this->migrationPluginManager = \Drupal::getContainer()->get('plugin.manager.migration'); | |
} | |
@@ -92,6 +105,7 @@ class MigrateBatchExecutable extends MigrateExecutable { | |
'limit' => $this->itemLimit, | |
'update' => $this->updateExistingRows, | |
'force' => $this->checkDependencies, | |
+ 'sync' => $this->syncSource, | |
]); | |
if (count($operations) > 0) { | |
@@ -141,6 +155,7 @@ class MigrateBatchExecutable extends MigrateExecutable { | |
'limit' => 0, | |
'update' => $options['update'], | |
'force' => $options['force'], | |
+ 'sync' => $options['sync'], | |
])); | |
} | |
} | |
@@ -177,7 +192,8 @@ class MigrateBatchExecutable extends MigrateExecutable { | |
// Prepare the migration executable. | |
$message = new MigrateMessage(); | |
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */ | |
- $migration = \Drupal::getContainer()->get('plugin.manager.migration')->createInstance($migration_id); | |
+ $migration = \Drupal::getContainer()->get('plugin.manager.migration')->createInstance($migration_id, isset($options['configuration']) ? $options['configuration'] : []); | |
+ unset($options['configuration']); | |
// Each batch run we need to reinitialize the counter for the migration. | |
if (!empty($options['limit']) && isset($context['results'][$migration->id()]['@numitems'])) { | |
-- | |
GitLab | |
From a8042e2efbda149a17462c37b200577163974fc3 Mon Sep 17 00:00:00 2001 | |
From: Igor Karpilenko <[email protected]> | |
Date: Mon, 26 Oct 2020 20:35:09 +0200 | |
Subject: [PATCH 2/4] Add sync option to migrate execute form | |
--- | |
src/Form/MigrationExecuteForm.php | 13 +++++++++++++ | |
1 file changed, 13 insertions(+) | |
diff --git a/src/Form/MigrationExecuteForm.php b/src/Form/MigrationExecuteForm.php | |
index 150f7d1..4aeffad 100644 | |
--- a/src/Form/MigrationExecuteForm.php | |
+++ b/src/Form/MigrationExecuteForm.php | |
@@ -142,6 +142,12 @@ class MigrationExecuteForm extends FormBase { | |
'#description' => $this->t('Check this box to update all previously-imported content in addition to importing new content. Leave unchecked to only import new content'), | |
]; | |
+ $form['options']['sync'] = [ | |
+ '#type' => 'checkbox', | |
+ '#title' => $this->t('Sync'), | |
+ '#description' => $this->t('Check this box to sync (delete missed in source) all previously-imported content in addition to importing new content. Leave unchecked to only import new content'), | |
+ ]; | |
+ | |
$form['options']['force'] = [ | |
'#type' => 'checkbox', | |
'#title' => $this->t('Ignore dependencies'), | |
@@ -184,6 +190,12 @@ class MigrationExecuteForm extends FormBase { | |
else { | |
$force = 0; | |
} | |
+ if ($form_state->getValue('sync')) { | |
+ $sync = $form_state->getValue('sync'); | |
+ } | |
+ else { | |
+ $sync = 0; | |
+ } | |
$migration = $this->getRouteMatch()->getParameter('migration'); | |
if ($migration) { | |
@@ -198,6 +210,7 @@ class MigrationExecuteForm extends FormBase { | |
'limit' => $limit, | |
'update' => $update, | |
'force' => $force, | |
+ 'sync' => $sync, | |
]; | |
$executable = new MigrateBatchExecutable($migration_plugin, $migrateMessage, $options); | |
-- | |
GitLab | |
From c3463cd38d8684bb8abf85917334775c0104a96b Mon Sep 17 00:00:00 2001 | |
From: Igor Karpilenko <[email protected]> | |
Date: Mon, 26 Oct 2020 20:36:09 +0200 | |
Subject: [PATCH 3/4] Fix for MigrationImportSync that was executed during each | |
batch process | |
--- | |
src/MigrateBatchExecutable.php | 4 ++++ | |
1 file changed, 4 insertions(+) | |
diff --git a/src/MigrateBatchExecutable.php b/src/MigrateBatchExecutable.php | |
index fa1ed52..2010443 100644 | |
--- a/src/MigrateBatchExecutable.php | |
+++ b/src/MigrateBatchExecutable.php | |
@@ -191,6 +191,10 @@ class MigrateBatchExecutable extends MigrateExecutable { | |
// Prepare the migration executable. | |
$message = new MigrateMessage(); | |
+ if ($context['sandbox']['counter'] > 0) { | |
+ // We need to run MigrationImportSync only once. | |
+ $options['sync'] = 0; | |
+ } | |
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */ | |
$migration = \Drupal::getContainer()->get('plugin.manager.migration')->createInstance($migration_id, isset($options['configuration']) ? $options['configuration'] : []); | |
unset($options['configuration']); | |
-- | |
GitLab | |
From 054d8629f51925d074ce680e25e02c4e36052aeb Mon Sep 17 00:00:00 2001 | |
From: Igor Karpilenko <[email protected]> | |
Date: Tue, 27 Oct 2020 18:39:45 +0200 | |
Subject: [PATCH 4/4] Pass syncSource option to migration instance | |
--- | |
src/MigrateBatchExecutable.php | 4 ++-- | |
1 file changed, 2 insertions(+), 2 deletions(-) | |
diff --git a/src/MigrateBatchExecutable.php b/src/MigrateBatchExecutable.php | |
index 2010443..790737e 100644 | |
--- a/src/MigrateBatchExecutable.php | |
+++ b/src/MigrateBatchExecutable.php | |
@@ -191,9 +191,9 @@ class MigrateBatchExecutable extends MigrateExecutable { | |
// Prepare the migration executable. | |
$message = new MigrateMessage(); | |
- if ($context['sandbox']['counter'] > 0) { | |
+ if ($options['sync'] && $context['sandbox']['counter'] == 0) { | |
// We need to run MigrationImportSync only once. | |
- $options['sync'] = 0; | |
+ $options['configuration']['syncSource'] = TRUE; | |
} | |
/** @var \Drupal\migrate\Plugin\MigrationInterface $migration */ | |
$migration = \Drupal::getContainer()->get('plugin.manager.migration')->createInstance($migration_id, isset($options['configuration']) ? $options['configuration'] : []); | |
-- | |
GitLab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment