diff --git a/core/modules/file/src/Plugin/migrate/source/d7/File.php b/core/modules/file/src/Plugin/migrate/source/d7/File.php index 0c1b00d..93d92e4 100644 --- a/core/modules/file/src/Plugin/migrate/source/d7/File.php +++ b/core/modules/file/src/Plugin/migrate/source/d7/File.php @@ -89,11 +89,9 @@ public function prepareRow(Row $row) { // At this point, $path could be an absolute path or a relative path, // depending on how the scheme's variable was set. So we need to shear out // the source_base_path in order to make them all relative. - // @todo Don't depend on destination configuration. - // @see https://www.drupal.org/node/2577871 - - // @TODO, figure out why this is done here and not the destination. - // $path = str_replace($this->migration->get('destination')['source_base_path'], NULL, $path); + // @todo Don't depend on destination configuration and figure out if this is + // even needed at all? https://www.drupal.org/node/2577871 + $path = str_replace($this->migration->get('destination')['source_base_path'], NULL, $path); $row->setSourceProperty('filepath', $path); return parent::prepareRow($row); } diff --git a/core/modules/migrate_drupal/src/MigrationCreationTrait.php b/core/modules/migrate_drupal/src/MigrationCreationTrait.php index 8cd2373..8287ff9 100644 --- a/core/modules/migrate_drupal/src/MigrationCreationTrait.php +++ b/core/modules/migrate_drupal/src/MigrationCreationTrait.php @@ -96,37 +96,20 @@ protected function getSourceDatabaseConnection(array $database) { * The state key. * @param int $drupal_version * The version of Drupal we're getting the migrations for. - * @param string $source_base_path - * (optional) Address of the source Drupal site (e.g., http://example.com/). * * @return \Drupal\migrate\Entity\MigrationInterface[] * The migrations for import. */ - protected function getMigrations($database_state_key, $drupal_version, $source_base_path = '') { + protected function getMigrations($database_state_key, $drupal_version) { $version_tag = 'Drupal ' . $drupal_version; $plugin_manager = \Drupal::service('plugin.manager.migration'); /** @var \Drupal\migrate\Plugin\Migration[] $all_migrations */ $all_migrations = $plugin_manager->createInstancesByTag($version_tag); $migrations = []; foreach ($all_migrations as $migration) { - // @TODO :/ -// // Set the state key into the source. -// $source = $migration->get('source'); -// $source['database_state_key'] = $database_state_key; -// $migration->set('source', $source); -// -// // Setup the destination for the file destination. -// $destination = $migration->get('destination'); -// if ($destination['plugin'] == 'entity:file') { -// if ($source_base_path) { -// // Make sure we have a single trailing slash. -// $source_base_path = rtrim($source_base_path, '/') . '/'; -// $destination['source_base_path'] = $source_base_path; -// $migration->set('destination', $destination); -// } -// } - try { + // @TODO, we should be able to validate the entire migration at this + // point. https://drupal.org/node/2625696 $source_plugin = $migration->getSourcePlugin(); if ($source_plugin instanceof RequirementsInterface) { $source_plugin->checkRequirements(); diff --git a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php index 938f3c9..7476d18 100644 --- a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php @@ -948,7 +948,7 @@ public function validateCredentialForm(array &$form, FormStateInterface $form_st try { $version = $this->getLegacyDrupalVersion($this->getSourceDatabaseConnection($database)); - $migrations = $this->getMigrations('migrate_drupal_' . $version, $version, $form_state->getValue('source_base_path')); + $migrations = $this->getMigrations('migrate_drupal_' . $version, $version); // Get the system data from source database. $system_data = $this->getSystemData($database); @@ -962,6 +962,7 @@ 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('source_base_path', $form_state->getValue('source_base_path')); // Store the retrived system data in from storage. $form_state->set('system_data', $system_data); @@ -1143,7 +1144,7 @@ public function submitConfirmForm(array &$form, FormStateInterface $form_state) 'operations' => [ [ [MigrateUpgradeRunBatch::class, 'run'], - [array_keys($migrations), 'rollback'], + [array_keys($migrations), 'rollback', []], ], ], 'finished' => [ @@ -1157,13 +1158,14 @@ public function submitConfirmForm(array &$form, FormStateInterface $form_state) } else { $migrations = $storage['migrations']; + $config['source_base_path'] = $storage['source_base_path']; $batch = [ 'title' => $this->t('Running upgrade'), 'progress_message' => '', 'operations' => [ [ [MigrateUpgradeRunBatch::class, 'run'], - [array_keys($migrations), 'import'], + [array_keys($migrations), 'import', $config], ], ], 'finished' => [ diff --git a/core/modules/migrate_drupal_ui/src/MigrateUpgradeRunBatch.php b/core/modules/migrate_drupal_ui/src/MigrateUpgradeRunBatch.php index dba824d..46bb33c 100644 --- a/core/modules/migrate_drupal_ui/src/MigrateUpgradeRunBatch.php +++ b/core/modules/migrate_drupal_ui/src/MigrateUpgradeRunBatch.php @@ -65,10 +65,12 @@ class MigrateUpgradeRunBatch { * The full set of migration IDs to import. * @param string $operation * The operation to perform, 'import' or 'rollback'. + * @param array $config + * An array of additional configuration from the form. * @param array $context * The batch context. */ - public static function run($initial_ids, $operation, &$context) { + public static function run($initial_ids, $operation, $config, &$context) { if (!static::$listenersAdded) { $event_dispatcher = \Drupal::service('event_dispatcher'); if ($operation == 'import') { @@ -109,6 +111,16 @@ public static function run($initial_ids, $operation, &$context) { $migration_id = reset($context['sandbox']['migration_ids']); /** @var \Drupal\migrate\Plugin\Migration $migration */ $migration = \Drupal::service('plugin.manager.migration')->createInstance($migration_id); + + // @TODO, remove this in https://www.drupal.org/node/2681869. + $destination = $migration->get('destination'); + if ($destination['plugin'] === 'entity:file') { + // Make sure we have a single trailing slash. + $source_base_path = rtrim($config['source_base_path'], '/') . '/'; + $destination['source_base_path'] = $source_base_path; + $migration->set('destination', $destination); + } + if ($migration) { static::$messages = new MigrateMessageCapture(); $executable = new MigrateExecutable($migration, static::$messages); 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 597492a..fd4ab62 100644 --- a/core/modules/migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php +++ b/core/modules/migrate_drupal_ui/src/Tests/d6/MigrateUpgrade6Test.php @@ -30,7 +30,7 @@ protected function setUp() { * {@inheritdoc} */ protected function getSourceBasePath() { - return __DIR__ . '/files'; + return './'; } /**