diff -u b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeFormBase.php
--- b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php
+++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeFormBase.php
@@ -9,14 +9,13 @@
use Drupal\Core\State\StateInterface;
use Drupal\Core\Url;
use Drupal\migrate\Plugin\MigrationPluginManagerInterface;
-use Drupal\migrate_drupal_ui\Batch\MigrateUpgradeImportBatch;
use Drupal\migrate_drupal\MigrationConfigurationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a multi-step form for performing direct site upgrades.
*/
-class MigrateUpgradeForm extends ConfirmFormBase {
+class MigrateUpgradeFormBase extends ConfirmFormBase {
use MigrationConfigurationTrait;
@@ -714,51 +713,7 @@
/**
* {@inheritdoc}
*/
- public function getFormId() {
- return 'migrate_drupal_ui_form';
- }
-
- /**
- * {@inheritdoc}
- */
public function buildForm(array $form, FormStateInterface $form_state) {
- $step = $form_state->get('step') ?: 'overview';
- switch ($step) {
- case 'overview':
- return $this->buildOverviewForm($form, $form_state);
-
- case 'credentials':
- return $this->buildCredentialForm($form, $form_state);
-
- case 'confirm':
- return $this->buildConfirmForm($form, $form_state);
-
- default:
- drupal_set_message($this->t('Unrecognized form step @step', ['@step' => $step]), 'error');
- return [];
- }
- }
-
- /**
- * {@inheritdoc}
- */
- public function submitForm(array &$form, FormStateInterface $form_state) {
- // This method is intentionally empty, see the specific submit methods for
- // each form step.
- }
-
- /**
- * Builds the form presenting an overview of the migration process.
- *
- * @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.
- *
- * @return array
- * The form structure.
- */
- public function buildOverviewForm(array $form, FormStateInterface $form_state) {
$form['#title'] = $this->t('Upgrade');
if ($date_performed = $this->state->get('migrate_drupal_ui.performed')) {
@@ -775,8 +730,8 @@
else {
$form['info_header'] = [
'#markup' => '
' . $this->t('Upgrade a site by importing it into a clean and empty new install of Drupal 8. You will lose any existing configuration once you import your site into it. See the online documentation for Drupal site upgrades for more detailed information.', [
- ':url' => 'https://www.drupal.org/upgrade/migrate',
- ]),
+ ':url' => 'https://www.drupal.org/upgrade/migrate',
+ ]),
];
$info[] = $this->t('Back up the database for this site. Upgrade will change the database for this site.');
@@ -796,8 +751,6 @@
$form['info_footer'] = [
'#markup' => '
' . $this->t('This upgrade can take a long time. It is better to import a local copy of your site instead of directly importing from your live site.'),
];
-
- $validate = [];
}
$form['actions'] = ['#type' => 'actions'];
@@ -805,381 +758,23 @@
'#type' => 'submit',
'#value' => $this->t('Continue'),
'#button_type' => 'primary',
- '#validate' => $validate,
- '#submit' => ['::submitOverviewForm'],
+ '#submit' => ['::submitForm'],
];
return $form;
}
/**
- * Form submission handler for the overview form.
- *
- * @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.
- */
- public function submitOverviewForm(array &$form, FormStateInterface $form_state) {
- $form_state->set('step', 'credentials');
- $form_state->setRebuild();
- }
-
- /**
- * Builds the database credential form and adds file location information.
- *
- * This is largely borrowed from \Drupal\Core\Installer\Form\SiteSettingsForm.
- *
- * @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.
- *
- * @return array
- * The form structure.
- *
- * @todo Private files directory not yet implemented, depends on
- * https://www.drupal.org/node/2547125.
- */
- public function buildCredentialForm(array $form, FormStateInterface $form_state) {
- $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['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'] = '
' . $this->t('@driver_name settings', ['@driver_name' => $driver->name()]) . '
';
- $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']['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).'),
- ];
-
- $form['actions'] = ['#type' => 'actions'];
- $form['actions']['save'] = [
- '#type' => 'submit',
- '#value' => $this->t('Review upgrade'),
- '#button_type' => 'primary',
- '#validate' => ['::validateCredentialForm'],
- '#submit' => ['::submitCredentialForm'],
- ];
- return $form;
- }
-
- /**
- * Validation handler for the credentials form.
- *
- * @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.
- */
- public function validateCredentialForm(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 = $this->getLegacyDrupalVersion($connection);
- if (!$version) {
- $form_state->setErrorByName($database['driver'] . '][0', $this->t('Source database does not contain a recognizable Drupal version.'));
- }
- else {
- $this->createDatabaseStateSettings($database, $version);
- $migrations = $this->getMigrations('migrate_drupal_' . $version, $version);
-
- // Get the system data from source database.
- $system_data = $this->getSystemData($connection);
-
- // Convert the migration object into array
- // so that it can be stored in form storage.
- $migration_array = [];
- foreach ($migrations as $migration) {
- $migration_array[$migration->id()] = $migration->label();
- }
-
- // Store the retrieved migration IDs in form storage.
- $form_state->set('migrations', $migration_array);
- $form_state->set('source_base_path', $form_state->getValue('source_base_path'));
-
- // Store the retrived system data in form storage.
- $form_state->set('system_data', $system_data);
- }
- }
- 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));
- }
- }
-
- /**
- * Submission handler for the credentials form.
- *
- * @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.
- */
- public function submitCredentialForm(array &$form, FormStateInterface $form_state) {
- // Indicate the next step is confirmation.
- $form_state->set('step', 'confirm');
- $form_state->setRebuild();
- }
-
- /**
- * Confirmation form for missing migrations, etc.
- *
- * @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.
- *
- * @return array
- * The form structure.
- */
- public function buildConfirmForm(array $form, FormStateInterface $form_state) {
- $form = parent::buildForm($form, $form_state);
- $form['actions']['submit']['#submit'] = ['::submitConfirmForm'];
-
- $form['actions']['submit']['#value'] = $this->t('Perform upgrade');
-
- // Build upgrade analysis.
- // Get system data and migrations.
- foreach ($form_state->get('migrations') as $migration_id => $migration_label) {
- // Fetch the system data at the first opportunity.
- if (empty($system_data)) {
- $system_data = $form_state->get('system_data');
- }
-
- // Handle derivatives.
- list($migration_id,) = explode(':', $migration_id, 2);
- $source_module = $this->moduleUpgradePaths[$migration_id]['source_module'];
- $destination_module = $this->moduleUpgradePaths[$migration_id]['destination_module'];
- $table_data[$source_module][$destination_module][$migration_id] = $migration_label;
- }
-
- // Sort the table by source module names and within that destination
- // module names.
- ksort($table_data);
- foreach ($table_data as $source_module => $destination_module_info) {
- ksort($table_data[$source_module]);
- }
-
- // Missing migrations.
- $form['missing_module_list_title'] = [
- '#type' => 'item',
- '#title' => $this->t('Missing upgrade paths'),
- '#description' => $this->t('The following items will not be upgraded. For more information see Upgrading from Drupal 6 or 7 to Drupal 8.', array(':migrate' => 'https://www.drupal.org/upgrade/migrate')),
- ];
- $form['missing_module_list'] = [
- '#type' => 'table',
- '#header' => [],
- ];
- $unmigrated_source_modules = array_diff_key($system_data['module'], $table_data);
- $missing = $this->getMissingMigrations($unmigrated_source_modules);
- $missing_count = count($missing);
- $form['missing_module_list'] = $form['missing_module_list'] + $missing;
-
- // Available migrations.
- $form['available_module_list'] = [
- '#tree' => TRUE,
- '#type' => 'details',
- '#title' => $this->t('Available upgrade paths'),
- ];
-
- $form['available_module_list']['module_list'] = [
- '#type' => 'table',
- '#header' => [],
- ];
- $available = $this->getAvailableMigrations($table_data);
- $available_count = count($table_data);
- $form['available_module_list']['module_list'] = $form['available_module_list']['module_list'] + $available;
-
- $form['counts'] = [
- '#type' => 'item',
- '#title' => '- ' . $this->t('@count available upgrade paths', ['@count' => $available_count]) . '
- ' . $this->t('@count missing upgrade paths', ['@count' => $missing_count]) . '
',
- '#weight' => -15,
- ];
-
- return $form;
- }
-
- /**
- * Build a list of missing migrations.
- *
- * @param array $unmigrated_source_modules
- * An array of missing migrations keyed by source module.
- *
- * @return array $available
- * Array of missing migrations formatted for display in a table.
- */
- protected function getMissingMigrations($unmigrated_source_modules) {
- ksort($unmigrated_source_modules);
- foreach ($unmigrated_source_modules as $source_module => $module_data) {
- if ($module_data['status']) {
- $missing[$source_module] = [
- 'source_module' => ['#plain_text' => $source_module],
- ];
- }
- }
- return $missing;
- }
-
- /**
- * Build a list of available migrations.
- *
- * @param array $table_data
- * An multidimensional array of migrations, keyed by source module,
- * destination module and migration id.
- *
- * @return array $available
- * Array of available migrations formatted for display in a table.
- */
- protected function getAvailableMigrations($table_data) {
- foreach ($table_data as $source_module => $destination_module_info) {
- $destination_details = [];
- foreach ($destination_module_info as $destination_module => $migration_ids) {
- $destination_details[$destination_module] = [
- '#type' => 'item',
- '#plain_text' => $destination_module,
- ];
- }
- $available[$source_module] = [
- 'source_module' => ['#plain_text' => $source_module],
- ];
- }
- return $available;
- }
-
- /**
- * Submission handler for the confirmation form.
- *
- * @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.
- */
- public function submitConfirmForm(array &$form, FormStateInterface $form_state) {
- $storage = $form_state->getStorage();
-
- $migrations = $storage['migrations'];
- $config['source_base_path'] = $storage['source_base_path'];
- $batch = [
- 'title' => $this->t('Running upgrade'),
- 'progress_message' => '',
- 'operations' => [
- [
- [MigrateUpgradeImportBatch::class, 'run'],
- [array_keys($migrations), $config],
- ],
- ],
- 'finished' => [
- MigrateUpgradeImportBatch::class, 'finished',
- ],
- ];
- batch_set($batch);
- $form_state->setRedirect('');
- $this->state->set('migrate_drupal_ui.performed', REQUEST_TIME);
- }
-
- /**
- * Returns all supported database driver installer objects.
- *
- * @return \Drupal\Core\Database\Install\Tasks[]
- * An array of available database driver installer objects.
+ * {@inheritdoc}
*/
- protected function getDatabaseTypes() {
- // Make sure the install API is available.
- include_once DRUPAL_ROOT . '/core/includes/install.inc';
- return drupal_get_database_types();
+ public function submitForm(array &$form, FormStateInterface $form_state) {
+ $form_state->setRedirect('migrate_drupal_ui.upgrade.upgrade');
}
/**
* {@inheritdoc}
*/
- public function getQuestion() {
- return $this->t('Are you sure?');
+ public function getFormId() {
+ return 'migrate_drupal_ui_formbase';
}
/**
@@ -1195,14 +790,12 @@
public function getDescription() {
// The description is added by the buildConfirmForm() method.
// @see \Drupal\migrate_drupal_ui\Form\MigrateUpgradeForm::buildConfirmForm()
- return;
}
/**
* {@inheritdoc}
*/
- public function getConfirmText() {
- return $this->t('Perform upgrade');
+ public function getQuestion() {
}
}
only in patch2:
unchanged:
--- a/core/modules/migrate_drupal_ui/migrate_drupal_ui.routing.yml
+++ b/core/modules/migrate_drupal_ui/migrate_drupal_ui.routing.yml
@@ -1,7 +1,17 @@
migrate_drupal_ui.upgrade:
path: '/upgrade'
defaults:
- _form: '\Drupal\migrate_drupal_ui\Form\MigrateUpgradeForm'
+ _form: '\Drupal\migrate_drupal_ui\Form\MigrateUpgradeFormBase'
+ _title: 'Upgrade'
+ requirements:
+ _custom_access: '\Drupal\migrate_drupal_ui\MigrateAccessCheck::checkAccess'
+ options:
+ _admin_route: TRUE
+
+migrate_drupal_ui.upgrade.upgrade:
+ path: '/upgrade/upgrade'
+ defaults:
+ _form: '\Drupal\migrate_drupal_ui\Form\MigrateUpgradeUpgradeForm'
_title: 'Upgrade'
requirements:
_custom_access: '\Drupal\migrate_drupal_ui\MigrateAccessCheck::checkAccess'
only in patch2:
unchanged:
--- /dev/null
+++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeUpgradeForm.php
@@ -0,0 +1,430 @@
+get('step') ?: 'credentials';
+ switch ($step) {
+ case 'credentials':
+ return $this->buildCredentialForm($form, $form_state);
+
+ case 'confirm':
+ return $this->buildConfirmForm($form, $form_state);
+
+ default:
+ drupal_set_message($this->t('Unrecognized form step @step', ['@step' => $step]), 'error');
+ return [];
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function submitForm(array &$form, FormStateInterface $form_state) {
+ // This method is intentionally empty, see the specific submit methods for
+ // each form step.
+ }
+
+ /**
+ * Builds the database credential form and adds file location information.
+ *
+ * This is largely borrowed from \Drupal\Core\Installer\Form\SiteSettingsForm.
+ *
+ * @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.
+ *
+ * @return array
+ * The form structure.
+ *
+ * @todo Private files directory not yet implemented, depends on
+ * https://www.drupal.org/node/2547125.
+ */
+ public function buildCredentialForm(array $form, FormStateInterface $form_state) {
+ $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['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'] = '' . $this->t('@driver_name settings', ['@driver_name' => $driver->name()]) . '
';
+ $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']['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).'),
+ ];
+
+ $form['actions'] = ['#type' => 'actions'];
+ $form['actions']['save'] = [
+ '#type' => 'submit',
+ '#value' => $this->t('Review upgrade'),
+ '#button_type' => 'primary',
+ '#validate' => ['::validateCredentialForm'],
+ '#submit' => ['::submitCredentialForm'],
+ ];
+ return $form;
+ }
+
+ /**
+ * Validation handler for the credentials form.
+ *
+ * @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.
+ */
+ public function validateCredentialForm(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;
+ }
+
+ $source_base_path = $form_state->getValue('source_base_path');
+ $this->setUpSourceAndMigrations($form_state, $database, $source_base_path, $database['driver'] . '][0');
+ }
+
+ /**
+ * Sets up the database connection and the migrations.
+ *
+ * @param \Drupal\Core\Form\FormStateInterface $form_state
+ * The current state of the form.
+ * @param array $database
+ * The source database settings.
+ * @param string $source_base_path
+ * The path to the source files.
+ * @param string $form_error_name
+ * The name of the form element.
+ */
+ protected function setUpSourceAndMigrations(FormStateInterface $form_state, array $database, $source_base_path, $form_error_name = '') {
+ try {
+ $connection = $this->getConnection($database);
+ $version = $this->getLegacyDrupalVersion($connection);
+ if (!$version) {
+ $form_state->setErrorByName($form_error_name, $this->t('Source database does not contain a recognizable Drupal version.'));
+ }
+ else {
+ $this->createDatabaseStateSettings($database, $version);
+ $migrations = $this->getMigrations('migrate_drupal_' . $version, $version);
+
+ // Get the system data from source database.
+ $system_data = $this->getSystemData($connection);
+
+ // Convert the migration object into array
+ // so that it can be stored in form storage.
+ $migration_array = [];
+ foreach ($migrations as $migration) {
+ $migration_array[$migration->id()] = $migration->label();
+ }
+
+ // Store the source_base_path in state.
+ \Drupal::state()
+ ->set('migrate.source_base_path_state_key', $source_base_path);
+
+ // Store the retrieved migration IDs in form storage.
+ $form_state->set('migrations', $migration_array);
+ $form_state->set('source_base_path', $source_base_path);
+
+ // Store the retrieved system data in form storage.
+ $form_state->set('system_data', $system_data);
+ }
+ }
+ 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));
+ }
+ }
+
+ /**
+ * Submission handler for the credentials form.
+ *
+ * @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.
+ */
+ public function submitCredentialForm(array &$form, FormStateInterface $form_state) {
+ // Indicate the next step is confirmation.
+ $form_state->set('step', 'confirm');
+ $form_state->setRebuild();
+ }
+
+ /**
+ * Confirmation form for rollbacks, missing migrations, etc.
+ *
+ * @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.
+ *
+ * @return array
+ * The form structure.
+ */
+ public function buildConfirmForm(array $form, FormStateInterface $form_state) {
+ $table_data = [];
+ $system_data = [];
+ foreach ($form_state->get('migrations') as $migration_id => $migration_label) {
+ // Fetch the system data at the first opportunity.
+ if (empty($system_data)) {
+ $system_data = $form_state->get('system_data');
+ }
+
+ // Handle derivatives.
+ list($migration_id,) = explode(':', $migration_id, 2);
+ $source_module = $this->moduleUpgradePaths[$migration_id]['source_module'];
+ $table_data[$source_module][$migration_id] = $migration_label;
+ }
+
+ // Missing migrations.
+ $unmigrated_source_modules = array_filter(array_diff_key($system_data['module'], $table_data), function ($module_data) {
+ return $module_data['status'];
+ });
+ $missing_items = array_map(function ($source_module) {
+ $info = unserialize($source_module['info']);
+ return $info['name'];
+ }, $unmigrated_source_modules);
+ sort($missing_items);
+
+ $form['missing_module_list'] = [
+ '#tree' => FALSE,
+ '#open' => TRUE,
+ '#type' => 'details',
+ '#title' => $this->t('@count Missing upgrade paths', ['@count' => count($missing_items)]),
+ '#description' => $this->t('The following items will not be upgraded. For more information see Upgrading from Drupal 6 or 7 to Drupal 8.', array(':migrate' => 'https://www.drupal.org/upgrade/migrate')),
+ ];
+ $form['missing_module_list']['module_list'] = [
+ '#theme' => 'item_list',
+ '#items' => $missing_items,
+ ];
+
+ // Available migrations.
+ $migrated_source_modules = array_filter(array_intersect_key($system_data['module'], $table_data), function ($module_data) {
+ return $module_data['status'];
+ });
+ $available_items = array_map(function ($source_module) {
+ $info = unserialize($source_module['info']);
+ return $info['name'];
+ }, $migrated_source_modules);
+ sort($available_items);
+
+ $form['available_module_list'] = [
+ '#tree' => TRUE,
+ '#type' => 'details',
+ '#title' => $this->t('@count Available upgrade paths', ['@count' => count($available_items)]),
+ ];
+ $form['available_module_list']['module_list'] = [
+ '#theme' => 'item_list',
+ '#items' => $available_items,
+ ];
+
+ $form['#title'] = $this->getQuestion();
+ $form['#attributes']['class'][] = 'confirmation';
+ $form['description'] = ['#markup' => $this->getDescription()];
+ $form[$this->getFormName()] = ['#type' => 'hidden', '#value' => 1];
+
+ $form['actions'] = ['#type' => 'actions'];
+ $form['actions']['submit'] = [
+ '#type' => 'submit',
+ '#value' => $this->t('Perform upgrade'),
+ '#button_type' => 'primary',
+ '#submit' => ['::submitConfirmForm'],
+ ];
+
+ $form['actions']['cancel'] = [
+ '#type' => 'link',
+ '#title' => $this->getCancelText(),
+ '#attributes' => ['class' => ['button']],
+ '#url' => new Url(''),
+ '#cache' => [
+ 'contexts' => [
+ 'url.query_args:destination',
+ ],
+ ],
+ ];
+ return $form;
+ }
+
+ /**
+ * Submission handler for the confirmation form.
+ *
+ * @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.
+ */
+ public function submitConfirmForm(array &$form, FormStateInterface $form_state) {
+ $storage = $form_state->getStorage();
+
+ $migrations = $storage['migrations'];
+ $config['source_base_path'] = $storage['source_base_path'];
+ $batch = [
+ 'title' => $this->t('Running upgrade'),
+ 'progress_message' => '',
+ 'operations' => [
+ [
+ [MigrateUpgradeImportBatch::class, 'run'],
+ [array_keys($migrations), $config],
+ ],
+ ],
+ 'finished' => [
+ MigrateUpgradeImportBatch::class,
+ 'finished',
+ ],
+ ];
+ batch_set($batch);
+ $form_state->setRedirect('');
+ $this->state->set('migrate_drupal_ui.performed', REQUEST_TIME);
+ }
+
+ /**
+ * 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();
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getQuestion() {
+ return $this->t('Are you sure you want to perform the upgrade?');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getCancelUrl() {
+ return new Url('migrate_drupal_ui.upgrade');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getCancelText() {
+ return $this->t('Cancel');
+ }
+
+ /**
+ * Returns additional text to display as a description.
+ *
+ * @return string
+ * The form description.
+ */
+ public function getDescription() {
+ return '';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function getConfirmText() {
+ return $this->t('Perform upgrade');
+ }
+
+}
only in patch2:
unchanged:
--- a/core/modules/migrate_drupal_ui/src/Tests/MigrateUpgradeTestBase.php
+++ b/core/modules/migrate_drupal_ui/src/Tests/MigrateUpgradeTestBase.php
@@ -134,7 +134,7 @@ protected function testMigrateUpgrade() {
$this->drupalPostForm(NULL, $edits, t('Review upgrade'));
$this->assertResponse(200);
- $this->assertText('Are you sure?');
+ $this->assertText('Are you sure you want to perform the upgrade?');
$this->drupalPostForm(NULL, [], t('Perform upgrade'));
$this->assertText(t('Congratulations, you upgraded Drupal!'));