Unverified Commit 61fa6735 authored by larowlan's avatar larowlan

Issue #2864849 by quietone, Jo Fitzgerald, rakesh.gectcr, heddn, yoroy:...

Issue #2864849 by quietone, Jo Fitzgerald, rakesh.gectcr, heddn, yoroy: Improve migrate UI database credential form
parent e22910b9
......@@ -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 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
}
}
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.<ul><li>Is the database server running?</li><li>Does the database exist, and have you entered the correct database name?</li><li>Have you entered the correct username and password?</li><li>Have you entered the correct database hostname?</li></ul>', ['%error' => $e->getMessage()]);
$this->errors[$error_key] = $msg;
}
}
......@@ -274,13 +289,14 @@ public function validateForm(array &$form, FormStateInterface $form_state) {
*/
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))) {
......
......@@ -90,11 +90,11 @@ public function testMigrateUpgradeExecute() {
}
$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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment