[vhffs-dev] [468] Removed all references to vhffs_panel_user_prefs.

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


Revision: 468
Author:   beuss
Date:     2007-02-17 10:39:40 +0000 (Sat, 17 Feb 2007)

Log Message:
-----------
Removed all references to vhffs_panel_user_prefs.
Migration script set all language and theme to a default value if
the user hasn't defined a default language.

Modified Paths:
--------------
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/User.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/User.pm
    branches/vhffs_4.1/vhffs-compat/4.0.sql


Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/User.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/User.pm	2007-02-17 10:21:01 UTC (rev 467)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/User.pm	2007-02-17 10:39:40 UTC (rev 468)
@@ -94,22 +94,9 @@
 	
 	return -1 if ( ( ! defined $user ) || ( ! defined $lang ) );
 
-	my $uid = $user->get_uid;
-
-	my $query = "SELECT * FROM vhffs_panel_user_prefs WHERE uid='".$uid."'";
-	my $request = $user->{'db'}->prepare( $query );
-	my $rows = $request->execute;
-
-	if( $rows != 0 )
-	{
-		$query = "UPDATE vhffs_panel_user_prefs SET language='".$lang."' WHERE uid='".$uid."'";
-	}
-	else
-	{
-		$query = "INSERT INTO vhffs_panel_user_prefs VALUES( '".$uid."' , '".$lang."' , '' )";
-	}
-	$request = $user->{'db'}->prepare( $query );
-	$request->execute or return -4;
+    my $sql = 'UPDATE vhffs_users SET language = ? WHERE uid = ?';
+    my $sth = $user->get_db_object()->prepare($sql);
+    $sth->execute($lang, $user->get_uid) or return -1;
 }
 
 
@@ -120,45 +107,17 @@
 	
 	return -1 if ( ( ! defined $user ) || ( ! defined $theme ) );
 
-	my $uid = $user->get_uid;
-
-	my $query = "SELECT * FROM vhffs_panel_user_prefs WHERE uid='".$uid."'";
-	my $request = $user->{'db'}->prepare( $query );
-	my $rows = $request->execute;
-
-	if( $rows != 0 )
-	{
-		$query = "UPDATE vhffs_panel_user_prefs SET theme='".$theme."' WHERE uid='".$uid."'";
-	}
-	else
-	{
-		$query = "INSERT INTO vhffs_panel_user_prefs VALUES( '".$uid."' , '', '".$theme."' )";
-	}
-	$request = $user->{'db'}->prepare( $query );
-	$request->execute or return -4;
+    my $sql = 'UPDATE vhffs_users SET theme = ? WHERE uid = ?';
+    my $dbh = $user->get_db_object();
+    my $sth = $dbh->prepare($sql);
+    $sth->execute($theme, $user->get_uid) or return -1;
 }
 
 sub get_lang
 {
 	my $user = shift;
 	return -1 if( ! defined $user );
-
-	my $uid = $user->get_uid;
-
-	my $query = "SELECT language FROM vhffs_panel_user_prefs WHERE uid='".$uid."'";
-	my $request = $user->{'db'}->prepare( $query );
-	my $rows = $request->execute;
-
-	if( $rows == 0 )
-	{
-		return Vhffs::Constants::DEFAULT_LANG;
-	}
-	else
-	{
-		my $value = $request->fetchrow_arrayref;
-		return $value->[0];
-	}
-	
+    return $user->get_lang;
 }
 
 
@@ -166,23 +125,7 @@
 {
 	my $user = shift;
 	return -1 if( ! defined $user );
-
-	my $uid = $user->get_uid;
-
-	my $query = "SELECT theme FROM vhffs_panel_user_prefs WHERE uid='".$uid."'";
-	my $request = $user->{'db'}->prepare( $query );
-	my $rows = $request->execute;
-
-	if( $rows == 0 )
-	{
-		return Vhffs::Constants::DEFAULT_THEME;
-	}
-	else
-	{
-		my $value = $request->fetchrow_arrayref;
-		return $value->[0];
-	}
-	
+    return $user->get_theme;
 }
 
 1;

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/User.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/User.pm	2007-02-17 10:21:01 UTC (rev 467)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/User.pm	2007-02-17 10:39:40 UTC (rev 468)
@@ -34,7 +34,6 @@
 package Vhffs::User;
 
 #Vhffs::User written by sod` <dieu AT gunnm DOT org>
-
 #Vhffs::User implements Unix authentification as an module of Vhffs.
 #You can manage user with Unix.
 #libnss-postgresql must be used with it to have an account on a machine with the database
