[vhffs-dev] [1157] This should fix issue #0000234.

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


Revision: 1157
Author:   beuss
Date:     2008-02-14 12:49:39 +0000 (Thu, 14 Feb 2008)

Log Message:
-----------
This should fix issue #0000234.

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Panel/Pgsql.pm
    trunk/vhffs-api/src/Vhffs/Robots/Pgsql.pm
    trunk/vhffs-api/src/Vhffs/Services/Pgsql.pm
    trunk/vhffs-backend/src/pgsql/initdb.sql.in
    trunk/vhffs-panel/pgsql/create.pl
    trunk/vhffs-panel/templates/pgsql/create.tmpl


Modified: trunk/vhffs-api/src/Vhffs/Panel/Pgsql.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Pgsql.pm	2008-02-14 12:37:30 UTC (rev 1156)
+++ trunk/vhffs-api/src/Vhffs/Panel/Pgsql.pm	2008-02-14 12:49:39 UTC (rev 1157)
@@ -107,12 +107,12 @@
 
 sub create_pgsql
 {
-    my( $main , $dbname , $user , $group , $dbuser , $dbpass, $description ) = @_;
+    my( $main , $dbname , $user , $group , $dbuser , $dbpass, $dbencoding, $description ) = @_;
 
     return -1 if( ! defined $user );
     return -2 if( ! defined $group );
     
-    my $pgsql = Vhffs::Services::Pgsql::create($main, $dbname, $dbuser, $dbpass, $description, $user, $group);
+    my $pgsql = Vhffs::Services::Pgsql::create($main, $dbname, $dbuser, $dbpass, $dbencoding, $description, $user, $group);
 
 	return undef if( ! defined $pgsql );
 	

Modified: trunk/vhffs-api/src/Vhffs/Robots/Pgsql.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Pgsql.pm	2008-02-14 12:37:30 UTC (rev 1156)
+++ trunk/vhffs-api/src/Vhffs/Robots/Pgsql.pm	2008-02-14 12:49:39 UTC (rev 1157)
@@ -65,7 +65,7 @@
 	
 	if( defined $pg )
 	{
-		$db->do('CREATE DATABASE '.$pg->get_dbname );
+		$db->do('CREATE DATABASE '.$pg->get_dbname.' ENCODING \''.$pg->get_dbencoding.'\'' );
 		$db->do('CREATE USER '.$pg->get_dbusername.' WITH PASSWORD ?', undef, $pg->get_dbpassword);
 		$pg->set_status( Vhffs::Constants::ACTIVATED );	
 		$pg->commit;

Modified: trunk/vhffs-api/src/Vhffs/Services/Pgsql.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/Pgsql.pm	2008-02-14 12:37:30 UTC (rev 1156)
+++ trunk/vhffs-api/src/Vhffs/Services/Pgsql.pm	2008-02-14 12:49:39 UTC (rev 1157)
@@ -54,6 +54,48 @@
 use base qw(Vhffs::Object);
 use DBI;
 
+my $supported_encodings = {
+    BIG5        => 1,
+    EUC_CN      => 1,
+    EUC_JP      => 1,
+    EUC_KR      => 1,
+    EUC_TW      => 1,
+    GB18030     => 1,
+    GBK         => 1,
+    ISO_8859_5  => 1,
+    ISO_8859_6  => 1,
+    ISO_8859_7  => 1,
+    ISO_8859_8  => 1,
+    JOHAB       => 1,
+    KOI8        => 1,
+    LATIN1      => 1,
+    LATIN2      => 1,
+    LATIN3      => 1,
+    LATIN4      => 1,
+    LATIN5      => 1,
+    LATIN6      => 1,
+    LATIN7      => 1,
+    LATIN8      => 1,
+    LATIN9      => 1,
+    LATIN10     => 1,
+    MULE_INTERNAL   => 1,
+    SJIS        => 1,
+    SQL_ASCII   => 1,
+    UHC         => 1,
+    UTF8        => 1,
+    WIN866      => 1,
+    WIN874      => 1,
+    WIN1250     => 1,
+    WIN1251     => 1,
+    WIN1252     => 1,
+    WIN1256     => 1,
+    WIN1258     => 1
+};
+
+sub get_supported_encodings() {
+    return $supported_encodings;
+}
+
 =pod
 
 =head2 check_dbname
@@ -125,9 +167,9 @@
 =cut
 
 sub create {
-    my ($main, $dbname, $dbuser, $dbpass, $description, $user, $group) = @_;
+    my ($main, $dbname, $dbuser, $dbpass, $dbencoding, $description, $user, $group) = @_;
     return undef unless(defined($user) && defined($group));
-    return undef unless(check_dbname($dbname) && check_dbpass($dbpass) && check_dbuser($dbuser));
+    return undef unless(check_dbname($dbname) && check_dbpass($dbpass) && check_dbuser($dbuser) && defined $supported_encodings->{$dbencoding});
 
     my $pg;
     my $dbh = $main->get_db_object();
@@ -140,9 +182,9 @@
         my $parent = Vhffs::Object::create($main, $user->get_uid, $group->get_gid, $description, undef, Vhffs::Constants::TYPE_PGSQL);
         die('Unable to create parent object') unless defined ($parent);
 
-        my $sql = 'INSERT INTO vhffs_pgsql(dbname, dbuser, dbpass, object_id) VALUES(?, ?, ?, ?)';
+        my $sql = 'INSERT INTO vhffs_pgsql(dbname, dbuser, dbpass, dbencoding, object_id) VALUES(?, ?, ?, ?, ?)';
         my $sth = $dbh->prepare($sql);
-        $sth->execute($dbname, $dbuser, $dbpass, $parent->get_oid);
+        $sth->execute($dbname, $dbuser, $dbpass, $dbencoding, $parent->get_oid);
 
         $dbh->commit;
         $pg = get_by_dbname($main, $dbname);
@@ -213,6 +255,12 @@
 	return 1;
 }
 
+sub get_dbencoding
+{
+    my $self = shift;
+    return $self->{dbencoding};
+}
+
 sub blank_password
 {   
     my $self = shift;
@@ -223,7 +271,7 @@
 }
 
 sub _new {
-    my ($class, $main, $pgsql_id, $owner_gid, $dbname, $dbuser, $dbpass, $oid, $owner_uid, $date_creation, $state, $description) = @_;
+    my ($class, $main, $pgsql_id, $owner_gid, $dbname, $dbuser, $dbpass, $dbencoding, $oid, $owner_uid, $date_creation, $state, $description) = @_;
     my $self = $class->SUPER::_new($main, $oid, $owner_uid, $owner_gid, $date_creation, $description, '', $state, Vhffs::Constants::TYPE_PGSQL);
     return undef unless(defined $self);
 
@@ -231,6 +279,7 @@
     $self->{dbname} = $dbname;
     $self->{dbuser} = $dbuser;
     $self->{dbpass} = $dbpass;
+    $self->{dbencoding} = $dbencoding;
     return $self;
 }
 
@@ -248,7 +297,7 @@
 sub get_by_dbname($$) {
     my ($vhffs, $dbname) = @_;
 
-    my $sql = q{SELECT m.pgsql_id, o.owner_gid, m.dbname, m.dbuser, m.dbpass, o.object_id, o.owner_uid, o.date_creation, o.state, o.description FROM vhffs_pgsql m INNER JOIN vhffs_object o ON o.object_id = m.object_id WHERE m.dbname = ?};
+    my $sql = q{SELECT m.pgsql_id, o.owner_gid, m.dbname, m.dbuser, m.dbpass, m.dbencoding, o.object_id, o.owner_uid, o.date_creation, o.state, o.description FROM vhffs_pgsql m INNER JOIN vhffs_object o ON o.object_id = m.object_id WHERE m.dbname = ?};
     my $dbh = $vhffs->get_db_object();
     my @params;
     return undef unless(@params = $dbh->selectrow_array($sql, undef, $dbname));
@@ -264,7 +313,7 @@
 =cut
 sub fill_object {
     my ($class, $obj) = @_;
-    my $sql = q{SELECT pgsql_id, dbname, dbuser, dbpass FROM vhffs_pgsql
+    my $sql = q{SELECT pgsql_id, dbname, dbuser, dbpass, dbencoding FROM vhffs_pgsql
         WHERE object_id = ?};
     return $class->SUPER::_fill_object($obj, $sql);
 }
@@ -276,7 +325,7 @@
     my $postgres = [];
     my @params;
 
-    my $sql = 'SELECT p.pgsql_id, o.owner_gid, p.dbname, p.dbuser, p.dbpass, o.object_id, o.owner_uid, o.date_creation, o.state, o.description FROM vhffs_pgsql p, vhffs_object o WHERE p.object_id = o.object_id';
+    my $sql = 'SELECT p.pgsql_id, o.owner_gid, p.dbname, p.dbuser, p.dbpass, p.dbencoding, o.object_id, o.owner_uid, o.date_creation, o.state, o.description FROM vhffs_pgsql p, vhffs_object o WHERE p.object_id = o.object_id';
 
     if(defined $state) {
         $sql .= ' AND o.state = ?';

Modified: trunk/vhffs-backend/src/pgsql/initdb.sql.in
===================================================================
--- trunk/vhffs-backend/src/pgsql/initdb.sql.in	2008-02-14 12:37:30 UTC (rev 1156)
+++ trunk/vhffs-backend/src/pgsql/initdb.sql.in	2008-02-14 12:49:39 UTC (rev 1157)
@@ -241,6 +241,7 @@
 	dbname varchar(200) NOT NULL,
 	dbuser varchar(32) NOT NULL,
 	dbpass varchar(32) NOT NULL,
+    dbencoding varchar(20) NOT NULL DEFAULT 'LATIN1',
 	object_id int4 NOT NULL,
 	CONSTRAINT vhffs_pgsql_pkey PRIMARY KEY (pgsql_id)
 ) WITH OIDS;

Modified: trunk/vhffs-panel/pgsql/create.pl
===================================================================
--- trunk/vhffs-panel/pgsql/create.pl	2008-02-14 12:37:30 UTC (rev 1156)
+++ trunk/vhffs-panel/pgsql/create.pl	2008-02-14 12:49:39 UTC (rev 1157)
@@ -75,6 +75,7 @@
 		$dbsuffix = $dbsuffix = $cgi->param('db_suffix');
 		my $dbname = $groupname.'_'.$dbsuffix;
 		my $dbuser = $dbname;
+		my $dbencoding = $cgi->param('db_encoding');
 		$dbpass = $cgi->param('db_pass');
 		$description = $cgi->param('description');
 
@@ -86,7 +87,9 @@
 			$panel->add_error( gettext('Invalid database name, it must contain only numbers, lowercase letters and underscore (the latter isn\'t allowed in first or last position) and be between 3 and 32 characters.') );
 		} elsif(!Vhffs::Services::Pgsql::check_dbpass($dbpass)) {
 			$panel->add_error( gettext('Invalid password. It must be at least 3 chars') );
-		} elsif(defined Vhffs::Panel::Pgsql::create_pgsql($vhffs, $dbname, $user, $group, $dbuser, $dbpass, $description)) {
+		} elsif(! defined Vhffs::Services::Pgsql::get_supported_encodings()->{$dbencoding}) {
+		    $panel->add_error( gettext('Invalid encoding') );
+		} elsif(defined Vhffs::Panel::Pgsql::create_pgsql($vhffs, $dbname, $user, $group, $dbuser, $dbpass, $dbencoding, $description)) {
 			my $url = '/group/view.pl?project='.$panel->{groupname}.'&msg='.gettext('The PostgreSQL DB was successfully created !');
 			$panel->redirect($url);
 		} else {
@@ -105,6 +108,11 @@
 		$template->param( DB_SUFFIX => gettext("PostgreSQL database name ") );
 		$template->param( DB_SUFFIX_VALUE => $dbsuffix );
 		$template->param( DB_PASS => gettext("PostgreSQL password for this database ") );
+		$template->param( DB_SELECT_ENCODING => gettext("Database encoding"));
+		# CAN'T HTML::Template RENDER A SIMPLE ARRAY?! THIS SIMPLY SUCKS!
+		my @encodings = map +{'encoding' => $_}, keys %{Vhffs::Services::Pgsql::get_supported_encodings()};
+		@encodings = sort { return -1 if($a->{'encoding'} eq 'UTF8'); return 1 if($b->{encoding} eq 'UTF8'); return $a->{encoding} cmp $b->{encoding}} @encodings;
+		$template->param( DB_ENCODINGS =>  \@encodings);
 		$template->param( GROUP => $groupname );
 		$template->param( SEND => gettext("Send") );
 		$template->param( DESCRIPTION => gettext("Description") );

Modified: trunk/vhffs-panel/templates/pgsql/create.tmpl
===================================================================
--- trunk/vhffs-panel/templates/pgsql/create.tmpl	2008-02-14 12:37:30 UTC (rev 1156)
+++ trunk/vhffs-panel/templates/pgsql/create.tmpl	2008-02-14 12:49:39 UTC (rev 1157)
@@ -16,9 +16,19 @@
 		<label for="db_pass">
 			<TMPL_VAR ESCAPE=1 NAME="DB_PASS">: 
 		</label>
-		<input type="PASSWORD" name="db_pass" id="db_pass"/>
+		<input type="password" name="db_pass" id="db_pass"/>
 	</p>
 	<p>
+		<label for="db_encoding">
+			<TMPL_VAR ESCAPE=1 NAME="DB_SELECT_ENCODING">
+		</label>
+		<select name="db_encoding" id="db_encoding">
+		<TMPL_LOOP name="DB_ENCODINGS">
+		<option value="<TMPL_VAR NAME="ENCODING">"><TMPL_VAR NAME="ENCODING"></option>
+		</TMPL_LOOP>
+		</select>
+	</p>
+	<p>
 		<label for="description">
 			<TMPL_VAR ESCAPE=1 NAME="DESCRIPTION">:
 		</label>


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