diff -u b/core/modules/migrate/src/MigrateIdAuditor.php b/core/modules/migrate/src/MigrateIdAuditor.php --- b/core/modules/migrate/src/MigrateIdAuditor.php +++ b/core/modules/migrate/src/MigrateIdAuditor.php @@ -27,13 +27,6 @@ if ($destination->getHighestDestinationId($field_name) > $id_map->getHighestMigratedId($field_name)) { $conflicts += $this->buildConflict($migration); } - elseif ($destination->isTranslationDestination()) { - // @TODO: Figure out how to determine if this will result in conflicts. - // Hint, I don't think this is possible by simply comparing highest id. - // For now, blindly warn it *is* a conflict, even though it very - // well might not. It would only effects term and node translation migrations. - $conflicts += $this->buildConflict($migration); - } } } } diff -u b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php --- b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php @@ -7,8 +7,11 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\RendererInterface; use Drupal\Core\State\StateInterface; +use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Url; use Drupal\migrate\MigrateIdAuditorInterface; +use Drupal\migrate\Plugin\MigrateDestinationAuditInterface; +use Drupal\migrate\Plugin\MigrationInterface; use Drupal\migrate\Plugin\MigrationPluginManagerInterface; use Drupal\migrate_drupal_ui\Batch\MigrateUpgradeImportBatch; use Drupal\migrate_drupal\MigrationConfigurationTrait; @@ -454,24 +457,55 @@ $migration_ids = array_keys($form_state->get('migrations')); $migrations = $this->pluginManager->createInstances($migration_ids); $conflicts = $this->idAuditor->auditIds($migrations); - if (empty($conflicts)) { + + $i18n = []; + foreach ($migrations as $migration) { + if ($migration->getDestinationPlugin() instanceof MigrateDestinationAuditInterface) { + if ($migration->getDestinationPlugin()->isTranslationDestination()) { + $i18n += $this->buildConflict($migration); + } + } + } + if (empty($conflicts) && empty($i18n)) { $form_state->set('step', 'confirm'); return $this->buildForm($form, $form_state); } + $form['warning'] = [ + '#type' => 'markup', + '#markup' => '

' . $this->t('Entities may be overwritten') . '

', + ]; $form = parent::buildForm($form, $form_state); $form['actions']['submit']['#submit'] = ['::submitConfirmIdConflictForm']; $form['actions']['submit']['#value'] = $this->t('I acknowledge I may lose data, continue anyway.'); - $form['warning'] = [ - '#type' => 'markup', - '#markup' => '

' . $this->t('Entities may be overwritten') . '

' . - '

' . $this->t('Upgrades work on brand new sites, or sites with previously upgraded data. However, it looks like you have content in your site that is unknown to the migrate system; perhaps manually added. These new entities may be overwritten if you run this upgrade. For more information, see the online handbook entry for handling migration conflicts..', [':id-conflicts-handbook' => 'https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#id_conflicts']) . '

', - ]; + $form = $this->conflictsForm($form, $form_state, $conflicts); + return $this->i18nWarningForm($form, $form_state, $i18n); + } + + /** + * Build the markup for conflict warnings. + * + * @param array $form + * An associative array containing the structure of the form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. + * @param array + * The conflicted migration labels. + * + * @return array + * The form structure. + */ + protected function conflictsForm(array &$form, FormStateInterface $form_state, $conflicts) { + if (empty($conflicts)) { + return $form; + } + + $form['warning']['#markup'] .= '

' . $this->t('Upgrades work on brand new sites, or sites with previously upgraded data. However, it looks like you have content in your site that is unknown to the migrate system; perhaps manually added. These new entities may be overwritten if you run this upgrade. For more information, see the online handbook entry for handling migration conflicts..', [':id-conflicts-handbook' => 'https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#id_conflicts']) . '

'; sort($conflicts); - $form['type_list'] = [ - '#title' => $this->t('These entities are of the following types:'), + $form['conflicts'] = [ + '#title' => $this->t('These conflicting entities are of the following types:'), '#theme' => 'item_list', '#items' => $conflicts, ]; @@ -480,6 +514,36 @@ } /** + * Build the markup for i18n warnings. + * + * @param array $form + * An associative array containing the structure of the form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The current state of the form. + * @param array + * The internationalization migration labels. + * + * @return array + * The form structure. + */ + protected function i18nWarningForm(array &$form, FormStateInterface $form_state, $i18n) { + if (empty($i18n)) { + return $form; + } + + $form['warning']['#markup'] .= '

' . $this->t('It looks like you are migrating translated content. Be extra cautious and make sure you aren\'t introducting any conflicts. For more on the subject, see the online handbook entry for handling migration conflicts..handling migration conflicts..', [':id-conflicts-handbook' => 'https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#id_conflicts']) . '

'; + + sort($i18n); + $form['i18n'] = [ + '#title' => $this->t('These translatable entities are of the following types:'), + '#theme' => 'item_list', + '#items' => $i18n, + ]; + + return $form; + } + + /** * Submission handler for the confirmation form. * * @param array $form @@ -681,2 +745,29 @@ + /** + * Build conflict label. + * + * @param \Drupal\migrate\Plugin\MigrationInterface $migration + * + * @TODO: This is a duplicate of MigrateIdAuditor::buildConflict() and should + * eventually be removed in https://www.drupal.org/node/2905759 + * + * @return array + */ + protected function buildConflict(MigrationInterface $migration) { + $conflict = []; + $base_id = $migration->getBaseId(); + $label = $migration->label(); + if (is_string($label)) { + $conflict[$base_id] = $label; + } + elseif ($label instanceof TranslatableMarkup) { + $conflict[$base_id] = $label->render(); + if (isset($label->getArguments()['@label'])) { + $conflict[$base_id] = $label->getArguments()['@label']; + } + } + + return $conflict; + } + }