[vhffs-dev] [401] Refactored Vhffs::Services::Cvs.

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


Revision: 401
Author:   beuss
Date:     2007-01-16 12:21:18 +0000 (Tue, 16 Jan 2007)

Log Message:
-----------
Refactored Vhffs::Services::Cvs. Less queries, less overhead.
Addeed some tests.

Modified Paths:
--------------
    branches/vhffs_4.1/Makefile
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Cvs.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Cvs.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/User.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Cvs.pm
    branches/vhffs_4.1/vhffs-api/src/examples/create_cvs.pl
    branches/vhffs_4.1/vhffs-api/src/examples/show_dumper_cvs.pl
    branches/vhffs_4.1/vhffs-backend/src/pgsql/alter_from4.0_tocurrent.sql
    branches/vhffs_4.1/vhffs-panel/acl/view.pl
    branches/vhffs_4.1/vhffs-panel/admin/cvs/edit.pl
    branches/vhffs_4.1/vhffs-panel/admin/cvs/edit_submit.pl
    branches/vhffs_4.1/vhffs-panel/admin/cvs/show.pl
    branches/vhffs_4.1/vhffs-panel/cvs/cvs_submit.pl
    branches/vhffs_4.1/vhffs-panel/cvs/delete.pl
    branches/vhffs_4.1/vhffs-panel/cvs/prefs.pl
    branches/vhffs_4.1/vhffs-panel/cvs/prefs_save.pl
    branches/vhffs_4.1/vhffs-robots/src/cvs_fixperms.pl
    branches/vhffs_4.1/vhffs-robots/src/delete_cvs.pl
    branches/vhffs_4.1/vhffs-tests/src/Stats.pl

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


Modified: branches/vhffs_4.1/Makefile
===================================================================
--- branches/vhffs_4.1/Makefile	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/Makefile	2007-01-16 12:21:18 UTC (rev 401)
@@ -300,4 +300,6 @@
 	@perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/User.pl");'
 test-stats:
 	@perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Stats.pl");'
