diff --git a/core/modules/field/src/Tests/Migrate/d7/MigrateFieldTest.php b/core/modules/field/src/Tests/Migrate/d7/MigrateFieldTest.php index 8d24372..9d6d47e 100644 --- a/core/modules/field/src/Tests/Migrate/d7/MigrateFieldTest.php +++ b/core/modules/field/src/Tests/Migrate/d7/MigrateFieldTest.php @@ -119,5 +119,4 @@ public function testFields() { $this->assertIdentical($migration->getSourcePlugin()->count(), $migration->getIdMap()->processedCount()); } - } diff --git a/core/modules/migrate_drupal/src/MigrationCreationTrait.php b/core/modules/migrate_drupal/src/MigrationCreationTrait.php index 8287ff9..28b3da3 100644 --- a/core/modules/migrate_drupal/src/MigrationCreationTrait.php +++ b/core/modules/migrate_drupal/src/MigrationCreationTrait.php @@ -9,13 +9,14 @@ use Drupal\Core\Database\Connection; use Drupal\Core\Database\Database; -use Drupal\migrate\Entity\Migration; use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\Plugin\RequirementsInterface; -use Drupal\Component\Plugin\Exception\PluginNotFoundException; /** * Creates the appropriate migrations for a given source Drupal database. + * + * @todo https://www.drupal.org/node/2682585 The trait no longer creates + * migrations. */ trait MigrationCreationTrait { @@ -44,8 +45,7 @@ protected function getConnection(array $database) { * @return array * The system data from the system table of the source Drupal database. */ - protected function getSystemData(array $database) { - $connection = $this->getConnection($database); + protected function getSystemData(Connection $connection) { $system_data = []; try { $results = $connection->select('system', 's', [ @@ -64,29 +64,19 @@ protected function getSystemData(array $database) { } /** - * Get the database connection for the source database. + * Creates the necessary state entries for SqlBase::getDatabase() to work. * * @param array $database - * The database connection. - * - * @return \Drupal\Core\Database\Connection - * The database connection. - * - * @throws \Exception + * The source database settings. + * @param string $drupal_version + * The drupal version. */ - protected function getSourceDatabaseConnection(array $database) { - // Set up the connection. - $connection = $this->getConnection($database); - if (!$drupal_version = $this->getLegacyDrupalVersion($connection)) { - throw new \Exception('Source database does not contain a recognizable Drupal version.'); - } + protected function createDatabaseStateSettings(array $database, $drupal_version) { $database_state['key'] = 'upgrade'; $database_state['database'] = $database; $database_state_key = 'migrate_drupal_' . $drupal_version; \Drupal::state()->set($database_state_key, $database_state); \Drupal::state()->set('migrate.fallback_state_key', $database_state_key); - - return $connection; } /** @@ -108,8 +98,8 @@ protected function getMigrations($database_state_key, $drupal_version) { $migrations = []; foreach ($all_migrations as $migration) { try { - // @TODO, we should be able to validate the entire migration at this - // point. https://drupal.org/node/2625696 + // @todo https://drupal.org/node/2681867 We should be able to validate + // the entire migration at this point. $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 7476d18..f64549d 100644 --- a/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/MigrateUpgradeForm.php @@ -946,40 +946,46 @@ public function validateCredentialForm(array &$form, FormStateInterface $form_st } } - try { - $version = $this->getLegacyDrupalVersion($this->getSourceDatabaseConnection($database)); - $migrations = $this->getMigrations('migrate_drupal_' . $version, $version); - - // Get the system data from source database. - $system_data = $this->getSystemData($database); - - // 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 from storage. - $form_state->set('system_data', $system_data); + $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.')); } - catch (\Exception $e) { - $error_message = [ - '#type' => 'inline_template', - '#template' => '{% trans %}Resolve the issue below to continue the upgrade.{% endtrans%}{{ errors }}', - '#context' => [ - 'errors' => [ - '#theme' => 'item_list', - '#items' => [$e->getMessage()], + else { + try { + $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 from storage. + $form_state->set('system_data', $system_data); + } catch (\Exception $e) { + $error_message = [ + '#type' => 'inline_template', + '#template' => '{% trans %}Resolve the issue below to continue the upgrade.{% endtrans%}{{ errors }}', + '#context' => [ + 'errors' => [ + '#theme' => 'item_list', + '#items' => [$e->getMessage()], + ], ], - ], - ]; + ]; - $form_state->setErrorByName($database['driver'] . '][0', $this->renderer->renderPlain($error_message)); + $form_state->setErrorByName($database['driver'] . '][0', $this->renderer->renderPlain($error_message)); + } } } diff --git a/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php b/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php index ee63aa8..97c9329 100644 --- a/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php +++ b/core/modules/node/src/Plugin/migrate/D6NodeDeriver.php @@ -123,7 +123,7 @@ public function getDerivativeDefinitions($base_plugin_definition) { } } catch (\Exception $e) { - // @TODO https://www.drupal.org/node/2666640 + // It is possible no D6 tables are loaded so just eat exceptions. } return $this->derivatives; } diff --git a/core/modules/taxonomy/src/Plugin/migrate/D6TermNodeDeriver.php b/core/modules/taxonomy/src/Plugin/migrate/D6TermNodeDeriver.php index 8bcf6ae..539be68 100644 --- a/core/modules/taxonomy/src/Plugin/migrate/D6TermNodeDeriver.php +++ b/core/modules/taxonomy/src/Plugin/migrate/D6TermNodeDeriver.php @@ -50,7 +50,7 @@ public function getDerivativeDefinitions($base_plugin_definition, $base_plugin_d } } catch (\Exception $e) { - // @TODO https://www.drupal.org/node/2666640 + // It is possible no D6 tables are loaded so just eat exceptions. } return $this->derivatives; } diff --git a/core/modules/user/src/Plugin/migrate/ProfileValues.php b/core/modules/user/src/Plugin/migrate/ProfileValues.php index ca7b363..202e3c4 100644 --- a/core/modules/user/src/Plugin/migrate/ProfileValues.php +++ b/core/modules/user/src/Plugin/migrate/ProfileValues.php @@ -7,6 +7,7 @@ namespace Drupal\user\Plugin\migrate; +use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\Plugin\Migration; /** @@ -39,7 +40,7 @@ public function getProcess() { $this->process[$name] = $name; } } - catch (\Exception $e) { + catch (RequirementsException $e) { // @TODO https://www.drupal.org/node/2666640 } }