From 61fa673530bbfc947626933c0af0b3e60450ea2f Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Fri, 21 Sep 2018 06:17:09 +1000 Subject: [PATCH] Issue #2864849 by quietone, Jo Fitzgerald, rakesh.gectcr, heddn, yoroy: Improve migrate UI database credential form --- .../src/Form/CredentialForm.php | 28 +++++++++++++++---- .../MigrateUpgradeExecuteTestBase.php | 6 ++-- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/core/modules/migrate_drupal_ui/src/Form/CredentialForm.php b/core/modules/migrate_drupal_ui/src/Form/CredentialForm.php index 85c5782ce46..74b542525ed 100644 --- a/core/modules/migrate_drupal_ui/src/Form/CredentialForm.php +++ b/core/modules/migrate_drupal_ui/src/Form/CredentialForm.php @@ -3,7 +3,6 @@ namespace Drupal\migrate_drupal_ui\Form; use Drupal\Component\Utility\UrlHelper; -use Drupal\Core\Database\DatabaseException; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\TempStore\PrivateTempStoreFactory; use Drupal\migrate\Exception\RequirementsException; @@ -219,12 +218,28 @@ class CredentialForm extends MigrateUpgradeFormBase { } } else { - // Validate the database connection. + $error_key = $database['driver'] . '[database'; try { $connection = $this->getConnection($database); + $version = (string) $this->getLegacyDrupalVersion($connection); + if (!$version) { + $this->errors[$error_key] = $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.', + [ + '@version' => $version, + '@selected' => $form_state->getValue('version'), + ]); + } + else { + // Setup migrations and save form data to private store. + $this->setupMigrations($database, $form_state); + } } - catch (DatabaseException $e) { - $this->errors[$error_key] = $e->getMessage(); + catch (\Exception $e) { + $msg = $this->t('Failed to connect to your database server. The server reports the following message: %error.', ['%error' => $e->getMessage()]); + $this->errors[$error_key] = $msg; } } @@ -274,13 +289,14 @@ class CredentialForm extends MigrateUpgradeFormBase { */ public function validatePaths($element, FormStateInterface $form_state) { if ($source = $element['#value']) { - $msg = $this->t('Unable to read from @title.', ['@title' => $element['#title']]); + $msg = $this->t('Failed to read from @title.', ['@title' => $element['#title']]); if (UrlHelper::isExternal($source)) { try { $this->httpClient->head($source); } catch (TransferException $e) { - $this->errors[$element['#name']] = $msg . ' ' . $e->getMessage(); + $msg .= ' ' . $this->t('The server reports the following message: %error.', ['%error' => $e->getMessage()]); + $this->errors[$element['#name']] = $msg; } } elseif (!file_exists($source) || (!is_dir($source)) || (!is_readable($source))) { diff --git a/core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php b/core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php index fc9529ee401..f165bb7c8e0 100644 --- a/core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php +++ b/core/modules/migrate_drupal_ui/tests/src/Functional/MigrateUpgradeExecuteTestBase.php @@ -90,11 +90,11 @@ abstract class MigrateUpgradeExecuteTestBase extends MigrateUpgradeTestBase { } $this->drupalPostForm(NULL, $paths + $edits, t('Review upgrade')); if ($version == 6) { - $session->responseContains('Unable to read from Files directory.'); + $session->responseContains('Failed to read from Files directory.'); } else { - $session->responseContains('Unable to read from Public files directory.'); - $session->responseContains('Unable to read from Private files directory.'); + $session->responseContains('Failed to read from Public files directory.'); + $session->responseContains('Failed to read from Private files directory.'); } // Restart the upgrade process.