diff --git a/core/modules/migrate_drupal_ui/src/Batch/MigrateUpgradeImportBatch.php b/core/modules/migrate_drupal_ui/src/Batch/MigrateUpgradeImportBatch.php index 8d9fd8f..5d60960 100644 --- a/core/modules/migrate_drupal_ui/src/Batch/MigrateUpgradeImportBatch.php +++ b/core/modules/migrate_drupal_ui/src/Batch/MigrateUpgradeImportBatch.php @@ -105,6 +105,7 @@ public static function run($initial_ids, $config, &$context) { if ($definition['destination']['plugin'] === 'entity:file') { // Make sure we have a single trailing slash. $configuration['source']['constants']['source_base_path'] = rtrim($config['source_base_path'], '/') . '/'; + $configuration['source']['constants']['source_private_file_path'] = rtrim($config['source_private_file_path'], '/') . '/'; } /** @var \Drupal\migrate\Plugin\Migration $migration */ diff --git a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php index 6b1fc1b..9ca8a16 100644 --- a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php @@ -426,7 +426,7 @@ class MigrateUpgradeForm extends ConfirmFormBase { 'source_module' => 'simpletest', 'destination_module' => 'simpletest', ], - 'd6_statistics_settings' => [ + 'statistics_settings' => [ 'source_module' => 'statistics', 'destination_module' => 'statistics', ], @@ -862,6 +862,15 @@ public function buildCredentialForm(array $form, FormStateInterface $form_state) $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'), @@ -915,10 +924,47 @@ public function buildCredentialForm(array $form, FormStateInterface $form_state) '#title' => $this->t('Source files'), '#open' => TRUE, ]; - $form['source']['source_base_path'] = [ + $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' => [ + 'invisible' => [ + ':input[name="version"]' => ['value' => 7], + ], + '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' => [ + 'invisible' => [ + ':input[name="version"]' => ['value' => 6], + ], + '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' => [ + 'invisible' => [ + ':input[name="version"]' => ['value' => 6], + ], + 'visible' => [ + ':input[name="version"]' => ['value' => 7], + ], + ], ]; $form['actions'] = ['#type' => 'actions']; @@ -969,6 +1015,12 @@ public function validateCredentialForm(array &$form, FormStateInterface $form_st if (!$version) { $form_state->setErrorByName($database['driver'] . '][0', $this->t('Source database does not contain a recognizable Drupal version.')); } + elseif ($version != $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 { $this->createDatabaseStateSettings($database, $version); $migrations = $this->getMigrations('migrate_drupal_' . $version, $version); @@ -985,7 +1037,10 @@ public function validateCredentialForm(array &$form, FormStateInterface $form_st // Store the retrieved migration IDs in form storage. $form_state->set('migrations', $migration_array); + $form_state->set('version', $form_state->getValue('version')); + $form_state->set('d6_source_base_path', $form_state->getValue('d6_source_base_path')); $form_state->set('source_base_path', $form_state->getValue('source_base_path')); + $form_state->set('source_private_file_path', $form_state->getValue('source_private_file_path')); // Store the retrived system data in form storage. $form_state->set('system_data', $system_data); @@ -1133,7 +1188,13 @@ public function submitConfirmForm(array &$form, FormStateInterface $form_state) $storage = $form_state->getStorage(); $migrations = $storage['migrations']; - $config['source_base_path'] = $storage['source_base_path']; + if ($storage['version'] == '6') { + $config['source_base_path'] = $storage['d6_source_base_path']; + } + else { + $config['source_base_path'] = $storage['source_base_path']; + } + $config['source_private_file_path'] = $storage['source_private_file_path']; $batch = [ 'title' => $this->t('Running upgrade'), 'progress_message' => '', diff --git a/core/modules/migrate_drupal_ui/src/Tests/MigrateUpgradeTestBase.php b/core/modules/migrate_drupal_ui/src/Tests/MigrateUpgradeTestBase.php index 85a9e79..49452af 100644 --- a/core/modules/migrate_drupal_ui/src/Tests/MigrateUpgradeTestBase.php +++ b/core/modules/migrate_drupal_ui/src/Tests/MigrateUpgradeTestBase.php @@ -118,10 +118,15 @@ public function testMigrateUpgrade() { $drivers = drupal_get_database_types(); $form = $drivers[$driver]->getFormOptions($connection_options); $connection_options = array_intersect_key($connection_options, $form + $form['advanced_options']); + $version = $this->getSourceDrupalVersion(); $edit = [ $driver => $connection_options, - 'source_base_path' => $this->getSourceBasePath(), + 'source_private_file_path' => $this->getSourcePrivateFilePath(), + 'version' => $version, ]; + if ($version == 6) { + $edit['d6_source_base_path'] = $this->getSourceBasePath(); + } if (count($drivers) !== 1) { $edit['driver'] = $driver; } @@ -187,6 +192,22 @@ public function testMigrateUpgrade() { abstract protected function getSourceBasePath(); /** + * Gets the source base path for the concrete test. + * + * @return string + * The source base path. + */ + abstract protected function getSourcePrivateFilePath(); + + /** + * Gets the source base path for the concrete test. + * + * @return string + * The source base path. + */ + abstract protected function getSourceDrupalVersion(); + + /** * Gets the expected number of entities per entity type after migration. * * @return int[] diff --git a/core/modules/migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php b/core/modules/migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php index 404f21b..7b0c846 100644 --- a/core/modules/migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php +++ b/core/modules/migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php @@ -32,6 +32,20 @@ protected function getSourceBasePath() { /** * {@inheritdoc} */ + protected function getSourcePrivateFilePath() { + return ''; + } + + /** + * {@inheritdoc} + */ + protected function getSourceDrupalVersion() { + return 6; + } + + /** + * {@inheritdoc} + */ protected function getEntityCounts() { return [ 'block' => 30, diff --git a/core/modules/migrate_drupal_ui/src/Tests/d7/MigrateUpgrade7Test.php b/core/modules/migrate_drupal_ui/src/Tests/d7/MigrateUpgrade7Test.php index 86f1ca9..54b299f 100644 --- a/core/modules/migrate_drupal_ui/src/Tests/d7/MigrateUpgrade7Test.php +++ b/core/modules/migrate_drupal_ui/src/Tests/d7/MigrateUpgrade7Test.php @@ -32,6 +32,20 @@ protected function getSourceBasePath() { /** * {@inheritdoc} */ + protected function getSourcePrivateFilePath() { + return __DIR__ . '/files'; + } + + /** + * {@inheritdoc} + */ + protected function getSourceDrupalVersion() { + return 7; + } + + /** + * {@inheritdoc} + */ protected function getEntityCounts() { return [ 'block' => 25,