+test-cvs:
+	@perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Services/Cvs.pl");'
 

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Cvs.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Cvs.pm	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Cvs.pm	2007-01-16 12:21:18 UTC (rev 401)
@@ -85,19 +85,15 @@
 
 sub create_cvs
 {
-	my( $main , $cvsroot , $user , $group ) = @_;
+	my( $main, $cvsroot, $description, $user, $group ) = @_;
 
 	return -1 if( ! defined $user );
-	return -2 if( $group->fetch < 0 );
+	return -2 if( ! defined $group );
 
-	my $cvs = new Vhffs::Services::Cvs( $main , $cvsroot , $user , $group );
+    my $cvs = Vhffs::Services::Cvs::create($main, $cvsroot, $description, $user, $group);
 
 	return undef if( ! defined $cvs);
-	$cvs->set_user( $user );
-	$cvs->set_group( $group );
 
-	return undef if( $cvs->create < 0 );
-
 	return undef if ( Vhffs::Acl::add_acl( $user , $cvs , Vhffs::Constants::ACL_DELETE , $main ) < 0 );
 	return undef if( Vhffs::Acl::add_acl( $group , $cvs , Vhffs::Constants::ACL_VIEW , $main ) < 0 );
 

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Cvs.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Cvs.pm	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Cvs.pm	2007-01-16 12:21:18 UTC (rev 401)
@@ -67,36 +67,32 @@
 {
 	my $cvs = shift;
 
-	if( $cvs->fetch > 0 )
+    return unless(defined($cvs));
+
+	if( create_repository( $cvs ) > 0 )
 	{
-		if( create_repository( $cvs ) > 0 )
-		{
-			$cvs->set_status( Vhffs::Constants::ACTIVATED );
-			$cvs->commit;
-			$cvs->add_history("Cvsroot now created !" );
-		}
-		else
-		{
-			$cvs->add_history("Cvsroot NOT created, bots encounters errors !" );
-		}
+		$cvs->set_status( Vhffs::Constants::ACTIVATED );
+		$cvs->commit;
+		$cvs->add_history("Cvsroot now created !" );
 	}
+	else
+	{
+		$cvs->add_history("Cvsroot NOT created, bots encounters errors !" );
+	}
 }
 
 
 sub delete_cvs
 {
 	my $cvs = shift;
+    return unless(defined ($cvs));
+	my $cvsroot = $cvs->get_cvsroot;
+	my $vhffs = $cvs->{'main'};
 
-	if( $cvs->fetch > 0 )
-	{
-		my $cvsroot = $cvs->get_cvsroot;
-		my $vhffs = $cvs->{'main'};
-
-		my $dir = $cvs->get_dir;
-		my $cmd = "rm -rf $dir";
-		system( $cmd );
-		$cvs->delete;
-	}
+	my $dir = $cvs->get_dir;
+	my $cmd = "rm -rf $dir";
+	system( $cmd );
+	$cvs->delete;
 }
 
 
@@ -104,7 +100,7 @@
 sub create_repository
 {
 	my $cvs = shift;
-	return if( $cvs->fetch < 0 );
+    return unless(defined $cvs);
 	my $cvsroot = $cvs->get_cvsroot;
 	my $vhffs = $cvs->{'main'};
 

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/User.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/User.pm	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/User.pm	2007-01-16 12:21:18 UTC (rev 401)
@@ -87,7 +87,7 @@
 	
 	if( defined $user )
 	{
-		$user->add_history( "Ok, robots take now the creation of the user" );
+		$user->add_history( "Ok, robots take now the deletion of the user" );
 		$homedir = $user->get_home;
 
 		@subdirs = split( /\// , $homedir );

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Cvs.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Cvs.pm	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Cvs.pm	2007-01-16 12:21:18 UTC (rev 401)
@@ -95,6 +95,27 @@
 
 sub create
 {
+    # Compatibility stuff, will be deleted before 4.1 release
+    return old_create(@_) if($_[0]->isa('Vhffs::Services::Cvs'));
+
+    my ($main, $cvsroot, $description, $user, $group) = @_;
+    return undef unless(defined($user) && defined($group));
+    return undef unless(defined($cvsroot) && ($cvsroot =~ /^[a-z0-9]+$/));
+
+    my $parent = Vhffs::Object::create($main, $user->get_uid, $description);
+
+    return undef unless(defined($parent));
+
+    my $sql = 'INSERT INTO vhffs_cvs(cvsroot, owner_uid, owner_gid, public, object_id) VALUES (?, ?, ?, TRUE, ?)';
+    my $request = $main->{db}->prepare($sql);
+    $request->execute($cvsroot, $user->get_uid, $group->get_gid, $parent->get_oid) or return undef;
+
+    return get_by_cvsroot($main, $cvsroot);
+
+}
+
+sub old_create
+{
 	my $self = shift;
 
 	return -2 if ( $self->{'user'}->fetch < 0 );
@@ -207,43 +228,7 @@
 }
 
 
-sub getall
-{
-    my $vhffs = shift;
-    my $state = shift;
-    my $name = shift;
-    my $group = shift;
 
-    my $query;
-    my $request;
-
-    my $objs;
-    my $result;
-    my $tmp;
-
-    $query = "SELECT c.cvsroot, c.object_id FROM  vhffs_cvs c, vhffs_object o WHERE c.object_id = o.object_id";
-	$query.= " AND o.state='".$state."'" if( defined $state );
-	$query.= " AND c.cvsroot LIKE '%".$name."%'" if( defined $name );
-	$query.= " AND c.owner_gid='".$group->get_gid."'" if( defined $group );
-    $query .= " ORDER BY c.cvsroot";
-    $request = $vhffs->{'db'}->prepare( $query );
-    my $rows = $request->execute;
-
-    return undef if( $rows == 0);
-
-    while( $result = $request->fetchrow_hashref )
-    {
-
-        $tmp = new Vhffs::Services::Cvs( $vhffs , $result->{'cvsroot'} );
-        if( ( defined ( $tmp ) ) && ( $tmp->fetch > 0 ) )
-        {
-            push @{$objs} , $tmp;
-        }
-    }
-    return $objs;
-}
-
-
 sub set_user
 {
 	my ( $self , $user ) = @_;
@@ -296,27 +281,83 @@
     return( $self->{'main'}->get_config->get_datadir . "/cvs/cvsroot/" . $self->get_group->get_groupname . "/" . $self->get_cvsroot );
 }
 
+sub get_by_cvsroot {
+    my($main, $cvsroot) = @_;
+    my $sql = 'SELECT c.cvs_id, c.cvsroot, c.owner_uid, c.owner_gid, c.public, c.object_id, o.date_creation, o.description, o.state FROM vhffs_cvs c INNER JOIN vhffs_object o ON c.object_id = o.object_id WHERE c.cvsroot = ?';
+    my $dbh = $main->get_db_object();
+    my @params = $dbh->selectrow_array($sql, undef, $cvsroot);
 
+    return _new Vhffs::Services::Cvs($main, @params);
+}
+
+sub _new {
+    my ($class, $main, $cvs_id, $cvsroot, $owner_uid, $owner_gid, $public, $oid, $date_creation, $description, $state) = @_;
+    my $self = $class->SUPER::_new($main, $oid, $owner_uid, $date_creation, $description, $state);
+    return undef unless(defined $self);
+    $self->{cvsroot} = $cvsroot;
+    $self->{cvs_id} = $cvs_id;
+    $self->{owner_gid} = $owner_gid;
+    $self->{public} = $public;
+    return $self;
+}
+
+sub getall
+{
+    my ($vhffs, $state, $name, $group) = @_;
+
+    my $query;
+    my $request;
+    my @params;
+
+    my $objs;
+    my $result;
+    my $tmp;
+
+    $query = 'SELECT c.cvs_id, c.cvsroot, c.owner_uid, c.owner_gid, c.public, o.object_id, o.date_creation, o.description, o.state FROM vhffs_cvs c INNER JOIN vhffs_object o ON c.object_id = o.object_id';
+    if(defined $state) {
+        $query .= ' AND o.state=?';
+        push(@params, $state);
+    }
+    if(defined $name) {
+        $query .= ' AND c.cvsroot LIKE ?';
+        push(@params, '%'.$name.'%');
+    }
+
+    if(defined $group) {
+        $query .= ' AND c.owner_gid=?';
+        push(@params, $group->get_gid);
+    }
+    $query .= " ORDER BY c.cvsroot";
+    $request = $vhffs->{'db'}->prepare( $query );
+    my $rows = $request->execute(@params);
+
+    return undef if( ! $rows );
+
+    while( $result = $request->fetchrow_arrayref )
+    {
+        $tmp = _new Vhffs::Services::Cvs( $vhffs, @{$result} ) ;
+        push @{$objs} , $tmp;
+    }
+    return $objs;
+}
+
 sub getall_per_group
 {
-    my $main  = shift;
-    my $group = shift;
+    my ($main, $group) = @_;
     my @result;
     my $cvsroot;
-    return undef if ( $group->fetch < 0 );
+    return undef if ( ! defined $group );
     
-    my $query = "SELECT c.cvsroot , c.object_id, o.state  FROM vhffs_cvs c, vhffs_object o WHERE o.object_id=c.object_id AND c.owner_gid='".$group->get_gid."'";
-    
+    my $query = 'SELECT c.cvs_id, c.cvsroot, c.owner_uid, c.owner_gid, c.public, o.object_id, o.date_creation, o.description, o.state FROM vhffs_cvs c INNER JOIN vhffs_object o ON c.object_id = o.object_id WHERE c.owner_gid=? ORDER BY c.cvsroot';
+
     my $request = $main->{'db'}->prepare( $query ) or return -1;
 
     
-    return undef if ( $request->execute() <= 0);
+    return undef if ( ! $request->execute($group->get_gid) );
     
-    my $repos = $request->fetchall_hashref( 'cvsroot' );
-    foreach $cvsroot ( %{$repos}  )
+    while( my $repos = $request->fetchrow_arrayref()  )
     {
-	my $cvs = new Vhffs::Services::Cvs( $main , $cvsroot );
-	push( @result , $cvs ) if( $cvs->fetch > 0 );
+        push(@result, _new Vhffs::Services::Cvs($main, @{$repos}))
     }
     
 

Modified: branches/vhffs_4.1/vhffs-api/src/examples/create_cvs.pl
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/examples/create_cvs.pl	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-api/src/examples/create_cvs.pl	2007-01-16 12:21:18 UTC (rev 401)
@@ -32,12 +32,11 @@
 }
 
 
-$user = new Vhffs::User( $princ , "soda" , 401) ;
-$group = new Vhffs::Group( $princ , "soda" , 401) ;
+$user = Vhffs::User::get_by_username( $princ, 'soda' );
+$group = Vhffs::Group::get_by_groupname( $princ, 'soda' );
 
+my $cvs = Vhffs::Services::Cvs::create( $princ , "$ARGV[0]" , 'Sample cvs repo', $user , $group );
 
-my $cvs = new Vhffs::Services::Cvs( $princ , "$ARGV[0]" , $user , $group );
-
 if( defined $cvs )
 {
 	print "object created\n";
@@ -48,20 +47,4 @@
 	exit;
 }
 
-if( $cvs->create > 0)
-{
-	print "Successfully create cvs object in the database\n";
-}
-else
-{
-	print "ERROR while create cvs object in the database\n";
-	exit( 0 );
-}
-
-if ( $cvs->fetch < 0 )
-{
-	print "error while fetching informations in the database";
-}
-$cvs->commit;
-
 print Dumper $cvs;

Modified: branches/vhffs_4.1/vhffs-api/src/examples/show_dumper_cvs.pl
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/examples/show_dumper_cvs.pl	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-api/src/examples/show_dumper_cvs.pl	2007-01-16 12:21:18 UTC (rev 401)
@@ -26,11 +26,8 @@
 
 $config = $princ->get_config;
 
-my $user = new Vhffs::User( $princ , "soda" , '401');
-my $cvs = new Vhffs::Services::Cvs( $princ , $ARGV[0] , $user ) ;
+my $cvs = Vhffs::Services::Cvs::get_by_cvsroot( $princ , $ARGV[0] ) ;
 
-$cvs->fetch;
-
 print Dumper $cvs;
 
 print $cvs->get_description;

Modified: branches/vhffs_4.1/vhffs-backend/src/pgsql/alter_from4.0_tocurrent.sql
===================================================================
--- branches/vhffs_4.1/vhffs-backend/src/pgsql/alter_from4.0_tocurrent.sql	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-backend/src/pgsql/alter_from4.0_tocurrent.sql	2007-01-16 12:21:18 UTC (rev 401)
@@ -27,6 +27,7 @@
 -- username must be unique
 ALTER TABLE vhffs_users ADD CONSTRAINT vhffs_users_unique_username UNIQUE (username);
 ALTER TABLE vhffs_groups ADD CONSTRAINT vhffs_groups_unique_groupname UNIQUE (groupname);
+ALTER TABLE vhffs_cvs ADD CONSTRAINT vhffs_cvs_unique_cvsroot UNIQUE (cvsroot);
 
 ALTER TABLE vhffs_object ALTER owner_uid DROP NOT NULL;
 ALTER TABLE vhffs_users ALTER gid DROP NOT NULL;

Modified: branches/vhffs_4.1/vhffs-panel/acl/view.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/acl/view.pl	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-panel/acl/view.pl	2007-01-16 12:21:18 UTC (rev 401)
@@ -91,7 +91,7 @@
 }
 elsif( $type eq "cvs" )
 {
-	$object = new Vhffs::Services::Cvs( $vhffs , $name  );
+	$object = Vhffs::Services::Cvs::get_by_cvsroot( $vhffs , $name );
 }
 elsif( $type eq "svn" )
 {

Modified: branches/vhffs_4.1/vhffs-panel/admin/cvs/edit.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/admin/cvs/edit.pl	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-panel/admin/cvs/edit.pl	2007-01-16 12:21:18 UTC (rev 401)
@@ -78,7 +78,7 @@
 	my $message = gettext( "CGI ERROR !");
 	$template->param( MESSAGE => $message );
 }
-elsif( ( ! defined ( $object = new Vhffs::Services::Cvs( $vhffs , $name  ) ) ) || ( $object->fetch < 0 ) )
+elsif( ! defined ( $object = Vhffs::Services::Cvs::get_by_cvsroot( $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/cvs/edit_submit.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/admin/cvs/edit_submit.pl	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-panel/admin/cvs/edit_submit.pl	2007-01-16 12:21:18 UTC (rev 401)
@@ -80,7 +80,7 @@
 	my $message = gettext( "CGI ERROR !");
 	$template->param( MESSAGE => $message );
 }
-elsif( ( ! defined ( $object = new Vhffs::Services::Cvs( $vhffs , $name ) ) ) || ( $object->fetch < 0 ) )
+elsif( ! defined ( $object = Vhffs::Services::Cvs::get_by_cvsroot( $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/cvs/show.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/admin/cvs/show.pl	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-panel/admin/cvs/show.pl	2007-01-16 12:21:18 UTC (rev 401)
@@ -78,7 +78,7 @@
 	my $message = gettext( "CGI ERROR !");
 	$template->param( MESSAGE => $message );
 }
-elsif( ( ! defined ( $object = new Vhffs::Services::Cvs( $vhffs , $name  ) ) ) || ( $object->fetch < 0 ) )
+elsif( ! defined ( $object = Vhffs::Services::Cvs::get_by_cvsroot( $vhffs , $name  ) ) )
 {
 	$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
 	my $message = gettext( "Cannot fetch object");

Modified: branches/vhffs_4.1/vhffs-panel/cvs/cvs_submit.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/cvs/cvs_submit.pl	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-panel/cvs/cvs_submit.pl	2007-01-16 12:21:18 UTC (rev 401)
@@ -81,11 +81,9 @@
 else
 {
     #Create CVS
-    my $cvs = Vhffs::Panel::Cvs::create_cvs( $vhffs , "$repo_name" , $user , $group );
+    my $cvs = Vhffs::Panel::Cvs::create_cvs( $vhffs, $repo_name, $description, $user , $group );
     if( defined $cvs )
     {
-	$cvs->set_description( $description );
-	$cvs->commit;
 	$message = gettext("The CVS object was successfully created !");
     }
     else

Modified: branches/vhffs_4.1/vhffs-panel/cvs/delete.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/cvs/delete.pl	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-panel/cvs/delete.pl	2007-01-16 12:21:18 UTC (rev 401)
@@ -66,13 +66,13 @@
 
 my $templatedir = $vhffs->get_config->get_templatedir;
 
-my $cvs = new Vhffs::Services::Cvs( $vhffs , $repo , $user , $group );
+my $cvs;
 
-if( ( ! defined $repo ) || ( ! defined $cvs ) || ( ! defined $sure ) )
+if( ( ! defined $repo ) || ( ! defined $sure ) )
 {
     $message = sprintf( gettext("CGI Error ! %s"), $repo );
 }
-elsif( $cvs->fetch < 0 )
+elsif( !defined($cvs = Vhffs::Services::Cvs::get_by_cvsroot($vhffs, $repo) ) )
 {
 	$message = gettext( "Cannot retrieve informations about this CVS repository" );
 }

Modified: branches/vhffs_4.1/vhffs-panel/cvs/prefs.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/cvs/prefs.pl	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-panel/cvs/prefs.pl	2007-01-16 12:21:18 UTC (rev 401)
@@ -60,19 +60,19 @@
 my $repo_name = $cgi->param("name");
 my $template;
 
-my $cvs = new Vhffs::Services::Cvs( $vhffs , $repo_name , $user );
+my $cvs;
 
 my $message;
 
 my $templatedir = $vhffs->get_config->get_templatedir;
 
-if( ( ! defined $repo_name ) || ( ! defined $cvs ) )
+if( ! defined $repo_name )
 {
 	$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
 	$message = gettext( "CGI Error !");
 	$template->param( MESSAGE => $message );
 }
-elsif( $cvs->fetch < 0 )
+elsif( !defined($cvs = Vhffs::Services::Cvs::get_by_cvsroot($vhffs, $repo_name) ) )
 {
 	$template = new HTML::Template( filename => $templatedir."/misc/simplemsg.tmpl" );
 	$message = gettext( "Cannot get informations on this object");

Modified: branches/vhffs_4.1/vhffs-panel/cvs/prefs_save.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/cvs/prefs_save.pl	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-panel/cvs/prefs_save.pl	2007-01-16 12:21:18 UTC (rev 401)
@@ -66,14 +66,13 @@
 
 my $templatedir = $vhffs->get_config->get_templatedir;
 
-my $cvs = new Vhffs::Services::Cvs( $vhffs , $repo , $user , $group );
+my $cvs;
 
-if( ( ! defined $repo ) || ( ! defined $cvs ) )
+if( ( ! defined $repo ) )
 {
     $message = sprintf( gettext("CGI Error ! %s"), $repo );
-}
-elsif( $cvs->fetch < 0 )
-{
+
+} elsif( !defined($cvs = Vhffs::Services::Cvs::get_by_cvsroot($vhffs, $repo) ) ) {
 	$message = gettext( "Cannot retrieve informations about this CVS repository" );
 }
 elsif( ( Vhffs::Acl::what_perm_for_user( $user , $cvs , $vhffs ) < Vhffs::Constants::ACL_MODIFY ) && ( $user->is_admin != 1 ) )

Modified: branches/vhffs_4.1/vhffs-robots/src/cvs_fixperms.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/cvs_fixperms.pl	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-robots/src/cvs_fixperms.pl	2007-01-16 12:21:18 UTC (rev 401)
@@ -60,51 +60,48 @@
 
 foreach $cvs ( @{$cvss} )
 {
-	if( $cvs->fetch > 0 )
+	$dir = $cvs->get_dir . "/CVSROOT/" ;
+	$readers_file = $dir."/readers";
+	$passwd_file = $dir."/passwd";
+	$user = $cvs->get_user;
+	$group = $cvs->get_group;
+	#First, update uid and gid informations on files
+	if( ( defined $user ) && ( $group->fetch > 0 ) )
+        {
+	            Vhffs::Functions::change_owner_recur( $cvs->get_dir , $user->get_uid , $group->get_gid );
+	}
+
+	if( $cvs->is_public == 0 )
 	{
-		$dir = $cvs->get_dir . "/CVSROOT/" ;
-		$readers_file = $dir."/readers";
-		$passwd_file = $dir."/passwd";
-		$user = $cvs->get_user;
-		$group = $cvs->get_group;
-		#First, update uid and gid informations on files
-		if( ( defined $user ) && ( $group->fetch > 0 ) )
-	        {
-		            Vhffs::Functions::change_owner_recur( $cvs->get_dir , $user->get_uid , $group->get_gid );
-		}
+		Vhffs::Robots::vhffs_log( sprintf( "CVS fixperm (private) for %s", $cvs->get_cvsroot ), $vhffs);
+		$cvs->add_history("CVS is now private");
+		Vhffs::Functions::chmod_recur( $cvs->get_dir , 0660 , 02770 );
 
-		if( $cvs->is_public == 0 )
-		{
-			Vhffs::Robots::vhffs_log( sprintf( "CVS fixperm (private) for %s", $cvs->get_cvsroot ), $vhffs);
-			$cvs->add_history("CVS is now private");
-			Vhffs::Functions::chmod_recur( $cvs->get_dir , 0660 , 02770 );
+		#Delete reader_file if exists
+		unlink( $readers_file ) if( -f $readers_file );
+	}
+	else
+	{
+		#Fix permissions
+		Vhffs::Robots::vhffs_log( sprintf( "CVS fixperm (public) for %s", $cvs->get_cvsroot ), $vhffs);
+		$cvs->add_history("CVS is now public");
+		Vhffs::Functions::chmod_recur( $cvs->get_dir , 0664 , 02775 );
 
-			#Delete reader_file if exists
-			unlink( $readers_file ) if( -f $readers_file );
-		}
-		else
-		{
-			#Fix permissions
-			Vhffs::Robots::vhffs_log( sprintf( "CVS fixperm (public) for %s", $cvs->get_cvsroot ), $vhffs);
-			$cvs->add_history("CVS is now public");
-			Vhffs::Functions::chmod_recur( $cvs->get_dir , 0664 , 02775 );
 
+		#Fix readers file
+		Vhffs::Robots::vhffs_log( sprintf("CVS, put repository %s public" , $cvs->get_cvsroot), $vhffs);
+		open( FILE , ">$readers_file" ) or die( "cannot open $readers_file" );
+		print FILE "anonymous";
+		close( FILE );
 
-			#Fix readers file
-			Vhffs::Robots::vhffs_log( sprintf("CVS, put repository %s public" , $cvs->get_cvsroot), $vhffs);
-			open( FILE , ">$readers_file" ) or die( "cannot open $readers_file" );
-			print FILE "anonymous";
-			close( FILE );
-
-			open( FILE , ">$passwd_file" ) or die( "cannot open $passwd_file" );
-			print FILE "anonymous::".$user->get_username;
-			close( FILE );
-			chown $cvs->get_owneruid , $cvs->get_ownergid , $passwd_file;
-			chown $cvs->get_owneruid , $cvs->get_ownergid , $readers_file;
-		}
-		$cvs->set_status( Vhffs::Constants::ACTIVATED );
-		$cvs->commit;
+		open( FILE , ">$passwd_file" ) or die( "cannot open $passwd_file" );
+		print FILE "anonymous::".$user->get_username;
+		close( FILE );
+		chown $cvs->get_owneruid , $cvs->get_ownergid , $passwd_file;
+		chown $cvs->get_owneruid , $cvs->get_ownergid , $readers_file;
 	}
+	$cvs->set_status( Vhffs::Constants::ACTIVATED );
+	$cvs->commit;
 }
 
 Vhffs::Robots::unlock( $vhffs );

Modified: branches/vhffs_4.1/vhffs-robots/src/delete_cvs.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/delete_cvs.pl	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-robots/src/delete_cvs.pl	2007-01-16 12:21:18 UTC (rev 401)
@@ -46,26 +46,17 @@
 
 foreach $cvs ( @{$lol} )
 {
-    if( ( defined $cvs ) && ( $cvs->fetch > 0 ))
-    {
-        if( Vhffs::Robots::Cvs::delete_cvs( $cvs ) > 0 )
-		{
-			Vhffs::Robots::vhffs_log( sprintf( "Delete files from %s", $cvs->get_cvsroot ), $vhffs);
-		}
-		else
-		{
-			Vhffs::Robots::vhffs_log( sprintf( "Cannot delete files from %s", $cvs->get_cvsroot ), $vhffs);
-		}
-		
-		if( $cvs->delete > 0 )
-		{
-			Vhffs::Robots::vhffs_log( sprintf( "Delete CVS object %s", $cvs->get_cvsroot ), $vhffs);
-		}
-		else
-		{
-			Vhffs::Robots::vhffs_log( sprintf( "Cannot delete CVS object %s", $cvs->get_cvsroot ), $vhffs);
-		}
+    if( Vhffs::Robots::Cvs::delete_cvs( $cvs ) > 0 ) {
+        Vhffs::Robots::vhffs_log( sprintf( "Delete files from %s", $cvs->get_cvsroot ), $vhffs);
+    } else {
+        Vhffs::Robots::vhffs_log( sprintf( "Cannot delete files from %s", $cvs->get_cvsroot ), $vhffs);
     }
+
+    if( $cvs->delete > 0 ) {
+        Vhffs::Robots::vhffs_log( sprintf( "Delete CVS object %s", $cvs->get_cvsroot ), $vhffs);
+    } else {
+        Vhffs::Robots::vhffs_log( sprintf( "Cannot delete CVS object %s", $cvs->get_cvsroot ), $vhffs);
+    }
 }
 
 

Added: branches/vhffs_4.1/vhffs-tests/src/Services/Cvs.pl
===================================================================
--- branches/vhffs_4.1/vhffs-tests/src/Services/Cvs.pl	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-tests/src/Services/Cvs.pl	2007-01-16 12:21:18 UTC (rev 401)
@@ -0,0 +1,39 @@
+use strict;
+use Vhffs::Tests::Main;
+use Vhffs::Tests::Utils;
+use Vhffs::Constants;
+use Vhffs::User;
+use Vhffs::Services::Cvs;
+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, 'cvsgroup1', $user1->get_uid, undef, 'Test group for CVS');
+isa_ok($group1, 'Vhffs::Group', '$group1');
+my $group2 = Vhffs::Group::create($main, 'cvsgroup2', $user1->get_uid, undef, 'Test group for CVS');
+isa_ok($group2, 'Vhffs::Group', '$group1');
+
+my $cvs1 = Vhffs::Services::Cvs::create($main, 'cvs1', 'Test cvs repo 1', $user1, $group1);
+isa_ok($cvs1, 'Vhffs::Services::Cvs', '$cvs1');
+cmp_ok($cvs1->get_cvsroot, 'eq', 'cvs1', 'cvsroot is the one defined while creating object');
+cmp_ok($cvs1->get_owneruid, '==', $user1->get_uid, 'uid matches');
+cmp_ok($cvs1->get_ownergid, '==', $group1->get_gid, 'gid matches');
+
+my @cvses = @{Vhffs::Services::Cvs::getall($main)};
+cmp_ok(scalar(@cvses), '==', 1);
+is_deeply($cvses[0], $cvs1);
+
+ok(!defined(Vhffs::Services::Cvs::getall($main, Vhffs::Constants::ACTIVATED)), 'No ACTIVATED CVS repo');
+
+@cvses = @{Vhffs::Services::Cvs::getall_per_group($main, $group1)};
+cmp_ok(scalar(@cvses), '==', 1);
+is_deeply($cvses[0], $cvs1);
+
+# FIXME THIS ISN'T COHERENT, FOR get_all WE GOT AN UNDEFINED VALUE AND HERE A ZERO LENGTH ARRAY
+cmp_ok(scalar(@{Vhffs::Services::Cvs::getall_per_group($main, $group2)}), '==', 0, 'No CVS repo for group2');

Modified: branches/vhffs_4.1/vhffs-tests/src/Stats.pl
===================================================================
--- branches/vhffs_4.1/vhffs-tests/src/Stats.pl	2007-01-15 08:30:08 UTC (rev 400)
+++ branches/vhffs_4.1/vhffs-tests/src/Stats.pl	2007-01-16 12:21:18 UTC (rev 401)
@@ -127,15 +127,14 @@
     $user = new Vhffs::User($main, "testuser0$i", 401);
     $group->fetch;
     $user->fetch;
-    $svc = new Vhffs::Services::Cvs($main, "testcvs0$i", $user, $group);
-    $svc->create;
+    Vhffs::Services::Cvs::create($main, "testcvs0$i", '', $user, $group);
 }
 
 $stats->fetch;
 is($stats->get_cvs_in_moderation, 9, 'All cvs services waiting for moderation');
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $svc = new Vhffs::Services::Cvs($main, "testcvs0$i", "testcvs0$i");
-    $svc->fetch;
+    $svc = Vhffs::Services::Cvs::get_by_cvsroot($main, "testcvs0$i");
+
     $svc->set_status(Vhffs::Constants::WAITING_FOR_CREATION);
     $svc->commit;
     $stats->fetch;
@@ -144,8 +143,7 @@
 }
 
 for(my $i = 1 ; $i < 10 ; ++$i) {
-    $svc = new Vhffs::Services::Cvs($main, "testcvs0$i", "testcvs0$i");
-    $svc->fetch;
+    $svc = Vhffs::Services::Cvs::get_by_cvsroot($main, "testcvs0$i");
     $svc->set_status(Vhffs::Constants::ACTIVATED);
     $svc->commit;
     $stats->fetch;


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