[vhffs-dev] [501] Not Implemented.

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


Revision: 501
Author:   beuss
Date:     2007-03-03 09:52:14 +0000 (Sat, 03 Mar 2007)

Log Message:
-----------
Not Implemented. (see rfc2616 for an explanation, this commit is dedicated to crafty, sorry I missed #500).
Refactored Vhffs::Services::Postgres creation & fetching processes, added DB name check. Modified Mysql dbname pattern and fixed a bug causing reject of valid usernames (@_ is intepreted in scalar context if a prototyped function declares a $ argument).

Modified Paths:
--------------
    branches/vhffs_4.1/Makefile
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Pgsql.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Postgres.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mysql.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Postgres.pm
    branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql
    branches/vhffs_4.1/vhffs-panel/pgsql/delete.pl
    branches/vhffs_4.1/vhffs-panel/pgsql/pgsql_submit.pl
    branches/vhffs_4.1/vhffs-panel/pgsql/prefs_save.pl
    branches/vhffs_4.1/vhffs-robots/src/refused_postgres.pl
    branches/vhffs_4.1/vhffs-tests/src/Stats.pl

Added Paths:
-----------
    branches/vhffs_4.1/vhffs-tests/src/Services/Postgres.pl


Modified: branches/vhffs_4.1/Makefile
===================================================================
--- branches/vhffs_4.1/Makefile	2007-02-28 23:16:11 UTC (rev 500)
+++ branches/vhffs_4.1/Makefile	2007-03-03 09:52:14 UTC (rev 501)
@@ -307,6 +307,8 @@
 	@perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Services/Mail.pl");'
 test-mysql:
 	@perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Services/Mysql.pl");'
+test-pgsql:
+	@perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Services/Postgres.pl");'
 test-functions:
 	@perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Functions.pl");'
 

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Pgsql.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Pgsql.pm	2007-02-28 23:16:11 UTC (rev 500)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Pgsql.pm	2007-03-03 09:52:14 UTC (rev 501)
@@ -154,22 +154,15 @@
 
 sub create_pgsql
 {
-    my( $main , $dbname , $user , $group , $dbuser , $dbpass ) = @_;
+    my( $main , $dbname , $user , $group , $dbuser , $dbpass, $description ) = @_;
 
     return -1 if( ! defined $user );
-    return -2 if( $group->fetch < 0 );
+    return -2 if( ! defined $group );
     
-    my $pgsql = new Vhffs::Services::Postgres( $main , $dbname , $user , $group );
+    my $pgsql = Vhffs::Services::Postgres::create($main, $dbname, $dbuser, $dbpass, $description, $user, $group);
 
 	return undef if( ! defined $pgsql );
 	
-    $pgsql->set_user( $user );
-    $pgsql->set_group( $group );
-    return undef if ( $pgsql->set_dbusername( $dbuser ) < 0 );
-    return undef if ( $pgsql->set_dbpassword( $dbpass ) < 0 );
-    
-    return undef if( $pgsql->create < 0 );
-
     return undef if ( Vhffs::Acl::add_acl( $user , $pgsql , Vhffs::Constants::ACL_DELETE , $main ) < 0 );
     return undef if( Vhffs::Acl::add_acl( $group , $pgsql , Vhffs::Constants::ACL_VIEW , $main ) < 0 );
 

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Postgres.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Postgres.pm	2007-02-28 23:16:11 UTC (rev 500)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Postgres.pm	2007-03-03 09:52:14 UTC (rev 501)
@@ -45,7 +45,7 @@
 
 	my $db = pgsql_admin_db_connect( $main );
 
-	if( $pg->fetch > 0 )
+	if( defined $pg )
 	{
 		$db->do("ALTER USER " . $pg->get_dbusername ." WITH PASSWORD '".$pg->get_dbpassword."'");
 		$pg->set_status( Vhffs::Constants::ACTIVATED );
@@ -63,7 +63,7 @@
 
 	my $db = pgsql_admin_db_connect( $main );
 	
-	if( $pg->fetch > 0 )
+	if( defined $pg )
 	{
 		$db->do("CREATE DATABASE ".$pg->get_dbname );
 		$db->do("CREATE USER " . $pg->get_dbusername ." WITH PASSWORD '".$pg->get_dbpassword."'");
@@ -80,7 +80,7 @@
 
 	my $db = pgsql_admin_db_connect( $main );
 	
-	if( ( $pg->fetch > 0 ) && ( $pg->get_status == Vhffs::Constants::TO_DELETE )  )
+	if( ( defined $pg ) && ( $pg->get_status == Vhffs::Constants::TO_DELETE )  )
 	{
 		$pg->add_history("Ok, robots will erased all data");
 		$db->do("DROP DATABASE ".$pg->get_dbname );

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mysql.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mysql.pm	2007-02-28 23:16:11 UTC (rev 500)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mysql.pm	2007-03-03 09:52:14 UTC (rev 501)
@@ -75,11 +75,11 @@
 
 sub check_dbname($) {
     my $dbname = shift;
-    return ($dbname =~ /^(?:[a-z0-9][a-z0-9\_]+[a-z0-9]){2,31}$/ );
+    return ($dbname =~ /^[a-z0-9][a-z0-9\_]{1,30}[a-z0-9]$/ );
 }
 
 sub check_dbuser($) {
-    return check_dbname(@_);
+    return check_dbname($_[0]);
 }
 
 sub check_dbpass($) {
@@ -109,7 +109,7 @@
     }
     my ($main, $dbname, $dbuser, $dbpass, $description, $user, $group) = @_;
     return undef unless(defined($user) && defined($group));
-    return undef unless(check_dbname($dbname) && check_dbpass($dbpass) && check_dbname($dbuser));
+    return undef unless(check_dbname($dbname) && check_dbpass($dbpass) && check_dbuser($dbuser));
 
     my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_MYSQL);
 

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Postgres.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Postgres.pm	2007-02-28 23:16:11 UTC (rev 500)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Postgres.pm	2007-03-03 09:52:14 UTC (rev 501)
@@ -64,10 +64,8 @@
 
     $this = {};
 	
-#    return undef if( $dbname =~ /^[\w\d\_\-]+$/ );
+    return undef unless(check_dbname($dbname));
 
-	return undef if( length $dbname > 32 );
-
     $this = $class->SUPER::new( $main , 1 , '401' );
 
     $this->{'dbname'} = $dbname if ( defined $dbname );
@@ -80,6 +78,20 @@
 	return $this;
 }
 
+sub check_dbname($) {
+    my $dbname = shift;
+    return ( $dbname =~ /^[a-z0-9][a-z0-9\_]{1,30}[a-z0-9]$/ );
+}
+
+sub check_dbuser($) {
+    return check_dbname($_[0]);
+}
+
+sub check_dbpass($) {
+    my $dbpass = shift;
+    return ( $dbpass =~ /^[a-zA-Z0-9]+$/);
+}
+
 sub delete
 {
     my $self = shift;
@@ -92,8 +104,31 @@
     return 1;
 }
 
+sub create {
+    if($_[0]->isa('Vhffs::Services::Postgres')) {
+        my ($package, $file, $line) = caller();
+        warn "Using deprecated form of method Vhffs::Services::Postgres::create from $package ($file:$line)\n";
+        return old_create(@_);
+    }
 
-sub create
+    my ($main, $dbname, $dbuser, $dbpass, $description, $user, $group) = @_;
+    return undef unless(defined($user) && defined($group));
+    return undef unless(check_dbname($dbname) && check_dbpass($dbpass) && check_dbuser($dbuser));
+    my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_PGSQL);
+
+    return undef unless defined ($parent);
+
+    my $sql = 'INSERT INTO vhffs_pgsql(dbname, dbuser, dbpass, owner_uid, owner_gid, object_id) VALUES(?, ?, ?, ?, ?, ?)';
+    my $dbh = $main->get_db_object();
+    my $sth = $dbh->prepare($sql);
+    return undef unless($sth->execute($dbname, $dbuser, $dbpass, $user->get_uid, $group->get_gid, $parent->get_oid));
+
+    return get_by_dbname($main, $dbname);
+
+}
+
+
+sub old_create
 {
 	my $self = shift;
 
@@ -215,11 +250,8 @@
 
 	return 1 if( $value eq $self->{'dbuser'});
 
-	my $request = $self->{'db'}->prepare("SELECT * FROM vhffs_pgsql where dbuser='".$value."'") or return -1;
-    my $rows = $request->execute();
+    return -1 if(! check_dbuser($value));
 
-	return -1 if( $rows >= 1 );
-	
 	$self->{'dbuser'} = $value;
 	return 1;
 }
@@ -255,40 +287,62 @@
     return 1;
 }
 
+sub _new {
+    my ($class, $main, $pgsql_id, $owner_gid, $dbname, $dbuser, $dbpass, $oid, $owner_uid, $date_creation, $state, $description) = @_;
+    my $self = $class->SUPER::_new($main, $oid, $owner_uid, $date_creation, $description, $state);
+    return undef unless(defined $self);
+
+    $self->{pgsql_id} = $pgsql_id;
+    $self->{owner_gid} = $owner_gid;
+    $self->{dbname} = $dbname;
+    $self->{dbuser} = $dbuser;
+    $self->{dbpass} = $dbpass;
+    return $self;
+}
+
+sub get_by_dbname($$) {
+    my ($vhffs, $dbname) = @_;
+
+    my $sql = q{SELECT m.pgsql_id, m.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 $dbh = $vhffs->get_db_object();
+    my @params = $dbh->selectrow_array($sql, undef, $dbname);
+
+    return _new Vhffs::Services::Postgres($vhffs, @params);
+
+}
+
 sub getall
-{   
-    my $vhffs = shift;
-    my $state = shift;
-    my $name = shift;
-    my $group = shift;
+{
+    my ($vhffs, $state, $name, $group) = @_;
 
-    my $query;
-    my $request;
+    my $postgres;
+    my @params;
 
-    my @objs;
-    my $result;
-    my $tmp;
+    my $sql = 'SELECT p.pgsql_id, p.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';
 
-    $query = "SELECT dbname FROM vhffs_pgsql p, vhffs_object o WHERE o.object_id=p.object_id";
-	$query .= " AND o.state='".$state."'" if( defined $state );
-	$query .= " AND p.dbname LIKE '%".$name."%'" if( defined $name );
-	$query .= " AND p.owner_gid='".$group->get_gid."'" if( defined $group );
+    if(defined $state) {
+        $sql .= ' AND o.state = ?';
+        push(@params, $state);
+    }
+    if(defined $name) {
+        $sql .= ' AND p.dbname LIKE ?';
+        push(@params, '%'.$name.'%');
+    }
+    if(defined $group) {
+        $sql .= ' AND p.owner_gid = ?';
+        push(@params, $group->get_gid);
+    }
 
-    $request = $vhffs->{'db'}->prepare( $query );
-    my $rows = $request->execute;
+    my $dbh = $vhffs->get_db_object();
+    my $sth = $dbh->prepare($sql);
 
-    return undef if( $rows <= 0);
-    $result = $request->fetchall_hashref('dbname');
-    foreach( keys %{$result} )
-    {
-            $tmp = new Vhffs::Services::Postgres( $vhffs , $_ );
-            if( ( defined ( $tmp ) ) && ( $tmp->fetch > 0 ) )
-            {
-                    push @objs , $tmp;
-            }
+    return undef unless($sth->execute(@params));
+
+    while(my $row = $sth->fetchrow_arrayref()) {
+        push(@$postgres, _new Vhffs::Services::Postgres($vhffs, @$row));
     }
-    return \@objs;
+
+    return $postgres;
 }
 
-
 1;

Modified: branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql
===================================================================
--- branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql	2007-02-28 23:16:11 UTC (rev 500)
+++ branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql	2007-03-03 09:52:14 UTC (rev 501)
@@ -296,6 +296,8 @@
 ALTER TABLE vhffs_mxdomain ADD CONSTRAINT vhffs_mxdomain_unique_domainname UNIQUE (domain);
 ALTER TABLE vhffs_mysql ADD CONSTRAINT vhffs_mysql_unique_dbname UNIQUE (dbname);
 ALTER TABLE vhffs_mysql ADD CONSTRAINT vhffs_mysql_unique_dbuser UNIQUE (dbuser);
+ALTER TABLE vhffs_pgsql ADD CONSTRAINT vhffs_pgsql_unique_dbname UNIQUE (dbname);
+ALTER TABLE vhffs_pgsql ADD CONSTRAINT vhffs_pgsql_unique_dbuser UNIQUE (dbuser);
 
 -- This index drastically improves performances on get_used_letters
 CREATE INDEX idx_vhffs_httpd_servername_firstletter ON vhffs_httpd(substr(servername, 1, 1));

Modified: branches/vhffs_4.1/vhffs-panel/pgsql/delete.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/pgsql/delete.pl	2007-02-28 23:16:11 UTC (rev 500)
+++ branches/vhffs_4.1/vhffs-panel/pgsql/delete.pl	2007-03-03 09:52:14 UTC (rev 501)
@@ -64,13 +64,13 @@
 
 my $dbname = $cgi->param("DBNAME");
 
-my $pgsql = new Vhffs::Services::Postgres( $vhffs , $dbname , $user , $group );
+my $pgsql = Vhffs::Services::Postgres::get_by_dbname( $vhffs , $dbname );
 
 my $templatedir = $vhffs->get_config->get_templatedir;
 
-if ( ! defined( $pgsql ) || ( $pgsql->fetch < 0 ) )
+if ( ! defined( $pgsql ) )
 {
-    $message = gettext("This user doesn't exist in VHFFS database");
+    $message = gettext("This DB doesn't exist in VHFFS database");
 }
 elsif( Vhffs::Acl::what_perm_for_user( $user , $pgsql , $vhffs ) < Vhffs::Constants::ACL_DELETE )
 {

Modified: branches/vhffs_4.1/vhffs-panel/pgsql/pgsql_submit.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/pgsql/pgsql_submit.pl	2007-02-28 23:16:11 UTC (rev 500)
+++ branches/vhffs_4.1/vhffs-panel/pgsql/pgsql_submit.pl	2007-03-03 09:52:14 UTC (rev 501)
@@ -80,20 +80,18 @@
 {
 	$message = gettext("Password must contains only alphanum caracters");
 }
-elsif( ( length( $dbname ) < 3 ) || ( length( $dbname ) >= 16 ) )
+elsif( ! Vhffs::Services::Postgres::check_dbname($dbname) )
 {
 	$message = gettext( "Database name must contain between 3 and 16 characters" );
 }
 else
 {
 
-	my $postgres = Vhffs::Panel::Pgsql::create_pgsql( $vhffs , $dbname , $user , $group , $dbuser , $dbpass );
+	my $postgres = Vhffs::Panel::Pgsql::create_pgsql( $vhffs , $dbname , $user , $group , $dbuser , $dbpass, $description );
 
 
 	if( defined $postgres )
 	{
-		$postgres->set_description( $description );
-		$postgres->commit;
 		$message = gettext("The PostgreSQL object was successfully created !");
 	}
 	else

Modified: branches/vhffs_4.1/vhffs-panel/pgsql/prefs_save.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/pgsql/prefs_save.pl	2007-02-28 23:16:11 UTC (rev 500)
+++ branches/vhffs_4.1/vhffs-panel/pgsql/prefs_save.pl	2007-03-03 09:52:14 UTC (rev 501)
@@ -68,13 +68,13 @@
 
 my $dbname = $cgi->param("name");
 
-my $pgsql = new Vhffs::Services::Postgres( $vhffs , $dbname , $user , $group );
+my $pgsql = Vhffs::Services::Postgres::get_by_dbname( $vhffs , $dbname );
 
 
 
-if ( ! defined( $pgsql ) || ( $pgsql->fetch < 0 ) )
+if ( ! defined( $pgsql ) )
 {
-    $message = gettext("This user doesn't exist in VHFFS database");
+    $message = gettext("This DB doesn't exist in VHFFS database");
 }
 elsif( $pgsql->get_status != Vhffs::Constants::ACTIVATED )
 {

Modified: branches/vhffs_4.1/vhffs-robots/src/refused_postgres.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/refused_postgres.pl	2007-02-28 23:16:11 UTC (rev 500)
+++ branches/vhffs_4.1/vhffs-robots/src/refused_postgres.pl	2007-03-03 09:52:14 UTC (rev 501)
@@ -60,7 +60,8 @@
 
 foreach $object ( @{$objects} )
 {
-	if( ( defined $object ) && ( $object->fetch > 0 ) )
+    # useless !!! (?)
+	if( defined $object )
 	{
 		$user = $object->get_user;
 		$lang = Vhffs::Panel::User::get_lang( $user );

Added: branches/vhffs_4.1/vhffs-tests/src/Services/Postgres.pl
===================================================================
--- branches/vhffs_4.1/vhffs-tests/src/Services/Postgres.pl	2007-02-28 23:16:11 UTC (rev 500)
+++ branches/vhffs_4.1/vhffs-tests/src/Services/Postgres.pl	2007-03-03 09:52:14 UTC (rev 501)
@@ -0,0 +1,34 @@
+use strict;
+use Vhffs::Tests::Main;
+use Vhffs::Tests::Utils;
+use Vhffs::Constants;
+use Vhffs::User;
+use Vhffs::Services::Postgres;
+use Test::More 'no_plan';
+
+my $main = init Vhffs::Tests::Main;
+isa_ok($main, 'Vhffs::Tests::Main', '$main');
+
+Vhffs::Tests::Utils::init_db($main->get_db_object);
+
+my $user1 = Vhffs::User::create($main, 'test1', 'abcdef', 0, 'test1@xxxxxxxx');
+isa_ok($user1, 'Vhffs::User', '$user1');
+
+my $group1 = Vhffs::Group::create($main, 'pggroup1', $user1->get_uid, undef, 'Test group for postgres');
+isa_ok($group1, 'Vhffs::Group', '$group1');
+my $group2 = Vhffs::Group::create($main, 'pggroup2', $user1->get_uid, undef, 'Test group for postgres');
+isa_ok($group2, 'Vhffs::Group', '$group1');
+
+my $postgres1 = Vhffs::Services::Postgres::create($main, 'postgres1', 'pgu1', 'plop', 'Test postgres DB 1', $user1, $group1);
+isa_ok($postgres1, 'Vhffs::Services::Postgres', '$postgres1');
+cmp_ok($postgres1->get_dbname, 'eq', 'postgres1', 'dbname is the one defined while creating object');
+cmp_ok($postgres1->get_dbusername, 'eq', 'pgu1', 'dbuser is the one defined while creating object');
+cmp_ok($postgres1->get_owneruid, '==', $user1->get_uid, 'uid matches');
+cmp_ok($postgres1->get_ownergid, '==', $group1->get_gid, 'gid matches');
+
+my @postgreses = @{Vhffs::Services::Postgres::getall($main)};
+cmp_ok(scalar(@postgreses), '==', 1, 'Total : 1 Postgres Service');
+is_deeply($postgreses[0], $postgres1, 'getall return correct Postgres objects');
+
+ok(!defined(Vhffs::Services::Postgres::getall($main, Vhffs::Constants::ACTIVATED)), 'No ACTIVATED Postgres DB');
+

Modified: branches/vhffs_4.1/vhffs-tests/src/Stats.pl
===================================================================
--- branches/vhffs_4.1/vhffs-tests/src/Stats.pl	2007-02-28 23:16:11 UTC (rev 500)
+++ branches/vhffs_4.1/vhffs-tests/src/Stats.pl	2007-03-03 09:52:14 UTC (rev 501)
@@ -60,8 +60,7 @@
 
 # Groups' stats
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $group = new Vhffs::Group($main, "testgroup0$i", 401);
-    $group->fetch;
+    $group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
     $group->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
     $group->commit;
     $stats = new Vhffs::Stats($main);
@@ -70,8 +69,7 @@
 }
 
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $group = new Vhffs::Group($main, "testgroup0$i", 401);
-    $group->fetch;
+    $group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
     $group->set_status(Vhffs::Constants::ACTIVATED);
     $group->commit;
     $stats = new Vhffs::Stats($main);
@@ -80,10 +78,8 @@
 
 # Web stats
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $group = new Vhffs::Group($main, "testgroup0$i", 401);
-    $user = new Vhffs::User($main, "testuser0$i", 401);
-    $group->fetch;
-    $user->fetch;
+    $group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
+    $user = Vhffs::User::get_by_username($main, "testuser0$i");
     # Httpd servername must end with a 2-4 letters suffix
     $svc = Vhffs::Services::Httpd::create($main, "httpd0$i.test.com", '', $user, $group);
 }
@@ -110,10 +106,8 @@
 # CVS stats
 
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $group = new Vhffs::Group($main, "testgroup0$i", 401);
-    $user = new Vhffs::User($main, "testuser0$i", 401);
-    $group->fetch;
-    $user->fetch;
+    $group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
+    $user = Vhffs::User::get_by_username($main, "testuser0$i");
     Vhffs::Services::Cvs::create($main, "testcvs0$i", '', $user, $group);
 }
 
@@ -140,10 +134,8 @@
 # DNS stats
 
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $group = new Vhffs::Group($main, "testgroup0$i", 401);
-    $user = new Vhffs::User($main, "testuser0$i", 401);
-    $group->fetch;
-    $user->fetch;
+    $group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
+    $user = Vhffs::User::get_by_username($main, "testuser0$i");
     $svc = new Vhffs::Services::DNS($main, "dns0$i.test.com", $user, $group);
     $svc->create;
 }
@@ -172,10 +164,8 @@
 # MySQL stats
 
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $group = new Vhffs::Group($main, "testgroup0$i", 401);
-    $user = new Vhffs::User($main, "testuser0$i", 401);
-    $group->fetch;
-    $user->fetch;
+    $group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
+    $user = Vhffs::User::get_by_username($main, "testuser0$i");
     $svc = Vhffs::Services::Mysql::create($main, "mysqltest0$i", "mysqltest0$i", 'abcdef', "Mysql test DB #0$i", $user, $group);
 }
 
@@ -201,21 +191,15 @@
 # Postgres Stats
 
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $group = new Vhffs::Group($main, "testgroup0$i", 401);
-    $user = new Vhffs::User($main, "testuser0$i", 401);
-    $group->fetch;
-    $user->fetch;
-    $svc = new Vhffs::Services::Postgres($main, "pgsqltest0$i", $user, $group);
-    $svc->set_dbusername( $user->get_username );
-    $svc->set_dbpassword('abcdef');
-    $svc->create;
+    $group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
+    $user = Vhffs::User::get_by_username($main, "testuser0$i");
+    $svc = Vhffs::Services::Postgres::create($main, "pgsqltest0$i", "pgsqlu0$i", 'abcdef', "MySQL test DB #0$i", $user, $group);
 }
 
 $stats = new Vhffs::Stats($main);
 is($stats->get_pgsql_in_moderation, 9, 'All PostgreSQL services waiting for moderation');
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $svc = new Vhffs::Services::Postgres($main, "pgsqltest0$i");
-    $svc->fetch;
+    $svc = Vhffs::Services::Postgres::get_by_dbname($main, "pgsqltest0$i");
     $svc->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
     $svc->commit;
     $stats = new Vhffs::Stats($main);
@@ -224,8 +208,7 @@
 }
 
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $svc = new Vhffs::Services::Postgres($main, "pgsqltest0$i");
-    $svc->fetch;
+    $svc = Vhffs::Services::Postgres::get_by_dbname($main, "pgsqltest0$i");
     $svc->set_status(Vhffs::Constants::ACTIVATED);
     $svc->commit;
     $stats = new Vhffs::Stats($main);
@@ -235,10 +218,8 @@
 # SVN Stats
 
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $group = new Vhffs::Group($main, "testgroup0$i", 401);
-    $user = new Vhffs::User($main, "testuser0$i", 401);
-    $group->fetch;
-    $user->fetch;
+    $group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
+    $user = Vhffs::User::get_by_username($main, "testuser0$i");
     $svc = new Vhffs::Services::Svn($main, "svntest0$i", $user, $group);
     $svc->create;
 }
@@ -246,8 +227,7 @@
 $stats = new Vhffs::Stats($main);
 is($stats->get_svn_in_moderation, 9, 'All SVN services waiting for moderation');
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $group = new Vhffs::Group($main, "testgroup0$i", 401);
-    $group->fetch;
+    $group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
     $svc = new Vhffs::Services::Svn($main, "svntest0$i", undef, $group);
     $svc->fetch;
     $svc->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
@@ -258,8 +238,7 @@
 }
 
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $group = new Vhffs::Group($main, "testgroup0$i", 401);
-    $group->fetch;
+    $group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
     $svc = new Vhffs::Services::Svn($main, "svntest0$i", undef, $group);
     $svc->fetch;
     $svc->set_status(Vhffs::Constants::ACTIVATED);
@@ -271,10 +250,8 @@
 # Mail tests
 
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $group = new Vhffs::Group($main, "testgroup0$i", 401);
-    $user = new Vhffs::User($main, "testuser0$i", 401);
-    $group->fetch;
-    $user->fetch;
+    $group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
+    $user = Vhffs::User::get_by_username($main, "testuser0$i");
     $svc = new Vhffs::Services::Mail($main, "mail0$i.test.com", $user, $group);
     $svc->create;
 }
@@ -333,10 +310,8 @@
 # Mailing lists tests
 
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $group = new Vhffs::Group($main, "testgroup0$i", 401);
-    $user = new Vhffs::User($main, "testuser0$i", 401);
-    $group->fetch;
-    $user->fetch;
+    $group = Vhffs::Group::get_by_groupname($main, "testgroup0$i");
+    $user = Vhffs::User::get_by_username($main, "testuser0$i");
     $svc = new Vhffs::Services::Mailing($main, "ml", "mail0$i.test.com", $user, $group);
     $svc->create;
 }


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