diff --git a/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php b/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php index 0aca5be..18cc5ca 100644 --- a/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php +++ b/core/modules/migrate_drupal/src/MigrationConfigurationTrait.php @@ -56,7 +56,7 @@ protected function getSystemData(Connection $connection) { $system_data[$result['type']][$result['name']] = $result; } } - catch (\Exception $e) { + catch (\PDOException $e) { // The table might not exist for example in tests. } return $system_data; @@ -183,10 +183,18 @@ protected function getLegacyDrupalVersion(Connection $connection) { // For Drupal 8 (and we're predicting beyond) the schema version is in the // key_value store. elseif ($connection->schema()->tableExists('key_value')) { - $result = $connection - ->query("SELECT value FROM {key_value} WHERE collection = :system_schema and name = :module", [':system_schema' => 'system.schema', ':module' => 'system']) - ->fetchField(); - $version_string = unserialize($result); + try { + $result = $connection + ->query("SELECT value FROM {key_value} WHERE collection = :system_schema and name = :module", [ + ':system_schema' => 'system.schema', + ':module' => 'system' + ]) + ->fetchField(); + $version_string = unserialize($result); + } + catch (\PDOException $e) { + $version_string = FALSE; + } } else { $version_string = FALSE; diff --git a/core/modules/migrate_drupal_ui/src/Form/CredentialForm.php b/core/modules/migrate_drupal_ui/src/Form/CredentialForm.php index deeebe5..a09c35c 100644 --- a/core/modules/migrate_drupal_ui/src/Form/CredentialForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/CredentialForm.php @@ -3,9 +3,12 @@ namespace Drupal\migrate_drupal_ui\Form; use Drupal\Component\Utility\UrlHelper; +use Drupal\Core\Database\DatabaseException; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Render\RendererInterface; use Drupal\Core\TempStore\PrivateTempStoreFactory; +use Drupal\migrate\Exception\RequirementsException; +use Drupal\migrate\Plugin\Exception\BadPluginDefinitionException; use GuzzleHttp\ClientInterface; use GuzzleHttp\Exception\TransferException; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -226,26 +229,45 @@ public function validateForm(array &$form, FormStateInterface $form_state) { } } else { + $error_message = [ + '#title' => $this->t('Resolve the issue below to continue the upgrade.'), + '#theme' => 'item_list', + ]; + // Validate the database connection. try { $connection = $this->getConnection($database); $version = (string) $this->getLegacyDrupalVersion($connection); - if (!$version) { - $this->errors[$database['driver'] . '][database'] = $this->t('Source database does not contain a recognizable Drupal version.'); - } - elseif ($version !== (string) $form_state->getValue('version')) { - $this->errors['version'] = $this->t('Source database is Drupal version @version but version @selected was selected.', - [ + } + catch (DatabaseException $e) { + $error_message['#items'] = [$e->getMessage()]; + $this->errors[$database['driver'] . '][database'] = $this->renderer->renderPlain($error_message); + } + // Validate the Drupal version. + if (!isset($version)) { + $error_message['#items'] = [$this->t('Source database does not contain a recognizable Drupal version.')]; + $this->errors[$database['driver'] . '][database'] = $this->renderer->renderPlain($error_message); + } + else { + if ($version !== (string) $form_state->getValue('version')) { + $message = $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); + ]); + $error_message['#items'] = [$message]; + $this->errors['version'] = $this->renderer->renderPlain($error_message); } } - catch (\Exception $e) { - $this->errors[$database['driver'] . '][database'] = $e->getMessage(); + // Setup migrations and save form data to private store. + try { + $this->setupMigrations($database, $form_state); + } + catch (BadPluginDefinitionException $e) { + $error_message['#items'] = [$e->getMessage()]; + $this->errors[$database['driver'] . '][database'] = $this->renderer->renderPlain($error_message); + } + catch (RequirementsException $e) { + $error_message['#items'] = [$e->getMessage()]; + $this->errors[$database['driver'] . '][database'] = $this->renderer->renderPlain($error_message); } } diff --git a/core/modules/migrate_drupal_ui/src/Form/IncrementalForm.php b/core/modules/migrate_drupal_ui/src/Form/IncrementalForm.php index 8090190..617514f 100644 --- a/core/modules/migrate_drupal_ui/src/Form/IncrementalForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/IncrementalForm.php @@ -2,7 +2,6 @@ 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; @@ -92,29 +91,6 @@ public function buildForm(array $form, FormStateInterface $form_state) { /** * {@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. - } - } - } - - /** - * {@inheritdoc} - */ public function submitForm(array &$form, FormStateInterface $form_state) { $this->store->set('step', 'credential'); $form_state->setRedirect('migrate_drupal_ui.upgrade_credential');