[vhffs-dev] [510] Svn creation/fetching reworked. |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 510
Author: beuss
Date: 2007-03-17 23:55:26 +0000 (Sat, 17 Mar 2007)
Log Message:
-----------
Svn creation/fetching reworked.
Fixed a critical bug in Repository (sql syntax error under particular condition)
Modified Paths:
--------------
branches/vhffs_4.1/Makefile
branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Svn.pm
branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Svn.pm
branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Repository.pm
branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Svn.pm
branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql
branches/vhffs_4.1/vhffs-panel/svn/prefs_save.pl
branches/vhffs_4.1/vhffs-panel/svn/svn_submit.pl
branches/vhffs_4.1/vhffs-robots/src/create_svn.pl
branches/vhffs_4.1/vhffs-robots/src/delete_svn.pl
branches/vhffs_4.1/vhffs-robots/src/fix_quota.pl
branches/vhffs_4.1/vhffs-robots/src/refused_svn.pl
branches/vhffs_4.1/vhffs-robots/src/svn_public.pl
Added Paths:
-----------
branches/vhffs_4.1/vhffs-tests/src/Services/Svn.pl
Modified: branches/vhffs_4.1/Makefile
===================================================================
--- branches/vhffs_4.1/Makefile 2007-03-11 11:37:54 UTC (rev 509)
+++ branches/vhffs_4.1/Makefile 2007-03-17 23:55:26 UTC (rev 510)
@@ -299,6 +299,8 @@
@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-svn:
+ @perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Services/Svn.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");'
test-web:
Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Svn.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Svn.pm 2007-03-11 11:37:54 UTC (rev 509)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Svn.pm 2007-03-17 23:55:26 UTC (rev 510)
@@ -65,7 +65,7 @@
{
my ( $group , $main ) = @_;
- return undef if ( $group->fetch < 0 );
+ return undef unless( defined($group) );
my $query = "SELECT s.reponame , s.object_id, o.state FROM vhffs_svn s, vhffs_object o WHERE o.object_id=s.object_id AND s.owner_gid='".$group->get_gid."'";
@@ -111,24 +111,15 @@
sub create_svn
{
- my $main = shift;
- my $repo = shift;
- my $user = shift;
- my $group = shift;
+ my ($main, $repo, $description, $user, $group) = @_;
-
- return -1 if( ! defined $user );
- return -2 if( $group->fetch < 0 );
+ return -1 unless( defined $user );
+ return -2 unless( defined $group );
- my $svn = new Vhffs::Services::Svn( $main , $repo , $user , $group );
+ my $svn = Vhffs::Services::Svn::create( $main, $repo, $description, $user, $group );
- return -1 if( ! defined $svn );
+ return -1 unless( defined $svn );
- $svn->set_user( $user );
- $svn->set_group( $group );
-
- return -2 if( $svn->create < 0 );
-
return ( -3 ) if ( Vhffs::Acl::add_acl( $user , $svn , Vhffs::Constants::ACL_DELETE , $main ) < 0 );
return ( -3 ) if( Vhffs::Acl::add_acl( $group , $svn , Vhffs::Constants::ACL_VIEW , $main ) < 0 );
Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Svn.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Svn.pm 2007-03-11 11:37:54 UTC (rev 509)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Svn.pm 2007-03-17 23:55:26 UTC (rev 510)
@@ -90,56 +90,42 @@
my $apache_file;
my $user_file;
- if( ( defined $svn ) && ( $svn->fetch > 0 ) )
+ if( defined $svn )
{
$dir = $svn->get_dir;
if( $svn->get_status == Vhffs::Constants::WAITING_FOR_CREATION )
{
- my $ok = 1;
+ my $ok = 1;
- if( ! -e $dir )
- {
- Vhffs::Functions::create_dir( $dir ) if( ! -d $dir );
- $svn->add_history("Ok, robots find the empty directory and will create subversion repository");
- system("svnadmin create --fs-type fsfs $dir");
- Vhffs::Functions::chmod_recur( $dir , 0664 , 02775 );
- Vhffs::Functions::change_owner_recur( $dir , $svn->get_owneruid , $svn->get_ownergid );
- change_conf( $svn );
- $svn->add_history("The Robots created the subversion repository");
- }
- else
- {
- $ok = 0;
- #TODO support syslog
- $svn->set_status( Vhffs::Constants::CREATING_ERROR );
- $svn->commit();
- $svn->add_history("Error, directory of this subversion already exists ! Administrators must fix the problem");
- }
-
-
-
- if( $ok == 1 )
- {
- $svn->set_status( Vhffs::Constants::ACTIVATED );
+ if( ! -e $dir ) {
+ Vhffs::Functions::create_dir( $dir ) if( ! -d $dir );
+ $svn->add_history("Ok, robots find the empty directory and will create subversion repository");
+ system("svnadmin create --fs-type fsfs $dir");
+ Vhffs::Functions::chmod_recur( $dir , 0664 , 02775 );
+ Vhffs::Functions::change_owner_recur( $dir , $svn->get_owneruid , $svn->get_ownergid );
+ change_conf( $svn );
+ $svn->add_history("The Robots created the subversion repository");
+ } else {
+ $ok = 0;
+ #TODO support syslog
+ $svn->set_status( Vhffs::Constants::CREATING_ERROR );
+ $svn->commit();
+ $svn->add_history("Error, directory of this subversion already exists ! Administrators must fix the problem");
+ }
+ if( $ok == 1 ) {
+ $svn->set_status( Vhffs::Constants::ACTIVATED );
- if( $svn->commit < 0 )
- {
- $svn->add_history( "Cannot commit changes on the object ! ");
- }
- else
- {
- $svn->add_history( "Subversion repository is now active");
- }
- }
- else
- {
- $svn->add_history("Object is not created, problem while creating it");
- }
- }
+ if( $svn->commit < 0 ) {
+ $svn->add_history( "Cannot commit changes on the object ! ");
+ } else {
+ $svn->add_history( "Subversion repository is now active");
+ }
+ } else {
+ $svn->add_history("Object is not created, problem while creating it");
+ }
+ }
}
-
-
}
Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Repository.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Repository.pm 2007-03-11 11:37:54 UTC (rev 509)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Repository.pm 2007-03-17 23:55:26 UTC (rev 510)
@@ -257,11 +257,11 @@
push(@params, $state);
}
if(defined $name) {
- $sql = ' AND r.name = ?';
+ $sql .= ' AND r.name = ?';
push(@params, $name);
}
if(defined($group)) {
- $sql = ' AND r.owner_gid = ?';
+ $sql .= ' AND r.owner_gid = ?';
push(@params, $group->get_gid);
}
$sql .= ' ORDER BY r.name';
Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Svn.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Svn.pm 2007-03-11 11:37:54 UTC (rev 509)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Svn.pm 2007-03-17 23:55:26 UTC (rev 510)
@@ -81,6 +81,11 @@
return $this;
}
+sub check_name($) {
+ my $name = shift;
+ return ($name =~ /^[a-z0-9]{3,64}$/);
+}
+
sub delete
{
my $self = shift;
@@ -98,6 +103,33 @@
sub create
{
+ if($_[0]->isa('Vhffs::Services::Svn')) {
+ my ($package, $file, $line) = caller();
+ warn "Using deprecated form of method Vhffs::Svn::Repository::create from $package ($file:$line)\n";
+ return old_create(@_);
+ }
+ my ($main, $rname, $description, $user, $group) = @_;
+
+ return undef unless(defined($user) && defined($group));
+ return undef unless(check_name($rname));
+
+ my $parent = Vhffs::Object::create($main, $user->get_uid, $description);
+
+ return undef unless(defined $parent);
+
+ my $sql = 'INSERT INTO vhffs_svn(reponame, owner_uid, owner_gid, public, object_id) VALUES(?, ?, ?, 1, ?)';
+
+ my $dbh = $main->get_db_object();
+
+ my $sth = $dbh->prepare($sql);
+
+ $sth->execute($rname, $user->get_uid, $group->get_gid, $parent->get_oid) or return undef;
+
+ return get_by_reponame($main, $rname);
+}
+
+sub old_create
+{
my $self = shift;
@@ -134,10 +166,13 @@
sub fetch
{
+ my ($package, $file, $line) = caller();
+ warn "Using deprecated method Vhffs::Svn::fetch from $package ($file:$line).\n";
+
my $self = shift;
- my $query = "SELECT * FROM vhffs_svn where reponame='".$self->{'reponame'}."' AND owner_gid='".$self->{'group'}->get_gid."'";
+ my $query = "SELECT * FROM vhffs_svn where reponame='".$self->{'reponame'}."' AND owner_gid='".$self->get_group->get_gid."'";
my $request = $self->{'db'}->prepare( $query ) or return -1;
my $rows = $request->execute() or return -3;
@@ -165,17 +200,35 @@
return 1;
}
+sub get_by_reponame($$) {
+ my ($main, $reponame) = @_;
+ my @params;
+ my $sql = 'SELECT s.svn_id, s.reponame, s.owner_uid, s.owner_gid, s.public, o.object_id, o.date_creation, o.description, o.state FROM vhffs_svn s INNER JOIN vhffs_object o ON o.object_id = s.object_id WHERE s.reponame = ?';
-sub get_users
-{
- my $self = shift;
-
- return( $self->{'users'} );
+ my $dbh = $main->get_db_object();
+
+ @params = $dbh->selectrow_array($sql, undef, $reponame);
+
+ return _new Vhffs::Services::Svn($main, @params);
+
}
+sub _new
+{
+ my ($class, $main, $svn_id, $reponame, $owner_uid, $owner_gid, $public, $oid, $date_creation, $description, $state) = @_;
+ my $self = $class->SUPER::_new($main, $oid, $owner_uid, $date_creation, $description, $state, Vhffs::Constants::TYPE_SVN);
+ return undef unless(defined $self);
+ $self->{svn_id} = $svn_id;
+ $self->{reponame} = $reponame;
+ $self->{owner_gid} = $owner_gid;
+ $self->{public} = $public;
+
+ return $self;
+}
+
sub commit
{
my $self = shift;
@@ -256,77 +309,61 @@
sub getall
{
- my $vhffs = shift;
- my $state = shift;
- my $name = shift;
- my $group = shift;
+ my ($vhffs, $state, $name, $group) = @_;
- my $query;
- my $request;
+ my $svn = [];
+ my @params;
- my $objs;
- my $result;
- my $tmp;
-
-
- $query = "SELECT * FROM vhffs_svn s, vhffs_object o WHERE s.object_id = o.object_id ";
- $query.= " AND o.state='".$state."'" if( defined $state);
- $query.= " AND s.owner_gid='".$group->get_gid."'" if( defined $group);
- $query.= " AND s.reponame LIKE '%".$name."%'" if( defined $name);
- $query .= " ORDER BY reponame";
-
- $request = $vhffs->{'db'}->prepare( $query );
+ my $sql = 'SELECT s.svn_id, s.reponame, s.owner_uid, s.owner_gid, s.public, o.object_id, o.date_creation, o.description, o.state FROM vhffs_svn s, vhffs_object o WHERE o.object_id = s.object_id';
- my $rows = $request->execute;
-
- return undef if( $rows == 0);
- while( $result = $request->fetchrow_hashref )
- {
- my $group = Vhffs::Group::get_by_gid( $vhffs , $result->{'owner_gid'} );
+ if(defined $state) {
+ $sql .= ' AND o.state = ?';
+ push(@params, $state);
+ }
+ if(defined $name) {
+ $sql .= ' AND s.name = ?';
+ push(@params, $name);
+ }
+ if(defined($group)) {
+ $sql .= ' AND s.owner_gid = ?';
+ push(@params, $group->get_gid);
+ }
+ $sql .= ' ORDER BY s.reponame';
- $tmp = new Vhffs::Services::Svn( $vhffs , $result->{'reponame'} , undef , $group );
- if( ( defined ( $tmp ) ) && ( $tmp->fetch > 0 ) )
- {
- push @{$objs} , $tmp;
- }
+ my $dbh = $vhffs->get_db_object();
+
+ my $sth = $dbh->prepare($sql);
+ $sth->execute(@params) or die($sql) ; #return undef;
+
+ while(my $s = $sth->fetchrow_arrayref()) {
+ push(@$svn, _new Vhffs::Services::Svn($vhffs, @$s));
}
- return $objs;
+ return $svn;
}
sub getall_by_group
{
- my $vhffs = shift;
- my $group = shift;
+ my ($vhffs, $group) = @_;
- my $query;
- my $request;
+ my $svn = [];
+ my @params;
- my $objs;
- my $result;
- my $tmp;
+ return undef unless( defined $group );
- return undef if( $group->fetch < 1 );
-
- $query = "SELECT s.reponame, s.object_id FROM vhffs_svn s, vhffs_object o WHERE s.object_id = o.object_id AND s.owner_gid='".$group->get_gid."'";
-
- $request = $vhffs->{'db'}->prepare( $query );
- my $rows = $request->execute;
+ my $sql = 'SELECT s.svn_id, s.reponame, s.owner_uid, s.owner_gid, s.public, o.object_id, o.date_creation, o.description, o.state FROM vhffs_svn s INNER
+ JOIN vhffs_object o ON o.object_id = s.object_id WHERE s.owner_gid = ? ORDER BY s.reponame';
- return undef if( $rows == 0);
+ my $dbh = $vhffs->get_db_object();
- $result = $request->fetchall_hashref( 'reponame' );
+ my $sth = $dbh->prepare($sql);
+ $sth->execute($group->get_gid) or return undef;
- foreach( keys %{$result} )
- {
- $tmp = new Vhffs::Services::Svn( $vhffs , $_ , undef , $group);
- if( ( defined ( $tmp ) ) && ( $tmp->fetch > 0 ) )
- {
- push @{$objs} , $tmp;
- }
+ while(my $s = $sth->fetchrow_arrayref()) {
+ push(@$svn, _new Vhffs::Services::Svn($vhffs, @$s));
}
- return $objs;
+ return $svn;
}
Modified: branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql
===================================================================
--- branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql 2007-03-11 11:37:54 UTC (rev 509)
+++ branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql 2007-03-17 23:55:26 UTC (rev 510)
@@ -299,6 +299,7 @@
ALTER TABLE vhffs_pgsql ADD CONSTRAINT vhffs_pgsql_unique_dbname UNIQUE (dbname);
ALTER TABLE vhffs_pgsql ADD CONSTRAINT vhffs_pgsql_unique_dbuser UNIQUE (dbuser);
ALTER TABLE vhffs_repository ADD CONSTRAINT vhffs_repository_unique_name UNIQUE (name);
+ALTER TABLE vhffs_svn ADD CONSTRAINT vhffs_svn_unique_reponame UNIQUE (reponame);
-- 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/svn/prefs_save.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/svn/prefs_save.pl 2007-03-11 11:37:54 UTC (rev 509)
+++ branches/vhffs_4.1/vhffs-panel/svn/prefs_save.pl 2007-03-17 23:55:26 UTC (rev 510)
@@ -65,15 +65,15 @@
my $repo = $cgi->param( "REPO_NAME" );
my $public = $cgi->param( "PUBLIC" );
-my $svn = new Vhffs::Services::Svn( $vhffs , $repo , $user , $group );
+my $svn = Vhffs::Services::Svn::get_by_reponame( $vhffs , $repo );
my $templatedir = $vhffs->get_config->get_templatedir;
-if( ( ! defined $repo ) || ( ! defined $svn ) )
+if( ! defined $repo )
{
$message = sprintf( gettext("CGI Error ! %s"), $repo );
}
-elsif( $svn->fetch < 0 )
+elsif( ! defined($svn->fetch) )
{
$message = gettext( "Cannot retrieve informations about this Subversion repository" );
}
Modified: branches/vhffs_4.1/vhffs-panel/svn/svn_submit.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/svn/svn_submit.pl 2007-03-11 11:37:54 UTC (rev 509)
+++ branches/vhffs_4.1/vhffs-panel/svn/svn_submit.pl 2007-03-17 23:55:26 UTC (rev 510)
@@ -67,33 +67,19 @@
my $svn;
-if( ! defined( $repo_name ) )
-{
+if( ! defined( $repo_name ) ) {
$message = gettext("CGI Error !");
-}
-elsif( ( length( $repo_name ) < 3 ) || ( ! ( $repo_name =~ /^[a-z0-9]+$/)) )
-{
+} elsif( ( length( $repo_name ) < 3 ) || ( ! ( $repo_name =~ /^[a-z0-9]+$/)) ) {
$message = gettext("The repository name is too short. It must contains at least 3 caracters, and must only contain letters and numbers");
-}
-elsif( ( $svn = Vhffs::Panel::Svn::create_svn( $vhffs , $repo_name , $user , $group ) ) < 0 )
-{
- if( $svn == -2 )
- {
+} elsif( ( $svn = Vhffs::Panel::Svn::create_svn( $vhffs , $repo_name , $description, $user , $group ) ) < 0 ) {
+ if( $svn == -2 ) {
$message = gettext( "This repository name already exists" );
- }
- elsif( $svn == -3 )
- {
+ } elsif( $svn == -3 ) {
$message = gettext( "An error occured while setting up the ACL" );
- }
- else
- {
+ } else {
$message = gettext( "An error occured while creating the object" );
}
-}
-else
-{
- $svn->set_description( $description );
- $svn->commit;
+} else {
$message = gettext("The Subversion object was successfully created !");
}
Modified: branches/vhffs_4.1/vhffs-robots/src/create_svn.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/create_svn.pl 2007-03-11 11:37:54 UTC (rev 509)
+++ branches/vhffs_4.1/vhffs-robots/src/create_svn.pl 2007-03-17 23:55:26 UTC (rev 510)
@@ -45,17 +45,10 @@
my $svn;
foreach $svn ( @{$repos} )
{
- if( $svn->fetch >= 0)
- {
-
- if( Vhffs::Robots::Svn::create_repo( $vhffs , $svn ) < 0 )
- {
- Vhffs::Robots::vhffs_log( sprintf( "Cannot create SVN %s" , $svn->get_reponame ), $vhffs);
- }
- else
- {
- Vhffs::Robots::vhffs_log( sprintf( "Create SVN %s" , $svn->get_reponame ), $vhffs);
- }
+ if( Vhffs::Robots::Svn::create_repo( $vhffs , $svn ) < 0 ) {
+ Vhffs::Robots::vhffs_log( sprintf( "Cannot create SVN %s" , $svn->get_reponame ), $vhffs);
+ } else {
+ Vhffs::Robots::vhffs_log( sprintf( "Create SVN %s" , $svn->get_reponame ), $vhffs);
}
}
Modified: branches/vhffs_4.1/vhffs-robots/src/delete_svn.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/delete_svn.pl 2007-03-11 11:37:54 UTC (rev 509)
+++ branches/vhffs_4.1/vhffs-robots/src/delete_svn.pl 2007-03-17 23:55:26 UTC (rev 510)
@@ -45,25 +45,16 @@
my $svn;
foreach $svn ( @{$repos} )
{
- if( $svn->fetch >= 0)
- {
- if( Vhffs::Robots::Svn::delete_repo( $vhffs , $svn ) < 0 )
- {
- Vhffs::Robots::vhffs_log( sprintf( "Cannot delete files from SVN repository %s" , $svn->get_reponame ), $vhffs);
- }
- else
- {
- Vhffs::Robots::vhffs_log( sprintf( "Delete files from SVN repository %s" , $svn->get_reponame ), $vhffs);
- }
+ if( Vhffs::Robots::Svn::delete_repo( $vhffs , $svn ) < 0 ) {
+ Vhffs::Robots::vhffs_log( sprintf( "Cannot delete files from SVN repository %s" , $svn->get_reponame ), $vhffs);
+ } else {
+ Vhffs::Robots::vhffs_log( sprintf( "Delete files from SVN repository %s" , $svn->get_reponame ), $vhffs);
+ }
- if( $svn->delete < 0 )
- {
- Vhffs::Robots::vhffs_log( sprintf( "Cannot delete SVN repository object %s" , $svn->get_reponame ), $vhffs);
- }
- else
- {
- Vhffs::Robots::vhffs_log( sprintf( "Delete SVN repository object %s" , $svn->get_reponame ), $vhffs);
- }
+ if( $svn->delete < 0 ) {
+ Vhffs::Robots::vhffs_log( sprintf( "Cannot delete SVN repository object %s" , $svn->get_reponame ), $vhffs);
+ } else {
+ Vhffs::Robots::vhffs_log( sprintf( "Delete SVN repository object %s" , $svn->get_reponame ), $vhffs);
}
}
Modified: branches/vhffs_4.1/vhffs-robots/src/fix_quota.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/fix_quota.pl 2007-03-11 11:37:54 UTC (rev 509)
+++ branches/vhffs_4.1/vhffs-robots/src/fix_quota.pl 2007-03-17 23:55:26 UTC (rev 510)
@@ -55,40 +55,34 @@
foreach $group ( @{$groups} )
{
- if( $group->fetch > 0 )
- {
- $blocks = $group->get_quota * 1024;
- $inodes = $group->get_quota * 1126400 / 100;
+ $blocks = $group->get_quota * 1024;
+ $inodes = $group->get_quota * 1126400 / 100;
- unless( Quota::setqlim($dev, $group->get_gid, $blocks, $blocks, $inodes, $inodes, 0, 1) )
- {
- Vhffs::Robots::vhffs_log( sprintf( "Update quota for group %s set %s" , $group->get_groupname , $group->get_quota ) , $vhffs);
- }
- else
- {
- printf("Cannot update quota for group %s, reason: %s\n", $group->get_groupname, Quota::strerr);
- }
+ unless( Quota::setqlim($dev, $group->get_gid, $blocks, $blocks, $inodes, $inodes, 0, 1) )
+ {
+ Vhffs::Robots::vhffs_log( sprintf( "Update quota for group %s set %s" , $group->get_groupname , $group->get_quota ) , $vhffs);
}
+ else
+ {
+ printf("Cannot update quota for group %s, reason: %s\n", $group->get_groupname, Quota::strerr);
+ }
}
$users = Vhffs::User::getall( $vhffs , Vhffs::Constants::ACTIVATED );
foreach $user ( @{$users} )
{
- if( defined $user )
- {
- $blocks = 1024;
- $inodes = 1126400 / 100;
+ $blocks = 1024;
+ $inodes = 1126400 / 100;
- unless( Quota::setqlim($dev, $user->get_gid, $blocks, $blocks, $inodes, $inodes, 0, 1) )
- {
+ unless( Quota::setqlim($dev, $user->get_gid, $blocks, $blocks, $inodes, $inodes, 0, 1) )
+ {
Vhffs::Robots::vhffs_log( sprintf( "Update quota for user group %s set 1" , $user->get_username ) , $vhffs);
- }
- else
- {
- printf("Cannot update quota for group %s, reason: %s\n", $user->get_username, Quota::strerr);
- }
}
+ else
+ {
+ printf("Cannot update quota for group %s, reason: %s\n", $user->get_username, Quota::strerr);
+ }
}
Vhffs::Robots::unlock( $vhffs );
Modified: branches/vhffs_4.1/vhffs-robots/src/refused_svn.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/refused_svn.pl 2007-03-11 11:37:54 UTC (rev 509)
+++ branches/vhffs_4.1/vhffs-robots/src/refused_svn.pl 2007-03-17 23:55:26 UTC (rev 510)
@@ -31,31 +31,26 @@
foreach $object ( @{$objects} )
{
- if( ( defined $object ) && ( $object->fetch > 0 ) )
- {
- $user = $object->get_user;
- $lang = Vhffs::Panel::User::get_lang( $user );
- setlocale( LC_ALL , $lang ) if( defined $lang );
- if( defined $user )
- {
- $message = sprintf( gettext("Your Subversion repository request : %s") , $object->get_reponame);
- $message .= gettext("has been refused by the Moderators team")."\n";
- $message .= gettext("In hope to keep you in our hosting service")."\n\n";
- if( length( $object->get_description ) > 1 )
- {
- $message .= gettext("Reason given : ");
- $message .= $object->get_description . "\n";
- }
- $message .= sprintf( gettext("If you encounters problem, please mail: %s\n") , $vhffs->get_config->get_moderator_mail ) if( defined $vhffs->get_config->get_moderator_mail );
- $message .= gettext("Cheers,")."\n";
- $message .= gettext("The Moderator and Admin team");
-
- $subject = gettext("Your Subversion repository request");
- Vhffs::Functions::send_mail( $vhffs->get_config->get_moderator_mail , $user->get_mail , $subject , $message );
+ $user = $object->get_user;
+ $lang = Vhffs::Panel::User::get_lang( $user );
+ setlocale( LC_ALL , $lang ) if( defined $lang );
+ if( defined $user ) {
+ $message = sprintf( gettext("Your Subversion repository request : %s") , $object->get_reponame);
+ $message .= gettext("has been refused by the Moderators team")."\n";
+ $message .= gettext("In hope to keep you in our hosting service")."\n\n";
+ if( length( $object->get_description ) > 1 ) {
+ $message .= gettext("Reason given : ");
+ $message .= $object->get_description . "\n";
}
-
- $object->delete;
+ $message .= sprintf( gettext("If you encounters problem, please mail: %s\n") , $vhffs->get_config->get_moderator_mail ) if( defined $vhffs->get_config->get_moderator_mail );
+ $message .= gettext("Cheers,")."\n";
+ $message .= gettext("The Moderator and Admin team");
+
+ $subject = gettext("Your Subversion repository request");
+ Vhffs::Functions::send_mail( $vhffs->get_config->get_moderator_mail , $user->get_mail , $subject , $message );
}
+
+ $object->delete;
}
Modified: branches/vhffs_4.1/vhffs-robots/src/svn_public.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/svn_public.pl 2007-03-11 11:37:54 UTC (rev 509)
+++ branches/vhffs_4.1/vhffs-robots/src/svn_public.pl 2007-03-17 23:55:26 UTC (rev 510)
@@ -45,43 +45,33 @@
my $svn;
foreach $svn ( @{$repos} )
{
- if( $svn->fetch >= 0)
- {
- $user = $svn->get_user;
- $group = $svn->get_group;
- #First, update uid and gid informations on files
- if( ( $user->fetch > 0 ) && ( $group->fetch > 0 ) )
- {
+ $user = $svn->get_user;
+ $group = $svn->get_group;
+ #First, update uid and gid informations on files
+ if( ( defined $user ) && ( defined $group ) ) {
Vhffs::Robots::vhffs_log( sprintf( "SVN change owner/group to %s/%s for repository %s" , $user->get_username , $group->get_groupname , $svn->get_dir ) , $vhffs);
Vhffs::Functions::change_owner_recur( $svn->get_dir , $user->get_uid , $group->get_gid );
- }
+ }
+ if( $svn->is_public == 1 ) {
+ Vhffs::Robots::vhffs_log( sprintf( "SVN change status %s is now public" , $svn->get_dir ) , $vhffs);
+ Vhffs::Functions::chmod_recur( $svn->get_dir , 0664 , 02775 );
+ } else {
+ Vhffs::Robots::vhffs_log( sprintf( "SVN change status %s is now private" , $svn->get_dir ) , $vhffs);
+ Vhffs::Functions::chmod_recur( $svn->get_dir , 0660 , 02770 );
+ }
- if( $svn->is_public == 1 )
- {
- Vhffs::Robots::vhffs_log( sprintf( "SVN change status %s is now public" , $svn->get_dir ) , $vhffs);
- Vhffs::Functions::chmod_recur( $svn->get_dir , 0664 , 02775 );
- }
- else
- {
- Vhffs::Robots::vhffs_log( sprintf( "SVN change status %s is now private" , $svn->get_dir ) , $vhffs);
- Vhffs::Functions::chmod_recur( $svn->get_dir , 0660 , 02770 );
- }
-
- Vhffs::Robots::Svn::change_conf( $svn );
- $svn->set_status( Vhffs::Constants::ACTIVATED );
-
- if( $svn->commit < 0 )
- {
- $svn->add_history( "Error while updating repository configuration");
- }
- else
- {
- $svn->add_history( "Successfully modify repository configuration");
- }
+ Vhffs::Robots::Svn::change_conf( $svn );
+ $svn->set_status( Vhffs::Constants::ACTIVATED );
+
+ if( $svn->commit < 0 ) {
+ $svn->add_history( "Error while updating repository configuration");
+ } else {
+ $svn->add_history( "Successfully modify repository configuration");
}
}
+
Vhffs::Robots::unlock( $vhffs );
exit 0;
Added: branches/vhffs_4.1/vhffs-tests/src/Services/Svn.pl
===================================================================
--- branches/vhffs_4.1/vhffs-tests/src/Services/Svn.pl 2007-03-11 11:37:54 UTC (rev 509)
+++ branches/vhffs_4.1/vhffs-tests/src/Services/Svn.pl 2007-03-17 23:55:26 UTC (rev 510)
@@ -0,0 +1,39 @@
+use strict;
+use Vhffs::Tests::Main;
+use Vhffs::Tests::Utils;
+use Vhffs::Constants;
+use Vhffs::User;
+use Vhffs::Services::Svn;
+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, 'svngroup1', $user1->get_uid, undef, 'test group for svn');
+isa_ok($group1, 'Vhffs::Group', '$group1');
+my $group2 = Vhffs::Group::create($main, 'svngroup2', $user1->get_uid, undef, 'test group for svn');
+isa_ok($group2, 'Vhffs::Group', '$group1');
+
+my $svn1 = Vhffs::Services::Svn::create($main, 'svn1', 'test svn repo 1', $user1, $group1);
+isa_ok($svn1, 'Vhffs::Services::Svn', '$svn1');
+cmp_ok($svn1->get_reponame, 'eq', 'svn1', 'svnroot is the one defined while creating object');
+cmp_ok($svn1->get_owneruid, '==', $user1->get_uid, 'uid matches');
+cmp_ok($svn1->get_ownergid, '==', $group1->get_gid, 'gid matches');
+
+my @svns = @{Vhffs::Services::Svn::getall($main)};
+cmp_ok(scalar(@svns), '==', 1, 'One Svn repository registered');
+is_deeply($svns[0], $svn1, 'Activated Svn repository is the created one');
+
+cmp_ok(scalar(@{Vhffs::Services::Svn::getall($main, Vhffs::Constants::ACTIVATED)}), '==', 0, 'No ACTIVATED Svn repo');
+
+@svns = @{Vhffs::Services::Svn::getall_by_group($main, $group1)};
+cmp_ok(scalar(@svns), '==', 1, 'group1 has one repository');
+is_deeply($svns[0], $svn1, 'group1\' repository is the created one');
+
+# FIXME THIS ISN'T COHERENT, FOR get_all WE GOT AN UNDEFINED VALUE AND HERE A ZERO LENGTH ARRAY
+cmp_ok(scalar(@{Vhffs::Services::Svn::getall_by_group($main, $group2)}), '==', 0, 'No Svn repo for group2');