[Pkg-owncloud-commits] [owncloud] 221/394: postgresql connect with specify db if 'postgres' does not work
David Prévot
taffit at alioth.debian.org
Fri Nov 8 23:12:10 UTC 2013
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to annotated tag v4.5.10
in repository owncloud.
commit fbd399ff1d03299b9089f059d1c40a55a77ac086
Author: Brice Maron <brice at bmaron.net>
Date: Thu Dec 13 18:25:14 2012 +0000
postgresql connect with specify db if 'postgres' does not work
---
lib/setup.php | 111 ++++++++++++++++++++++++++++++---------------------------
1 file changed, 58 insertions(+), 53 deletions(-)
diff --git a/lib/setup.php b/lib/setup.php
index a9bdba7..787ef5c 100644
--- a/lib/setup.php
+++ b/lib/setup.php
@@ -176,69 +176,74 @@ class OC_Setup {
$connection_string = "host='$e_host' dbname=postgres user='$e_user' password='$e_password'";
$connection = @pg_connect($connection_string);
if(!$connection) {
- $error[] = array(
- 'error' => 'PostgreSQL username and/or password not valid',
- 'hint' => 'You need to enter either an existing account or the administrator.'
- );
- return $error;
+ $e_dbname = addslashes($dbname);
+ //Try to connect directly to the specified DB
+ $connection_string = "host='$e_host' dbname='$e_dbname' user='$e_user' password='$e_password'";
+ $connection = @pg_connect($connection_string);
+ if(!$connection) {
+ $error[] = array(
+ 'error' => 'PostgreSQL username and/or password not valid',
+ 'hint' => 'You need to enter either an existing account or the administrator.'
+ );
+ return $error;
+ }
}
- else {
- $e_user = pg_escape_string($dbuser);
- //check for roles creation rights in postgresql
- $query="SELECT 1 FROM pg_roles WHERE rolcreaterole=TRUE AND rolname='$e_user'";
- $result = pg_query($connection, $query);
- if($result and pg_num_rows($result) > 0) {
- //use the admin login data for the new database user
- //add prefix to the postgresql user name to prevent collisions
- $dbusername='oc_'.$username;
- //create a new password so we don't need to store the admin config in the config file
- $dbpassword=md5(time());
+ $e_user = pg_escape_string($dbuser);
+ //check for roles creation rights in postgresql
+ $query="SELECT 1 FROM pg_roles WHERE rolcreaterole=TRUE AND rolname='$e_user'";
+ $result = pg_query($connection, $query);
+ if($result and pg_num_rows($result) > 0) {
+ //use the admin login data for the new database user
- self::pg_createDBUser($dbusername, $dbpassword, $connection);
+ //add prefix to the postgresql user name to prevent collisions
+ $dbusername='oc_'.$username;
+ //create a new password so we don't need to store the admin config in the config file
+ $dbpassword=md5(time());
- OC_CONFIG::setValue('dbuser', $dbusername);
- OC_CONFIG::setValue('dbpassword', $dbpassword);
+ self::pg_createDBUser($dbusername, $dbpassword, $connection);
- //create the database
- self::pg_createDatabase($dbname, $dbusername, $connection);
- }
- else {
- OC_CONFIG::setValue('dbuser', $dbuser);
- OC_CONFIG::setValue('dbpassword', $dbpass);
+ OC_CONFIG::setValue('dbuser', $dbusername);
+ OC_CONFIG::setValue('dbpassword', $dbpassword);
- //create the database
- self::pg_createDatabase($dbname, $dbuser, $connection);
- }
+ //create the database
+ self::pg_createDatabase($dbname, $dbusername, $connection);
+ }
+ else {
+ OC_CONFIG::setValue('dbuser', $dbuser);
+ OC_CONFIG::setValue('dbpassword', $dbpass);
- // the connection to dbname=postgres is not needed anymore
- pg_close($connection);
+ //create the database
+ self::pg_createDatabase($dbname, $dbuser, $connection);
+ }
- // connect to the ownCloud database (dbname=$dbname) an check if it needs to be filled
- $dbuser = OC_CONFIG::getValue('dbuser');
- $dbpass = OC_CONFIG::getValue('dbpassword');
+ // the connection to dbname=postgres is not needed anymore
+ pg_close($connection);
- $e_host = addslashes($dbhost);
- $e_dbname = addslashes($dbname);
- $e_user = addslashes($dbuser);
- $e_password = addslashes($dbpass);
+ // connect to the ownCloud database (dbname=$dbname) an check if it needs to be filled
+ $dbuser = OC_CONFIG::getValue('dbuser');
+ $dbpass = OC_CONFIG::getValue('dbpassword');
- $connection_string = "host='$e_host' dbname='$e_dbname' user='$e_user' password='$e_password'";
- $connection = @pg_connect($connection_string);
- if(!$connection) {
- $error[] = array(
- 'error' => 'PostgreSQL username and/or password not valid',
- 'hint' => 'You need to enter either an existing account or the administrator.'
- );
- } else {
- $query = "select count(*) FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1";
- $result = pg_query($connection, $query);
- if($result) {
- $row = pg_fetch_row($result);
- }
- if(!$result or $row[0]==0) {
- OC_DB::createDbFromStructure('db_structure.xml');
- }
+ $e_host = addslashes($dbhost);
+ $e_dbname = addslashes($dbname);
+ $e_user = addslashes($dbuser);
+ $e_password = addslashes($dbpass);
+
+ $connection_string = "host='$e_host' dbname='$e_dbname' user='$e_user' password='$e_password'";
+ $connection = @pg_connect($connection_string);
+ if(!$connection) {
+ $error[] = array(
+ 'error' => 'PostgreSQL username and/or password not valid',
+ 'hint' => 'You need to enter either an existing account or the administrator.'
+ );
+ } else {
+ $query = "select count(*) FROM pg_class WHERE relname='{$dbtableprefix}users' limit 1";
+ $result = pg_query($connection, $query);
+ if($result) {
+ $row = pg_fetch_row($result);
+ }
+ if(!$result or $row[0]==0) {
+ OC_DB::createDbFromStructure('db_structure.xml');
}
}
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git
More information about the Pkg-owncloud-commits
mailing list