@@ -80,7 +79,7 @@
 }
 
 sub _new {
-    my ($class, $main, $uid, $gid, $oid, $username, $passwd, $homedir, $shell, $admin, $firstname, $lastname, $address, $zipcode, $city, $country, $mail, $gpg_key, $date_creation, $description, $state) = @_;
+    my ($class, $main, $uid, $gid, $oid, $username, $passwd, $homedir, $shell, $admin, $firstname, $lastname, $address, $zipcode, $city, $country, $mail, $gpg_key, $note, $language, $theme, $date_creation, $description, $state) = @_;
     my $self = $class->SUPER::_new($main, $oid, $uid, $date_creation, $description, $state);
     return undef unless(defined $self);
     $self->{uid} = $uid;
@@ -98,6 +97,9 @@
     $self->{country} = $country;
     $self->{mail} = $mail;
     $self->{gpg_key} = $gpg_key;
+    $self->{note} = $note;
+    $self->{language} = $language;
+    $self->{theme} = $theme;
     return $self;
 }
 
@@ -643,18 +645,7 @@
 {
     my $self = shift;
     my $request;
-    $request = $self->{'db'}->prepare("SELECT language FROM vhffs_panel_user_prefs WHERE uid='".$self->get_uid."'");
-    my $rows = $request->execute();
- 
-   if( $rows == 0 )
-   {
-     return Vhffs::Constants::DEFAULT_LANG;
-   }
-   else
-   {
-     my $value = $request->fetchrow_arrayref;
-     return $value->[0];
-   }
+    return $self->{language};
 }
 
 
@@ -664,6 +655,12 @@
 	return $self->{'mail'};
 }
 
+sub get_theme
+{
+    my $self = shift;
+    return $self->{theme};
+}
+
 sub get_address
 {
 	my $self = shift;
@@ -925,7 +922,7 @@
 
 sub get_by_uid {
     my ($main, $uid) = @_;
-    my $query = 'SELECT u.uid, u.gid, u.object_id, u.username, u.passwd, u.homedir, u.shell, u.admin, u.firstname, u.lastname, u.address, u.zipcode, u.city, u.country, u.mail, u.gpg_key, o.date_creation, o.description, o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.uid = ?';
+    my $query = 'SELECT u.uid, u.gid, u.object_id, u.username, u.passwd, u.homedir, u.shell, u.admin, u.firstname, u.lastname, u.address, u.zipcode, u.city, u.country, u.mail, u.gpg_key, u.note, u.language, u.theme, o.date_creation, o.description, o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.uid = ?';
     my $dbh = $main->get_db_object;
     my @params = $dbh->selectrow_array($query, undef, $uid);
     return undef unless(@params);
@@ -936,7 +933,7 @@
 
 sub get_by_username {
     my ($main, $username) = @_;
-    my $query = 'SELECT u.uid, u.gid, u.object_id, u.username, u.passwd, u.homedir, u.shell, u.admin, u.firstname, u.lastname, u.address, u.zipcode, u.city, u.country, u.mail, u.gpg_key, o.date_creation, o.description, o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.username = ?';
+    my $query = 'SELECT u.uid, u.gid, u.object_id, u.username, u.passwd, u.homedir, u.shell, u.admin, u.firstname, u.lastname, u.address, u.zipcode, u.city, u.country, u.mail, u.gpg_key, u.note, u.language, u.theme, o.date_creation, o.description, o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.username = ?';
     my $dbh = $main->get_db_object;
     my @params = $dbh->selectrow_array($query, undef, $username);
     return undef unless(@params);

Modified: branches/vhffs_4.1/vhffs-compat/4.0.sql
===================================================================
--- branches/vhffs_4.1/vhffs-compat/4.0.sql	2007-02-17 10:21:01 UTC (rev 467)
+++ branches/vhffs_4.1/vhffs-compat/4.0.sql	2007-02-17 10:39:40 UTC (rev 468)
@@ -80,6 +80,8 @@
 -- merge vhffs_panel_user_prefs to vhffs_users
 ALTER TABLE vhffs_users ADD COLUMN language varchar(16);
 ALTER TABLE vhffs_users ADD COLUMN theme varchar(250);
+-- Not all users have a language and a theme set in vhffs_panel_user_prefs
+UPDATE vhffs_users SET language = 'en_US', theme = 'default';
 UPDATE vhffs_users SET language = up.language, theme = up.theme
     FROM vhffs_panel_user_prefs up
     WHERE up.uid = vhffs_users.uid;


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