]> git.agnieray.net Git - galette.git/commitdiff
Fix display issue on connection failure
authorJohan Cwiklinski <johan@x-tnd.be>
Sun, 12 Mar 2023 10:02:43 +0000 (11:02 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Sun, 12 Mar 2023 10:02:43 +0000 (11:02 +0100)
Fix error message

galette/install/steps/db_checks.php
galette/lib/Galette/Core/Db.php
galette/lib/Galette/Core/Install.php

index 9cf1965a6c6f8f1f8ba3c49b3205e3c57613f310..0c456ea19e983c7e235b3a1c88d4909d83d7952f 100644 (file)
 use Galette\Core\Install as GaletteInstall;
 use Galette\Core\Db as GaletteDb;
 
-$db_connected = $install->testDbConnexion();
+try {
+    $db_connected = $install->testDbConnexion();
+} catch (Throwable $e) {
+    $db_connected = $e;
+}
 $conndb_ok = true;
 $permsdb_ok = true;
 
@@ -192,7 +196,6 @@ if ($db_connected !== true) {
     echo '<div class="ui red message">';
     echo '<div class="ui small header">' . _T("Unable to connect to the database") . '</div>';
     echo '<p>' . $db_connected->getMessage() . '</p>';
-    echo '<pre>' . $db_connected->getTraceAsString() . '</pre>';
     echo '</div>';
 }
 
@@ -231,12 +234,14 @@ if (!$conndb_ok) {
         }
         ?>
                 </ul>
+        <?php
+}
+?>
             </div>
         </div>
     </div>
-        <?php
-}
 
+<?php
 if (!isset($install_plugin)) {
 ?>
     <form action="installer.php" method="POST" class="ui form">
index 981a5acd4b65d51b3d4f2a390e941b50083c281d..e77ac2f8b6e1564bf4b861e89988729fd26c4e42 100644 (file)
@@ -277,6 +277,8 @@ class Db
      * @param string $db   database name
      *
      * @return true
+     *
+     * @throws \Exception|Throwable
      */
     public static function testConnectivity(
         $type,
@@ -286,14 +288,13 @@ class Db
         $port = null,
         $db = null
     ) {
-        $_type = null;
         try {
             if ($type === self::MYSQL) {
                 $_type = 'Pdo_Mysql';
             } elseif ($type === self::PGSQL) {
                 $_type = 'Pdo_Pgsql';
             } else {
-                throw new \Exception();
+                throw new \Exception('Unknown database type');
             }
 
             $_options = array(
index e4ba9a8ff39cd6f9492af2b76b23263c38ab04d2..82e874fe30548aa0f602f96b9dbb0f499969d361 100644 (file)
@@ -452,8 +452,9 @@ class Install
     /**
      * Test database connection
      *
-     * @return true|array true if connection was successfull,
-     * an array with some infos otherwise
+     * @return true
+     *
+     * @throws \Exception
      */
     public function testDbConnexion()
     {