check connection

This commit is contained in:
Roland Gruber 2025-05-14 07:34:27 +02:00
parent 241375dc20
commit 3a285fc63e

View file

@ -1,9 +1,11 @@
<?php <?php
namespace LAM\CONFIG; namespace LAM\CONFIG;
use Exception;
use htmlJavaScript; use htmlJavaScript;
use htmlResponsiveTable; use htmlResponsiveTable;
use LAM\LOGIN\WEBAUTHN\WebauthnManager; use LAM\LOGIN\WEBAUTHN\WebauthnManager;
use LAM\PERSISTENCE\ConfigurationDatabase;
use LAMCfgMain; use LAMCfgMain;
use htmlTable; use htmlTable;
use htmlTitle; use htmlTitle;
@ -145,18 +147,32 @@ if (isset($_POST['submitFormData'])) {
$cfg->configDatabaseUser = $_POST['configDatabaseUser']; $cfg->configDatabaseUser = $_POST['configDatabaseUser'];
$cfg->configDatabasePassword = $_POST['configDatabasePassword']; $cfg->configDatabasePassword = $_POST['configDatabasePassword'];
if ($cfg->configDatabaseType === LAMCfgMain::DATABASE_MYSQL) { if ($cfg->configDatabaseType === LAMCfgMain::DATABASE_MYSQL) {
$mySqlConfigOk = true;
if (empty($cfg->configDatabaseServer) || !get_preg($cfg->configDatabaseServer, 'hostname')) { if (empty($cfg->configDatabaseServer) || !get_preg($cfg->configDatabaseServer, 'hostname')) {
$errors[] = _('Please enter a valid database host name.'); $errors[] = _('Please enter a valid database host name.');
$mySqlConfigOk = false;
} }
if (empty($cfg->configDatabaseName)) { if (empty($cfg->configDatabaseName)) {
$errors[] = _('Please enter a valid database name.'); $errors[] = _('Please enter a valid database name.');
$mySqlConfigOk = false;
} }
if (empty($cfg->configDatabaseUser)) { if (empty($cfg->configDatabaseUser)) {
$errors[] = _('Please enter a valid database user.'); $errors[] = _('Please enter a valid database user.');
$mySqlConfigOk = false;
} }
if (empty($cfg->configDatabasePassword)) { if (empty($cfg->configDatabasePassword)) {
$errors[] = _('Please enter a valid database password.'); $errors[] = _('Please enter a valid database password.');
$mySqlConfigOk = false;
} }
if ($mySqlConfigOk) {
try {
$configurationDatabase = new ConfigurationDatabase($cfg);
$configurationDatabase->checkConnection();
}
catch (Exception $e) {
$errors[] = _('Unable to connect to configuration database.');
}
}
} }
} }
// set master password // set master password