[vhffs-dev] [svn] commit: r294 - /branches/vhffs_4.1/vhffs-api/src/Vhffs/Group.pm

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


Author: beuss
Date: Fri Nov 10 08:36:54 2006
New Revision: 294

Log:
groupname uniqueness is now handled by a constraint
initial quota used is 0
INSERT use sequences


Modified:
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Group.pm

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Group.pm
==============================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Group.pm (original)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Group.pm Fri Nov 10 08:36:54 2006
@@ -181,8 +181,6 @@
     return $result;    
 }
 
-
-
 #create a new group with the name given in parameter
 sub create
 {
@@ -221,20 +219,10 @@
 
 
 
-    #default init
-    $self->{'gid'} = $conf->{'mingid'};
-    
-    #first, we check if the group doesn't exists
-	$query ="SELECT * FROM vhffs_groups WHERE groupname= '" .$self->{'groupname'}."'";
-    $request = $self->{'db'}->{'DB_READ'}->prepare( $query );
-    $rows = $request->execute;
-
-	return -1 if ( $rows > 0 );
-
     #Create the related object
     $oid = $self->SUPER::create;
     
-    return -1 if ( $oid lt 0 );
+    return -1 if ( $oid < 0 );
 
 
 
@@ -244,26 +232,20 @@
 	$quota = 10;
 	$quota = $conf->{'default_quota'} if( ( defined $conf ) && ( defined $conf->{'default_quota'} ) );
 	$self->{'quota'} 		= $quota;
-	$self->{'quota_used'} 	= $quota;
-
-
-	
-    # compute the gid
-    $self->{'gid'} = $conf->{'mingid'};
-    $result = $self->{'db'}->{'DB_READ'}->selectall_arrayref("SELECT MAX(gid) FROM vhffs_groups");
-    $gid = $result->[0][0] + 1 if( $result->[0][0] );
-    $self->{'gid'} =  $gid if ( ( $gid ) && ( $gid > $conf->{'mingid'}) );
-
-
+	$self->{'quota_used'} 	= 0;
+
+
+	
     #finally, create the group
-	$query = "INSERT INTO vhffs_groups VALUES('" . $self->{'gid'} . "' , '" . $self->{'groupname'} . "' , NULL , '".$quota."' , '".$quota."' , '$oid')";
+	$query = 'INSERT INTO vhffs_groups(groupname, passwd, quota, quota_used, object_id) VALUES(?, NULL, ?, ?, ?)';
     $request = $self->{'db'}->{'DB_WRITE'}->prepare( $query ) or return -2;
-    $request->execute() or return -3;
-
-
-	$query = "INSERT INTO vhffs_groups_info VALUES( '" . $self->{'gid'} ."' , '".$self->{'owner_uid'}."' , '".$self->{'owner_uid'}."')";
+    $request->execute($self->{'groupname'}, $self->{'quota'}, $self->{'quota_used'}, $oid) or return -3;
+    $self->{'gid'} = $self->{'db'}->{'DB_WRITE'}->last_insert_id(undef, undef, 'vhffs_groups', undef);
+
+
+	$query = 'INSERT INTO vhffs_groups_info(gid, owner_uid, uid_mod) VALUES( ?, ?, ?)';
     $request = $self->{'db'}->{'DB_WRITE'}->prepare($query) or return -2;
-    $request->execute() or return -3;
+    $request->execute($self->{'gid'}, $self->{'owner_uid'}, $self->{'owner_uid'}) or return -3;
 
     $self->commit;
 




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