[vhffs-dev] [2121] MySQL and PostgreSQL now use datasource string as well

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 2121
Author:   gradator
Date:     2012-03-05 00:38:18 +0100 (Mon, 05 Mar 2012)
Log Message:
-----------
MySQL and PostgreSQL now use datasource string as well

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Robots/Mysql.pm
    trunk/vhffs-api/src/Vhffs/Robots/Pgsql.pm
    trunk/vhffs-api/src/Vhffs.pm
    trunk/vhffs-backend/conf/vhffs.conf.dist.in

Modified: trunk/vhffs-api/src/Vhffs/Robots/Mysql.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Mysql.pm	2012-03-04 22:30:06 UTC (rev 2120)
+++ trunk/vhffs-api/src/Vhffs/Robots/Mysql.pm	2012-03-04 23:38:18 UTC (rev 2121)
@@ -46,11 +46,8 @@
 	use DBI;
 	my $vhffs = shift;
 	my $mysqlconfig = $vhffs->get_config->get_service('mysql');
-	my $dbuser = $mysqlconfig->{'username'};
-	my $dbpass = $mysqlconfig->{'password'};
-	my $dbhost = $mysqlconfig->{'host'};
 
-	return DBI->connect( 'DBI:mysql:dbname=mysql;host='.$dbhost , $dbuser , $dbpass );
+	return DBI->connect( 'DBI:mysql:'.$mysqlconfig->{'datasource'}, $mysqlconfig->{'username'}, $mysqlconfig->{'password'} );
 }
 
 sub create {
@@ -177,11 +174,21 @@
 	my $mysqlconf = $mysql->get_config->get_service('mysql');
 	return undef unless defined $mysqlconf;
 
+	my $dbconf = {};
+	foreach( split /;/, $mysqlconf->{'datasource'} ) {
+		my ( $key, $value ) = split /=/;
+		$dbconf->{$key} = $value;
+	}
+
 	my ( $tmpfile, $tmppath ) = Vhffs::Robots::tmpfile( $mysql->get_vhffs );
 	return undef unless defined $tmpfile;
 
+	my @params;
+	push @params, '-h', $dbconf->{'host'} if defined $dbconf->{'host'};
+	push @params, '-P', $dbconf->{'port'} if defined $dbconf->{'port'};
+
 	my $ret;
-	my $childpid = open( my $output, '-|', $mysqlconf->{'mysqldump_path'}, '-c', '-R', '--hex-blob', '-u', $mysqlconf->{'username'}, '-h', $mysqlconf->{'host'}, '-p'.$mysqlconf->{'password'}, $mysql->get_dbname );
+	my $childpid = open( my $output, '-|', $mysqlconf->{'mysqldump_path'}, '-c', '-R', '--hex-blob', @params, '-u', $mysqlconf->{'username'}, '-p'.$mysqlconf->{'password'}, $mysql->get_dbname );
 	if ($childpid) {
 		# Ensure output is in binary mode
 		binmode($output);

Modified: trunk/vhffs-api/src/Vhffs/Robots/Pgsql.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Pgsql.pm	2012-03-04 22:30:06 UTC (rev 2120)
+++ trunk/vhffs-api/src/Vhffs/Robots/Pgsql.pm	2012-03-04 23:38:18 UTC (rev 2121)
@@ -46,16 +46,8 @@
 	use DBI;
 	my $vhffs = shift;
 	my $pgsqlconfig = $vhffs->get_config->get_service('pgsql');
-	my $dbuser = $pgsqlconfig->{'username'};
-	my $dbpass = $pgsqlconfig->{'password'};
-	my $dbhost = $pgsqlconfig->{'host'};
 
-	# TODO: Change that!
-	if( $dbhost eq 'localhost' ) {
-		return DBI->connect( 'DBI:Pg:dbname=postgres', $dbuser, $dbpass ) or return -1;
-	}
-
-	return DBI->connect( 'DBI:Pg:dbname=postgres;host='.$dbhost, $dbuser, $dbpass ) or return -1;
+	return DBI->connect( 'DBI:Pg:'.$pgsqlconfig->{'datasource'}, $pgsqlconfig->{'username'}, $pgsqlconfig->{'password'} ) or return -1;
 }
 
 sub create {
@@ -178,6 +170,12 @@
 	my $pgsqlconf = $pg->get_config->get_service('pgsql');
 	return undef unless defined $pgsqlconf;
 
+	my $dbconf = {};
+	foreach( split /;/, $pgsqlconf->{'datasource'} ) {
+		my ( $key, $value ) = split /=/;
+		$dbconf->{$key} = $value;
+	}
+
 	# create the postgres password file
 	my ( $pgpassfile, $pgpasspath ) = Vhffs::Robots::tmpfile( $pg->get_vhffs );
 	return undef unless defined $pgpassfile;
@@ -195,7 +193,11 @@
 	my $ret;
 	$ENV{'PGPASSFILE'} = $pgpasspath;
 
-	my $childpid = open( my $output, '-|', $pgsqlconf->{'pgdump_path'}, '-U', $pgsqlconf->{'username'}, '-h', $pgsqlconf->{'host'}, '-b', '-Fc', '-Z0', '-f', $tmppath, $pg->get_dbname );
+	my @params;
+	push @params, '-h', $dbconf->{'host'} if defined $dbconf->{'host'};
+	push @params, '-p', $dbconf->{'port'} if defined $dbconf->{'port'};
+
+	my $childpid = open( my $output, '-|', $pgsqlconf->{'pgdump_path'}, '-U', $pgsqlconf->{'username'}, @params, '-b', '-Fc', '-Z0', '-f', $tmppath, $pg->get_dbname );
 	if ($childpid) {
 		# read process output
 		while(<$output>) {}

Modified: trunk/vhffs-api/src/Vhffs.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs.pm	2012-03-04 22:30:06 UTC (rev 2120)
+++ trunk/vhffs-api/src/Vhffs.pm	2012-03-04 23:38:18 UTC (rev 2121)
@@ -136,10 +136,7 @@
 	}
 
 	if( $config->{'driver'} eq 'pg' )  {
-		my $port = ( $config->{'db_port'} or '5432' );
-		my $host = ( $config->{'db_host'} or 'localhost' );
-
-		my $dbh = DBI->connect('DBI:Pg:'.$config->{'db_datasource'}, $config->{'db_username'}, $config->{'db_password'}, {pg_enable_utf8 => 1} );
+		my $dbh = DBI->connect('DBI:Pg:'.$config->{'datasource'}, $config->{'username'}, $config->{'password'}, {pg_enable_utf8 => 1} );
 		return undef unless defined $dbh;
 		$dbh->do( 'SET CLIENT_ENCODING TO \'UTF8\'' );
 		$self->{'db'} = $dbh;

Modified: trunk/vhffs-backend/conf/vhffs.conf.dist.in
===================================================================
--- trunk/vhffs-backend/conf/vhffs.conf.dist.in	2012-03-04 22:30:06 UTC (rev 2120)
+++ trunk/vhffs-backend/conf/vhffs.conf.dist.in	2012-03-04 23:38:18 UTC (rev 2121)
@@ -146,13 +146,13 @@
 	driver		=	pg
 
 	# Database to use (DBI data source name)
-	db_datasource	=	database=vhffs;host=localhost;port=5432
+	datasource	=	database=vhffs;host=localhost;port=5432
 
 	# Username used to access the database server
-	db_username	=	vhffs
+	username	=	vhffs
 
 	# Password
-	db_password	=	vhffs
+	password	=	vhffs
 </database>
 
 
@@ -254,7 +254,7 @@
 		activate	=	yes
 
 		# Parameters used to connect to MySQL server as admin
-		host		=	localhost
+		datasource	=	database=mysql;host=localhost;port=3306
 		username	=	root
 		password	=	mysecret
 
@@ -274,7 +274,7 @@
 		activate	=	no
 
 		# Parameters used to connect to PostgresSQL server as admin
-		host		=	localhost
+		datasource	=	database=postgres;host=localhost;port=5432
 		username	=	vhffs
 		password	=	mysecret
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/