Commit a819fdbb authored by alexpott's avatar alexpott

Revert "Issue #2918761 by quiett pushone, chiranjeeb2410, phenaproxima,...

Revert "Issue #2918761 by quiett pushone, chiranjeeb2410, phenaproxima, maxocub, heddn, alexpott: Break up MigrateUpgradeForm into smaller forms"

This reverts commit da3818ab.
parent da3818ab
migrate_drupal_ui.upgrade:
path: '/upgrade'
defaults:
_form: '\Drupal\migrate_drupal_ui\Form\OverviewForm'
_title: 'Upgrade'
requirements:
_custom_access: '\Drupal\migrate_drupal_ui\MigrateAccessCheck::checkAccess'
options:
_admin_route: TRUE
migrate_drupal_ui.upgrade_incremental:
path: '/upgrade/incremental'
defaults:
_form: '\Drupal\migrate_drupal_ui\Form\IncrementalForm'
_title: 'Upgrade'
requirements:
_custom_access: '\Drupal\migrate_drupal_ui\MigrateAccessCheck::checkAccess'
options:
_admin_route: TRUE
migrate_drupal_ui.upgrade_credential:
path: '/upgrade/credentials'
defaults:
_form: '\Drupal\migrate_drupal_ui\Form\CredentialForm'
_title: 'Upgrade'
requirements:
_custom_access: '\Drupal\migrate_drupal_ui\MigrateAccessCheck::checkAccess'
options:
_admin_route: TRUE
migrate_drupal_ui.upgrade_id_conflict:
path: '/upgrade/idconflict'
defaults:
_form: '\Drupal\migrate_drupal_ui\Form\IdConflictForm'
_title: 'Upgrade'
requirements:
_custom_access: '\Drupal\migrate_drupal_ui\MigrateAccessCheck::checkAccess'
options:
_admin_route: TRUE
migrate_drupal_ui.upgrade_review:
path: '/upgrade/review'
defaults:
_form: '\Drupal\migrate_drupal_ui\Form\ReviewForm'
_form: '\Drupal\migrate_drupal_ui\Form\MigrateUpgradeForm'
_title: 'Upgrade'
requirements:
_custom_access: '\Drupal\migrate_drupal_ui\MigrateAccessCheck::checkAccess'
......
<?php
namespace Drupal\migrate_drupal_ui\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Migrate Upgrade database credential form.
*
* @internal
*/
class CredentialForm extends MigrateUpgradeFormBase {
/**
* The renderer service.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected $renderer;
/**
* CredentialForm constructor.
*
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer service.
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $tempstore_private
* The private tempstore factory.
*/
public function __construct(RendererInterface $renderer, PrivateTempStoreFactory $tempstore_private) {
parent::__construct($tempstore_private);
$this->renderer = $renderer;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('renderer'),
$container->get('tempstore.private')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'migrate_drupal_ui_credential_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
if ($this->store->get('step') != 'credential') {
$this->store->set('step', 'overview');
return $this->redirect('migrate_drupal_ui.upgrade');
}
$form = parent::buildForm($form, $form_state);
$form['actions']['submit']['#value'] = $this->t('Review upgrade');
$form['#title'] = $this->t('Drupal Upgrade');
$drivers = $this->getDatabaseTypes();
$drivers_keys = array_keys($drivers);
// @todo https://www.drupal.org/node/2678510 Because this is a multi-step
// form, the form is not rebuilt during submission. Ideally we would get
// the chosen driver from form input, if available, in order to use
// #limit_validation_errors in the same way
// \Drupal\Core\Installer\Form\SiteSettingsForm does.
$default_driver = current($drivers_keys);
$default_options = [];
$form['version'] = [
'#type' => 'radios',
'#default_value' => 7,
'#title' => $this->t('Drupal version of the source site'),
'#options' => ['6' => $this->t('Drupal 6'), '7' => $this->t('Drupal 7')],
'#required' => TRUE,
];
$form['database'] = [
'#type' => 'details',
'#title' => $this->t('Source database'),
'#description' => $this->t('Provide credentials for the database of the Drupal site you want to upgrade.'),
'#open' => TRUE,
];
$form['database']['driver'] = [
'#type' => 'radios',
'#title' => $this->t('Database type'),
'#required' => TRUE,
'#default_value' => $default_driver,
];
if (count($drivers) == 1) {
$form['database']['driver']['#disabled'] = TRUE;
}
// Add driver-specific configuration options.
foreach ($drivers as $key => $driver) {
$form['database']['driver']['#options'][$key] = $driver->name();
$form['database']['settings'][$key] = $driver->getFormOptions($default_options);
// @todo https://www.drupal.org/node/2678510 Using
// #limit_validation_errors in the submit does not work so it is not
// possible to require the database and username for mysql and pgsql.
// This is because this is a multi-step form.
$form['database']['settings'][$key]['database']['#required'] = FALSE;
$form['database']['settings'][$key]['username']['#required'] = FALSE;
$form['database']['settings'][$key]['#prefix'] = '<h2 class="js-hide">' . $this->t('@driver_name settings', ['@driver_name' => $driver->name()]) . '</h2>';
$form['database']['settings'][$key]['#type'] = 'container';
$form['database']['settings'][$key]['#tree'] = TRUE;
$form['database']['settings'][$key]['advanced_options']['#parents'] = [$key];
$form['database']['settings'][$key]['#states'] = [
'visible' => [
':input[name=driver]' => ['value' => $key],
],
];
// Move the host fields out of advanced settings.
if (isset($form['database']['settings'][$key]['advanced_options']['host'])) {
$form['database']['settings'][$key]['host'] = $form['database']['settings'][$key]['advanced_options']['host'];
$form['database']['settings'][$key]['host']['#title'] = 'Database host';
$form['database']['settings'][$key]['host']['#weight'] = -1;
unset($form['database']['settings'][$key]['database']['#default_value']);
unset($form['database']['settings'][$key]['advanced_options']['host']);
}
}
$form['source'] = [
'#type' => 'details',
'#title' => $this->t('Source files'),
'#open' => TRUE,
];
$form['source']['d6_source_base_path'] = [
'#type' => 'textfield',
'#title' => $this->t('Files directory'),
'#description' => $this->t('To import files from your current Drupal site, enter a local file directory containing your site (e.g. /var/www/docroot), or your site address (for example http://example.com).'),
'#states' => [
'visible' => [
':input[name="version"]' => ['value' => '6'],
],
],
];
$form['source']['source_base_path'] = [
'#type' => 'textfield',
'#title' => $this->t('Public files directory'),
'#description' => $this->t('To import public files from your current Drupal site, enter a local file directory containing your site (e.g. /var/www/docroot), or your site address (for example http://example.com).'),
'#states' => [
'visible' => [
':input[name="version"]' => ['value' => '7'],
],
],
];
$form['source']['source_private_file_path'] = [
'#type' => 'textfield',
'#title' => $this->t('Private file directory'),
'#default_value' => '',
'#description' => $this->t('To import private files from your current Drupal site, enter a local file directory containing your site (e.g. /var/www/docroot).'),
'#states' => [
'visible' => [
':input[name="version"]' => ['value' => '7'],
],
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
// Retrieve the database driver from the form, use reflection to get the
// namespace, and then construct a valid database array the same as in
// settings.php.
$driver = $form_state->getValue('driver');
$drivers = $this->getDatabaseTypes();
$reflection = new \ReflectionClass($drivers[$driver]);
$install_namespace = $reflection->getNamespaceName();
$database = $form_state->getValue($driver);
// Cut the trailing \Install from namespace.
$database['namespace'] = substr($install_namespace, 0, strrpos($install_namespace, '\\'));
$database['driver'] = $driver;
// Validate the driver settings and just end here if we have any issues.
if ($errors = $drivers[$driver]->validateDatabaseSettings($database)) {
foreach ($errors as $name => $message) {
$form_state->setErrorByName($name, $message);
}
return;
}
try {
$connection = $this->getConnection($database);
$version = (string) $this->getLegacyDrupalVersion($connection);
if (!$version) {
$form_state->setErrorByName($database['driver'] . '][0', $this->t('Source database does not contain a recognizable Drupal version.'));
}
elseif ($version !== (string) $form_state->getValue('version')) {
$form_state->setErrorByName($database['driver'] . '][0', $this->t('Source database is Drupal version @version but version @selected was selected.', [
'@version' => $version,
'@selected' => $form_state->getValue('version'),
]));
}
else {
// Setup migrations and save form data to private store.
$this->setupMigrations($database, $form_state);
}
}
catch (\Exception $e) {
$error_message = [
'#title' => $this->t('Resolve the issue below to continue the upgrade.'),
'#theme' => 'item_list',
'#items' => [$e->getMessage()],
];
$form_state->setErrorByName($database['driver'] . '][0', $this->renderer->renderPlain($error_message));
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->store->set('step', 'id_conflict');
$form_state->setRedirect('migrate_drupal_ui.upgrade_id_conflict');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Review upgrade');
}
/**
* Returns all supported database driver installer objects.
*
* @return \Drupal\Core\Database\Install\Tasks[]
* An array of available database driver installer objects.
*/
protected function getDatabaseTypes() {
// Make sure the install API is available.
include_once DRUPAL_ROOT . '/core/includes/install.inc';
return drupal_get_database_types();
}
}
<?php
namespace Drupal\migrate_drupal_ui\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Drupal\migrate\Audit\IdAuditor;
use Drupal\migrate\Plugin\migrate\destination\EntityContentBase;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Migrate Upgrade Id Conflict form.
*
* @internal
*/
class IdConflictForm extends MigrateUpgradeFormBase {
/**
* The migration plugin manager service.
*
* @var \Drupal\migrate\Plugin\MigrationPluginManagerInterface
*/
protected $pluginManager;
/**
* IdConflictForm constructor.
*
* @param \Drupal\migrate\Plugin\MigrationPluginManagerInterface $migration_plugin_manager
* The migration plugin manager service.
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $tempstore_private
* The private tempstore factory.
*/
public function __construct(MigrationPluginManagerInterface $migration_plugin_manager, PrivateTempStoreFactory $tempstore_private) {
parent::__construct($tempstore_private);
$this->pluginManager = $migration_plugin_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('plugin.manager.migration'),
$container->get('tempstore.private')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'migrate_drupal_ui_id_conflict_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
if ($this->store->get('step') != 'id_conflict') {
$this->store->set('step', 'overview');
return $this->redirect('migrate_drupal_ui.upgrade');
}
// Check if there are conflicts. If none, just skip this form!
$migration_ids = array_keys($this->store->get('migrations'));
$migrations = $this->pluginManager->createInstances($migration_ids);
$translated_content_conflicts = $content_conflicts = [];
$results = (new IdAuditor())->auditMultiple($migrations);
/** @var \Drupal\migrate\Audit\AuditResult $result */
foreach ($results as $result) {
$destination = $result->getMigration()->getDestinationPlugin();
if ($destination instanceof EntityContentBase && $destination->isTranslationDestination()) {
// Translations are not yet supported by the audit system. For now, we
// only warn the user to be cautious when migrating translated content.
// I18n support should be added in https://www.drupal.org/node/2905759.
$translated_content_conflicts[] = $result;
}
elseif (!$result->passed()) {
$content_conflicts[] = $result;
}
}
if ($content_conflicts || $translated_content_conflicts) {
$this->messenger()->addWarning($this->t('WARNING: Content may be overwritten on your new site.'));
$form = parent::buildForm($form, $form_state);
$form['#title'] = $this->t('Upgrade analysis report');
if ($content_conflicts) {
$form = $this->conflictsForm($form, $content_conflicts);
}
if ($translated_content_conflicts) {
$form = $this->i18nWarningForm($form, $translated_content_conflicts);
}
return $form;
}
else {
$this->store->set('step', 'review');
return $this->redirect('migrate_drupal_ui.upgrade_review');
}
}
/**
* Build the markup for conflict warnings.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\migrate\Audit\AuditResult[] $conflicts
* The failing audit results.
*
* @return array
* The form structure.
*/
protected function conflictsForm(array &$form, array $conflicts) {
$form['conflicts'] = [
'#title' => $this->t('There is conflicting content of these types:'),
'#theme' => 'item_list',
'#items' => $this->formatConflicts($conflicts),
];
$form['warning'] = [
'#type' => 'markup',
'#markup' => '<p>' . $this->t('It looks like you have content on your new site which <strong>may be overwritten</strong> if you continue to run this upgrade. The upgrade should be performed on a clean Drupal 8 installation. For more information see the <a target="_blank" href=":id-conflicts-handbook">upgrade handbook</a>.', [':id-conflicts-handbook' => 'https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#id_conflicts']) . '</p>',
];
return $form;
}
/**
* Formats a set of failing audit results as strings.
*
* Each string is the label of the destination plugin of the migration that
* failed the audit, keyed by the destination plugin ID in order to prevent
* duplication.
*
* @param \Drupal\migrate\Audit\AuditResult[] $conflicts
* The failing audit results.
*
* @return string[]
* The formatted audit results.
*/
protected function formatConflicts(array $conflicts) {
$items = [];
foreach ($conflicts as $conflict) {
$definition = $conflict->getMigration()->getDestinationPlugin()->getPluginDefinition();
$id = $definition['id'];
$items[$id] = $definition['label'];
}
sort($items, SORT_STRING);
return $items;
}
/**
* Build the markup for i18n warnings.
*
* @param array $form
* An associative array containing the structure of the form.
* @param \Drupal\migrate\Audit\AuditResult[] $conflicts
* The failing audit results.
*
* @return array
* The form structure.
*/
protected function i18nWarningForm(array &$form, array $conflicts) {
$form['i18n'] = [
'#title' => $this->t('There is translated content of these types:'),
'#theme' => 'item_list',
'#items' => $this->formatConflicts($conflicts),
];
$form['i18n_warning'] = [
'#type' => 'markup',
'#markup' => '<p>' . $this->t('It looks like you are migrating translated content from your old site. Possible ID conflicts for translations are not automatically detected in the current version of Drupal. Refer to the <a target="_blank" href=":id-conflicts-handbook">upgrade handbook</a> for instructions on how to avoid ID conflicts with translated content.', [':id-conflicts-handbook' => 'https://www.drupal.org/docs/8/upgrade/known-issues-when-upgrading-from-drupal-6-or-7-to-drupal-8#id_conflicts']) . '</p>',
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->store->set('step', 'review');
$form_state->setRedirect('migrate_drupal_ui.upgrade_review');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('I acknowledge I may lose data. Continue anyway.');
}
}
<?php
namespace Drupal\migrate_drupal_ui\Form;
use Drupal\Core\Database\DatabaseExceptionWrapper;
use Drupal\Core\Datetime\DateFormatterInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Migrate Upgrade Incremental form.
*
* @internal
*/
class IncrementalForm extends MigrateUpgradeFormBase {
/**
* The state service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* IncrementalForm constructor.
*
* @param \Drupal\Core\State\StateInterface $state
* The state service.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $tempstore_private
* The private temp store factory.
*/
public function __construct(StateInterface $state, DateFormatterInterface $date_formatter, PrivateTempStoreFactory $tempstore_private) {
parent::__construct($tempstore_private);
$this->state = $state;
$this->dateFormatter = $date_formatter;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('state'),
$container->get('date.formatter'),
$container->get('tempstore.private')
);
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'migrate_drupal_ui_incremental_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
if ($this->store->get('step') != 'incremental') {
$this->store->set('step', 'overview');
return $this->redirect('migrate_drupal_ui.upgrade');
}
$form = parent::buildForm($form, $form_state);
$form['#title'] = $this->t('Upgrade');
$date_performed = $this->store->get('performed');
// @todo Add back support for rollbacks.
// https://www.drupal.org/node/2687849
$form['upgrade_option_item'] = [
'#type' => 'item',
'#prefix' => $this->t('An upgrade has already been performed on this site. To perform a new migration, create a clean and empty new install of Drupal 8. Rollbacks are not yet supported through the user interface. For more information, see the <a href=":url">upgrading handbook</a>.', [':url' => 'https://www.drupal.org/upgrade/migrate']),
'#description' => $this->t('Last upgrade: @date', ['@date' => $this->dateFormatter->format($date_performed)]),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
// Retrieve the database driver from state.
$database_state_key = $this->state->get('migrate.fallback_state_key', '');
if ($database_state_key) {
try {
$database = $this->state->get($database_state_key, [])['database'];
if ($connection = $this->getConnection($database)) {
if ($version = $this->getLegacyDrupalVersion($connection)) {
$this->setupMigrations($database, $form_state);
$valid_legacy_database = TRUE;
}
}
}
catch (DatabaseExceptionWrapper $exception) {
// Hide DB exceptions and forward to the DB credentials form. In that
// form we can more properly display errors and accept new credentials.
}
}
if (empty($valid_legacy_database)) {
$form_state->setValue('step', 'credentials')->setRebuild();
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->store->set('step', 'id_conflict');
$form_state->setRedirect('migrate_drupal_ui.upgrade_id_conflict');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Import new configuration and content from old site');
}
}
This diff is collapsed.
<?php
namespace Drupal\migrate_drupal_ui\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\migrate_drupal\MigrationConfigurationTrait;
use Drupal\Core\TempStore\PrivateTempStoreFactory;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Form base for the Migrate Upgrade UI.
*/
abstract class MigrateUpgradeFormBase extends FormBase {
use MigrationConfigurationTrait;
/**
* Private temporary storage.
*
* @var \Drupal\Core\TempStore\PrivateTempStoreFactory
*/
protected $store;
/**
* Constructs the Migrate Upgrade Form Base.
*
* @param \Drupal\Core\TempStore\PrivateTempStoreFactory $tempstore_private
* Private store.
*/
public function __construct(PrivateTempStoreFactory $tempstore_private) {
$this->store = $tempstore_private->get('migrate_drupal_ui');
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('tempstore.private')
);
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form = [];
$form['actions']['#type'] = 'actions';
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->getConfirmText(),
'#button_type' => 'primary',
'#weight' => 10,
];
return $form;
}
/**
* Puts migrations information in form state.
*
* Gets all the migrations, converts each to an array and stores it in the
* form state. The source base path for public and private files is also
* put into form state.
*
* @param array $database