Explorar el Código

Fix PostgreSQL database auto-create with limited rights (#3013)

* Fix PostgreSQL database auto-create with limited rights

#fix https://github.com/FreshRSS/FreshRSS/issues/3009
Install would fail if the user is not even allowed to connect to the default `postgres` database.

* Confused by custom Minz_PDOConnectionException
Alexandre Alapetite hace 5 años
padre
commit
fe1e02dab9
Se han modificado 2 ficheros con 12 adiciones y 6 borrados
  1. 2 2
      app/Models/DatabaseDAO.php
  2. 10 4
      lib/lib_install.php

+ 2 - 2
app/Models/DatabaseDAO.php

@@ -21,7 +21,7 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo {
 		try {
 		try {
 			$sql = sprintf($SQL_CREATE_DB, empty($db['base']) ? '' : $db['base']);
 			$sql = sprintf($SQL_CREATE_DB, empty($db['base']) ? '' : $db['base']);
 			return $this->pdo->exec($sql) !== false;
 			return $this->pdo->exec($sql) !== false;
-		} catch (PDOException $e) {
+		} catch (Exception $e) {
 			$_SESSION['bd_error'] = $e->getMessage();
 			$_SESSION['bd_error'] = $e->getMessage();
 			syslog(LOG_DEBUG, __method__ . ' warning: ' . $e->getMessage());
 			syslog(LOG_DEBUG, __method__ . ' warning: ' . $e->getMessage());
 			return false;
 			return false;
@@ -34,7 +34,7 @@ class FreshRSS_DatabaseDAO extends Minz_ModelPdo {
 			$stm = $this->pdo->query($sql);
 			$stm = $this->pdo->query($sql);
 			$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
 			$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
 			return $res != false;
 			return $res != false;
-		} catch (PDOException $e) {
+		} catch (Exception $e) {
 			$_SESSION['bd_error'] = $e->getMessage();
 			$_SESSION['bd_error'] = $e->getMessage();
 			syslog(LOG_DEBUG, __method__ . ' warning: ' . $e->getMessage());
 			syslog(LOG_DEBUG, __method__ . ' warning: ' . $e->getMessage());
 			return false;
 			return false;

+ 10 - 4
lib/lib_install.php

@@ -94,13 +94,19 @@ function initDb() {
 		//For first connection, use default database for PostgreSQL, empty database for MySQL / MariaDB:
 		//For first connection, use default database for PostgreSQL, empty database for MySQL / MariaDB:
 		$db['base'] = $db['type'] === 'pgsql' ? 'postgres' : '';
 		$db['base'] = $db['type'] === 'pgsql' ? 'postgres' : '';
 		$conf->db = $db;
 		$conf->db = $db;
-		//First connection without database name to create the database
-		$databaseDAO = FreshRSS_Factory::createDatabaseDAO();
+		try {
+			//First connection without database name to create the database
+			$databaseDAO = FreshRSS_Factory::createDatabaseDAO();
+		} catch (Exception $ex) {
+			$databaseDAO = null;
+		}
 		//Restore final database parameters for auto-creation and for future connections
 		//Restore final database parameters for auto-creation and for future connections
 		$db['base'] = $dbBase;
 		$db['base'] = $dbBase;
 		$conf->db = $db;
 		$conf->db = $db;
-		//Perfom database auto-creation
-		$databaseDAO->create();
+		if ($databaseDAO != null) {
+			//Perfom database auto-creation
+			$databaseDAO->create();
+		}
 	}
 	}
 
 
 	//New connection with the database name
 	//New connection with the database name