[vhffs-dev] [495] Vhffs::Services::Mysql now use new creation/fetching scheme.

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


Revision: 495
Author:   beuss
Date:     2007-02-24 14:07:51 +0000 (Sat, 24 Feb 2007)

Log Message:
-----------
Vhffs::Services::Mysql now use new creation/fetching scheme.
Corrected a couple of SQL errors

Modified Paths:
--------------
    branches/vhffs_4.1/Makefile
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Acl.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Mysql.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Mysql.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mail.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mysql.pm
    branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql
    branches/vhffs_4.1/vhffs-panel/acl/view.pl
    branches/vhffs_4.1/vhffs-panel/admin/mysql/edit.pl
    branches/vhffs_4.1/vhffs-panel/admin/mysql/edit_submit.pl
    branches/vhffs_4.1/vhffs-panel/admin/mysql/show.pl
    branches/vhffs_4.1/vhffs-panel/mysql/delete.pl
    branches/vhffs_4.1/vhffs-panel/mysql/prefs.pl
    branches/vhffs_4.1/vhffs-panel/mysql/prefs_save.pl
    branches/vhffs_4.1/vhffs-panel/mysql/submit.pl
    branches/vhffs_4.1/vhffs-robots/src/dump_mysql.pl
    branches/vhffs_4.1/vhffs-robots/src/refused_mysql.pl
    branches/vhffs_4.1/vhffs-tests/src/Services/Mail.pl
    branches/vhffs_4.1/vhffs-tests/src/Stats.pl

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


Modified: branches/vhffs_4.1/Makefile
===================================================================
--- branches/vhffs_4.1/Makefile	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/Makefile	2007-02-24 14:07:51 UTC (rev 495)
@@ -290,7 +290,7 @@
 	install -m 644 vhffs-panel/themes/vhffs-ng/js/*.js		$(PANELDIR)/themes/vhffs-ng/js/
 
 
-test: test-object test-group test-user test-stats
+test: test-object test-group test-user test-stats test-cvs test-web test-mail test-mysql test-functions
 test-object:
 	@perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Object.pl");'
 test-group:
@@ -304,7 +304,9 @@
 test-web:
 	@perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Services/Httpd.pl");'
 test-mail:
-	@perl -I vhffs-tests/src/ -I vhffs-api/src/ vhffs-tests/src/Services/Mail.pl
+	@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-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/Acl.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Acl.pm	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Acl.pm	2007-02-24 14:07:51 UTC (rev 495)
@@ -176,7 +176,7 @@
 	my ( $obj , $main ) = @_;
 	return -1 if( $obj->fetch < 0 );
 
-    my $query = 'SELECT u.username, perm FROM vhffs_acl acl INNER JOIN vhffs_users ON u.object_id = acl.oid_src WHERE oid_dst=?';
+    my $query = 'SELECT u.username, acl.perm FROM vhffs_acl acl INNER JOIN vhffs_users u ON u.object_id = acl.oid_src WHERE oid_dst=?';
 	my $request = $main->{'db'}->prepare( $query );
 	return undef if( !$request->execute( $obj->{'object_id'} ) );
 	return ( $request->fetchall_hashref('username') );

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Mysql.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Mysql.pm	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Mysql.pm	2007-02-24 14:07:51 UTC (rev 495)
@@ -89,25 +89,18 @@
 
 
 
-sub create_mysql
+sub create_mysql($$$$$$$)
 {
-    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 $mysql = new Vhffs::Services::Mysql( $main , $dbname , $user , $group );
+    
+    my $mysql = Vhffs::Services::Mysql::create($main, $dbname, $dbuser, $dbpass, $description, $user, $group);
 
-    return undef if( ! defined $mysql );
+    return undef unless( defined $mysql );
 
-    $mysql->set_user( $user );
-    $mysql->set_group( $group );
-
-    return undef if ( $mysql->set_dbusername( $dbuser ) < 0 );
-    return undef if ( $mysql->set_dbpassword( $dbpass ) < 0 );
-
-    return undef if( $mysql->create < 0 );
-
     return undef if ( Vhffs::Acl::add_acl( $user , $mysql , Vhffs::Constants::ACL_DELETE , $main ) < 0 );
     return undef if ( Vhffs::Acl::add_acl( $group , $mysql , Vhffs::Constants::ACL_VIEW , $main ) < 0 );
 

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Mysql.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Mysql.pm	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Mysql.pm	2007-02-24 14:07:51 UTC (rev 495)
@@ -52,7 +52,7 @@
 
 	my $query;
 		
-	if( $db->fetch > 0 )
+	if( $defined $db )
 	{
 		$db->add_history( "Ok, robots takes the destruction of this database" );
 		my $dbi = mysql_admin_db_connect( $main );
@@ -92,7 +92,7 @@
 
         my $query;
                 
-        if( ( defined $db ) && ( $db->fetch > 0 ) )
+        if( defined $db )
         {
                 $db->add_history( "Ok, robots takes the creation of this database" );
                 my $dbi = mysql_admin_db_connect( $main );
@@ -139,7 +139,7 @@
 
         my $query;
 
-        if( $db->fetch > 0 )
+        if( defined $db )
         {
                 $db->add_history( "Ok, will change password for this database" );
                 my $dbi = mysql_admin_db_connect( $main );

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mail.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mail.pm	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mail.pm	2007-02-24 14:07:51 UTC (rev 495)
@@ -113,12 +113,11 @@
         return old_create(@_);
     }
 
-    return old_create(@_) if($_[0]->isa('Vhffs::Services::Mail'));
     my ($main, $domain, $description, $user, $group) = @_;
     return undef unless(defined($user) && defined($group));
     return undef unless(Vhffs::Functions::check_domain_name($domain));
 
-    my $parent = Vhffs::Object::create($main, $user->get_uid, $description);
+    my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_MAIL);
 
     return undef unless(defined $parent);
 

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-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mysql.pm	2007-02-24 14:07:51 UTC (rev 495)
@@ -60,8 +60,7 @@
 
     $this = $class->SUPER::new( $main , 1 , '401' );
 
-	return undef if( ! ( $dbname =~ /^[a-z0-9][a-z0-9\_]+[a-z0-9]$/ ) );
-	return undef if( length( $dbname ) > 32 );
+    return undef unless(check_dbname($dbname));
 
     $this->{'dbname'} = $dbname if ( defined $dbname );
     $this->{'dbuser'} = $dbname if ( defined $dbname );
@@ -74,6 +73,20 @@
 	return $this;
 }
 
+sub check_dbname($) {
+    my $dbname = shift;
+    return ($dbname =~ /^(?:[a-z0-9][a-z0-9\_]+[a-z0-9]){2,31}$/ );
+}
+
+sub check_dbuser($) {
+    return check_dbname(@_);
+}
+
+sub check_dbpass($) {
+    my $dbpass = shift;
+    return ($dbpass =~ /^[a-zA-Z0-9]{3,}$/ );
+}
+
 sub delete
 {
 	my $self = shift;
@@ -88,8 +101,28 @@
 
 }
 
+sub create {
+    if($_[0]->isa('Vhffs::Services::Mysql')) {
+        my ($package, $file, $line) = caller();
+        warn "Using deprecated form of Vhffs::Services::Mysql::create from $package ($file:$line).\n";
+        return old_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_dbname($dbuser));
 
-sub create
+    my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_MYSQL);
+
+    return undef unless defined ($parent);
+
+    my $sql = 'INSERT INTO vhffs_mysql(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;
 
@@ -242,39 +275,61 @@
 	$self->{'user'} = $user;
 }
 
+sub _new {
+    my ($class, $main, $mysql_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->{mysql_id} = $mysql_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.mysql_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_mysql 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::Mysql($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 $mysql;
+    my @params;
+   
+    my $sql = 'SELECT m.mysql_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_mysql m, vhffs_object o WHERE m.object_id = o.object_id';
 
-    my @objs;
-    my $result;
-    my $tmp;
+    if(defined $state) {
+        $sql .= ' AND o.state = ?';
+        push(@params, $state);
+    }
+    if(defined $name) {
+        $sql .= ' AND m.dbname LIKE ?';
+        push(@params, '%'.$name.'%');
+    }
+    if(defined $group) {
+        $sql .= ' AND m.owner_gid = ?';
+        push(@params, $group->get_gid);
+    }
 
-	$query = "SELECT dbname, dbuser FROM vhffs_mysql m, vhffs_object o WHERE o.object_id=m.object_id";
-    $query.= " AND o.state='".$state."'" if( defined $state );
-    $query.= " AND m.dbname LIKE '%".$name."%'" if( defined $name );
-    $query.= " AND m.owner_gid='".$group->get_gid."'" if( defined $group );
-	$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::Mysql( $vhffs , $_ );
-            if( ( defined ( $tmp ) ) && ( $tmp->fetch > 0 ) )
-            {
-                    push @objs , $tmp;
-            }
+    return undef unless($sth->execute(@params));
+
+    while(my $row = $sth->fetchrow_arrayref()) {
+        push(@$mysql, _new Vhffs::Services::Mysql($vhffs, @$row));
     }
-    return \@objs;   
 
+    return $mysql;
 }
 
 

Modified: branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql
===================================================================
--- branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql	2007-02-24 14:07:51 UTC (rev 495)
@@ -294,6 +294,8 @@
 ALTER TABLE vhffs_cvs ADD CONSTRAINT vhffs_cvs_unique_cvsroot UNIQUE (cvsroot);
 ALTER TABLE vhffs_httpd ADD CONSTRAINT vhffs_httpd_unique_servername UNIQUE (servername);
 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);
 
 -- 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/acl/view.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/acl/view.pl	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-panel/acl/view.pl	2007-02-24 14:07:51 UTC (rev 495)
@@ -84,7 +84,7 @@
 }
 elsif( $type eq "mysql" )
 {
-	$object = new Vhffs::Services::Mysql( $vhffs , $name , $user , $group );
+	$object = Vhffs::Services::Mysql::get_by_dbname( $vhffs , $name );
 }
 elsif( $type eq "pgsql" )
 {
@@ -104,7 +104,7 @@
 }
 elsif( $type eq "mail" )
 {
-	$object = new Vhffs::Services::Mail( $vhffs , $name  );
+	$object = Vhffs::Services::Mail::get_by_mxdomain( $vhffs , $name  );
 }
 elsif( $type eq "ml" )
 {

Modified: branches/vhffs_4.1/vhffs-panel/admin/mysql/edit.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/admin/mysql/edit.pl	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-panel/admin/mysql/edit.pl	2007-02-24 14:07:51 UTC (rev 495)
@@ -79,7 +79,7 @@
 	my $message = gettext( "CGI ERROR !");
 	$template->param( MESSAGE => $message );
 }
-elsif( ( ! defined ( $object = new Vhffs::Services::Mysql( $vhffs , $name , '401' ) ) ) || ( $object->fetch < 0 ) )
+elsif( ! defined ( $object = Vhffs::Services::Mysql::get_by_dbname( $vhffs , $name ) ) )
 {
 	$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
 	my $message = gettext( "Cannot fetch object");

Modified: branches/vhffs_4.1/vhffs-panel/admin/mysql/edit_submit.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/admin/mysql/edit_submit.pl	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-panel/admin/mysql/edit_submit.pl	2007-02-24 14:07:51 UTC (rev 495)
@@ -56,7 +56,6 @@
 my $session = $panel->{'session'};
 my $maintemplate = $panel->{'template'};
 my $user = $panel->{'user'};
-#my $group = $panel->{'group'};
 my $projectname = $session->param("project");
 my $cgi = $panel->{'cgi'};
 my $name = $cgi->param("NAME");
@@ -79,7 +78,7 @@
 	my $message = gettext( "CGI ERROR !");
 	$template->param( MESSAGE => $message );
 }
-elsif( ( ! defined ( $object = new Vhffs::Services::Mysql( $vhffs , $name , '401' ) ) ) || ( $object->fetch < 0 ) )
+elsif( ! defined ( $object = Vhffs::Services::Mysql::get_by_dbname( $vhffs , $name ) ) )
 {
 	$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
 	my $message = sprintf( gettext("Cannot fetch object %s"), $name );

Modified: branches/vhffs_4.1/vhffs-panel/admin/mysql/show.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/admin/mysql/show.pl	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-panel/admin/mysql/show.pl	2007-02-24 14:07:51 UTC (rev 495)
@@ -78,7 +78,7 @@
 	my $message = gettext( "CGI ERROR !");
 	$template->param( MESSAGE => $message );
 }
-elsif( ( ! defined ( $object = new Vhffs::Services::Mysql( $vhffs , $name , '401' ) ) ) || ( $object->fetch < 0 ) )
+elsif( ! defined ( $object = Vhffs::Services::Mysql::get_by_dbname( $vhffs , $name ) ) )
 {
 	$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
 	my $message = gettext( "Cannot fetch object");

Modified: branches/vhffs_4.1/vhffs-panel/mysql/delete.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/mysql/delete.pl	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-panel/mysql/delete.pl	2007-02-24 14:07:51 UTC (rev 495)
@@ -63,11 +63,11 @@
 my $dbname = $cgi->param("DBNAME");
 my $sure = $cgi->param("DELETE");
 
-my $mysql = new Vhffs::Services::Mysql( $vhffs , $dbname , $user , $group );
+my $mysql = Vhffs::Services::Mysql::get_by_dbname( $vhffs, $dbname );
 
 my $templatedir = $vhffs->get_config->get_templatedir;
 
-if ( ! defined( $mysql ) || ( $mysql->fetch < 0 ) )
+if ( ! defined( $mysql ) )
 {
     $message = gettext("This database doesn't exist in VHFFS database");
 }

Modified: branches/vhffs_4.1/vhffs-panel/mysql/prefs.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/mysql/prefs.pl	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-panel/mysql/prefs.pl	2007-02-24 14:07:51 UTC (rev 495)
@@ -62,7 +62,7 @@
 
 my $templatedir = $vhffs->get_config->get_templatedir;
 
-my $mysql = new Vhffs::Services::Mysql( $vhffs , $dbname , $user , $group );
+my $mysql = Vhffs::Services::Mysql::get_by_dbname( $vhffs , $dbname );
 my $message;
 
 if( ! defined $dbname )
@@ -71,7 +71,7 @@
 	$message = gettext( "CGI Error !");
 	$template->param( MESSAGE => $message );
 }
-elsif( $mysql->fetch < 0 )
+elsif( ! defined($mysql) )
 {
 	$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
 	$message = gettext( "Cannot get informations on this object");

Modified: branches/vhffs_4.1/vhffs-panel/mysql/prefs_save.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/mysql/prefs_save.pl	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-panel/mysql/prefs_save.pl	2007-02-24 14:07:51 UTC (rev 495)
@@ -67,10 +67,10 @@
 
 my $dbname = $cgi->param("name");
 
-my $mysql = new Vhffs::Services::Mysql( $vhffs , $dbname , $user , $group );
+my $mysql = Vhffs::Services::Mysql::get_by_dbname( $vhffs , $dbname );
 
 
-if ( ! defined( $mysql ) || ( $mysql->fetch < 0 ) )
+if ( ! defined( $mysql ) )
 {
     $message = gettext("This database doesn't exist on VHFFS");
 }

Modified: branches/vhffs_4.1/vhffs-panel/mysql/submit.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/mysql/submit.pl	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-panel/mysql/submit.pl	2007-02-24 14:07:51 UTC (rev 495)
@@ -94,10 +94,8 @@
 {
 	$message = gettext( "The password is not valid" );
 }
-elsif( defined ( $mysql = Vhffs::Panel::Mysql::create_mysql($vhffs,$dbname,$user,$group,$dbuser,$dbpass ) ) )
+elsif( defined ( $mysql = Vhffs::Panel::Mysql::create_mysql($vhffs,$dbname,$user,$group,$dbuser,$dbpass,$description ) ) )
 {
-	$mysql->set_description( $description );
-	$mysql->commit;
 	$message = gettext("The MySQL object was successfully created !");
 }
 else

Modified: branches/vhffs_4.1/vhffs-robots/src/dump_mysql.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/dump_mysql.pl	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-robots/src/dump_mysql.pl	2007-02-24 14:07:51 UTC (rev 495)
@@ -88,7 +88,6 @@
 			}
 			
 		}
-#	$group = new Vhffs::Group( $vhffs , Vhffs::Group::get_name_by_gid( $vhffs , $obj->get_ownergid ) );
 }
 
 Vhffs::Robots::unlock( $vhffs );

Modified: branches/vhffs_4.1/vhffs-robots/src/refused_mysql.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/refused_mysql.pl	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-robots/src/refused_mysql.pl	2007-02-24 14:07:51 UTC (rev 495)
@@ -31,7 +31,7 @@
 
 foreach $object ( @{$objects} )
 {
-	if( ( defined $object ) && ( $object->fetch > 0 ) )
+	if( defined $object )
 	{
 		$user = $object->get_user;
 		$lang = Vhffs::Panel::User::get_lang( $user );

Modified: branches/vhffs_4.1/vhffs-tests/src/Services/Mail.pl
===================================================================
--- branches/vhffs_4.1/vhffs-tests/src/Services/Mail.pl	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-tests/src/Services/Mail.pl	2007-02-24 14:07:51 UTC (rev 495)
@@ -33,8 +33,8 @@
 $mail1->addbox('box1', 'dummy');
 my $boxes = $mail1->get_boxes;
 cmp_ok(scalar(%$boxes), '==', '1', 'Box added');
-cmp_ok($boxes->{box1}{local_part}, '==', 'box1', 'Local part OK');
-cmp_ok($boxes->{box1}{domain}, '==', 'test.com', 'Domain name propagated');
+cmp_ok($boxes->{box1}{local_part}, 'eq', 'box1', 'Local part OK');
+cmp_ok($boxes->{box1}{domain}, 'eq', 'test.com', 'Domain name propagated');
 
 my $mail2 = Vhffs::Services::Mail::get_by_mxdomain($main, 'test.com');
 isa_ok($mail2, 'Vhffs::Services::Mail', '$mail2');

Added: branches/vhffs_4.1/vhffs-tests/src/Services/Mysql.pl
===================================================================
--- branches/vhffs_4.1/vhffs-tests/src/Services/Mysql.pl	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-tests/src/Services/Mysql.pl	2007-02-24 14:07:51 UTC (rev 495)
@@ -0,0 +1,34 @@
+use strict;
+use Vhffs::Tests::Main;
+use Vhffs::Tests::Utils;
+use Vhffs::Constants;
+use Vhffs::User;
+use Vhffs::Services::Mysql;
+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, 'mysqlgroup1', $user1->get_uid, undef, 'Test group for mysql');
+isa_ok($group1, 'Vhffs::Group', '$group1');
+my $group2 = Vhffs::Group::create($main, 'mysqlgroup2', $user1->get_uid, undef, 'Test group for mysql');
+isa_ok($group2, 'Vhffs::Group', '$group1');
+
+my $mysql1 = Vhffs::Services::Mysql::create($main, 'mysql1', 'mysqlu1', 'plop', 'Test mysql DB 1', $user1, $group1);
+isa_ok($mysql1, 'Vhffs::Services::Mysql', '$mysql1');
+cmp_ok($mysql1->get_dbname, 'eq', 'mysql1', 'dbname is the one defined while creating object');
+cmp_ok($mysql1->get_dbusername, 'eq', 'mysqlu1', 'dbuser is the one defined while creating object');
+cmp_ok($mysql1->get_owneruid, '==', $user1->get_uid, 'uid matches');
+cmp_ok($mysql1->get_ownergid, '==', $group1->get_gid, 'gid matches');
+
+my @mysqles = @{Vhffs::Services::Mysql::getall($main)};
+cmp_ok(scalar(@mysqles), '==', 1, 'Total : 1 MySQL Service');
+is_deeply($mysqles[0], $mysql1, 'getall return correct MySQL objects');
+
+ok(!defined(Vhffs::Services::Mysql::getall($main, Vhffs::Constants::ACTIVATED)), 'No ACTIVATED mysql DB');
+

Modified: branches/vhffs_4.1/vhffs-tests/src/Stats.pl
===================================================================
--- branches/vhffs_4.1/vhffs-tests/src/Stats.pl	2007-02-22 20:36:03 UTC (rev 494)
+++ branches/vhffs_4.1/vhffs-tests/src/Stats.pl	2007-02-24 14:07:51 UTC (rev 495)
@@ -176,16 +176,13 @@
     $user = new Vhffs::User($main, "testuser0$i", 401);
     $group->fetch;
     $user->fetch;
-    $svc = new Vhffs::Services::Mysql($main, "mysqltest0$i", $user, $group);
-    $svc->set_dbpassword('abcdef');
-    $svc->create;
+    $svc = Vhffs::Services::Mysql::create($main, "mysqltest0$i", "mysqltest0$i", 'abcdef', "Mysql test DB #0$i", $user, $group);
 }
 
 $stats = new Vhffs::Stats($main);
 is($stats->get_mysql_in_moderation, 9, 'All MySQL services waiting for moderation');
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $svc = new Vhffs::Services::Mysql($main, "mysqltest0$i");
-    $svc->fetch;
+    $svc = Vhffs::Services::Mysql::get_by_dbname($main, "mysqltest0$i");
     $svc->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
     $svc->commit;
     $stats = new Vhffs::Stats($main);
@@ -194,8 +191,7 @@
 }
 
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $svc = new Vhffs::Services::Mysql($main, "mysqltest0$i");
-    $svc->fetch;
+    $svc = Vhffs::Services::Mysql::get_by_dbname($main, "mysqltest0$i");
     $svc->set_status(Vhffs::Constants::ACTIVATED);
     $svc->commit;
     $stats = new Vhffs::Stats($main);


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