[vhffs-dev] [505] HTTP Version Not Supported. |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 505
Author: beuss
Date: 2007-03-07 15:08:29 +0000 (Wed, 07 Mar 2007)
Log Message:
-----------
HTTP Version Not Supported.
Refactored Repository creation/fetching. Updated uses.
Modified Paths:
--------------
branches/vhffs_4.1/Makefile
branches/vhffs_4.1/vhffs-api/src/Vhffs/Object.pm
branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Repository.pm
branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Repository.pm
branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Cvs.pm
branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Repository.pm
branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql
branches/vhffs_4.1/vhffs-panel/admin/repository/edit_submit.pl
branches/vhffs_4.1/vhffs-panel/repository/delete.pl
branches/vhffs_4.1/vhffs-panel/repository/prefs_save.pl
branches/vhffs_4.1/vhffs-panel/repository/quota_used.pl
branches/vhffs_4.1/vhffs-robots/src/delete_repository.pl
branches/vhffs_4.1/vhffs-robots/src/fix_quota_repository.pl
branches/vhffs_4.1/vhffs-robots/src/refused_repository.pl
branches/vhffs_4.1/vhffs-robots/src/update_quota_used_repository.pl
Added Paths:
-----------
branches/vhffs_4.1/vhffs-tests/src/Services/Repository.pl
Modified: branches/vhffs_4.1/Makefile
===================================================================
--- branches/vhffs_4.1/Makefile 2007-03-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/Makefile 2007-03-07 15:08:29 UTC (rev 505)
@@ -311,4 +311,5 @@
@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");'
-
+test-repos:
+ @perl -I vhffs-tests/src/ -I vhffs-api/src/ -e 'use Test::Harness; Test::Harness::runtests("vhffs-tests/src/Services/Repository.pl");'
Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Object.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Object.pm 2007-03-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Object.pm 2007-03-07 15:08:29 UTC (rev 505)
@@ -100,7 +100,7 @@
sub _new {
my ($class, $main, $oid, $owner_uid, $date_creation, $description, $state, $type) = @_;
-
+
$self = {};
bless($self, $class);
Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Repository.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Repository.pm 2007-03-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Panel/Repository.pm 2007-03-07 15:08:29 UTC (rev 505)
@@ -90,19 +90,14 @@
sub create_repository
{
- my( $main , $name , $user , $group ) = @_;
+ my( $main , $name , $user , $group, $description ) = @_;
- return -1 if( ! defined $user );
- return -2 if( $group->fetch < 0 );
+ return undef unless(defined $user && defined $group);
- my $repo = new Vhffs::Services::Repository( $main , $name , $user , $group );
+ my $repo = Vhffs::Services::Repository::create( $main , $name , $description, $user , $group );
return undef if( ! defined $repo);
- $repo->set_user( $user );
- $repo->set_group( $group );
- return undef if( $repo->create < 0 );
-
return undef if ( Vhffs::Acl::add_acl( $user , $repo , Vhffs::Constants::ACL_DELETE , $main ) < 0 );
return undef if( Vhffs::Acl::add_acl( $group , $repo , Vhffs::Constants::ACL_VIEW , $main ) < 0 );
Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Repository.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Repository.pm 2007-03-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Robots/Repository.pm 2007-03-07 15:08:29 UTC (rev 505)
@@ -41,7 +41,7 @@
{
my $repo = shift;
- if( $repo->fetch > 0 )
+ if( defined $repo )
{
if( create_repositoryondisk( $repo ) > 0 )
{
@@ -61,7 +61,7 @@
{
my $repo = shift;
- if( $repo->fetch > 0 )
+ if( defined $repo )
{
my $vhffs = $repo->{'main'};
@@ -83,7 +83,7 @@
sub create_repositoryondisk
{
my $repo = shift;
- return if( $repo->fetch < 0 );
+ return if( ! defined $repo );
my $name = $repo->get_name;
my $vhffs = $repo->{'main'};
Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Cvs.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Cvs.pm 2007-03-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Cvs.pm 2007-03-07 15:08:29 UTC (rev 505)
@@ -292,8 +292,10 @@
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;
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-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Repository.pm 2007-03-07 15:08:29 UTC (rev 505)
@@ -76,10 +76,16 @@
return $this;
}
+sub check_name($)
+{
+ my $name = shift;
+ return ($name =~ /^[a-z0-9]+$/);
+}
+
sub delete
{
my $self = shift;
- $self->fetch;
+ return unless(defined $self);
my $query = "DELETE FROM vhffs_repository WHERE object_id='".$self->{'object_id'}."'";
my $request = $self->{'db'}->prepare($query);
@@ -89,8 +95,41 @@
return 1;
}
-sub create
+sub create
{
+ if($_[0]->isa('Vhffs::Services::Repository')) {
+ my ($package, $file, $line) = caller();
+ warn "Using deprecated form of method Vhffs::Services::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_repository(name, owner_uid, owner_gid, quota, quota_used, object_id) VALUES(?, ?, ?, ?, 0, ?)';
+
+ #Quota
+ my $config = $main->get_config()->get_service('repository');
+ my $quota = $config->{'default_quota'} if defined($config);
+ $quota = 100 unless defined($quota);
+
+ my $dbh = $main->get_db_object();
+
+ my $sth = $dbh->prepare($sql);
+
+ $sth->execute($rname, $user->get_uid, $group->get_gid, $quota, $parent->get_oid) or return undef;
+
+ return get_by_reponame($main, $rname);
+}
+
+sub old_create
+{
my $self = shift;
my $conf;
my $quota;
@@ -163,8 +202,34 @@
return 1;
}
+sub get_by_reponame($$) {
+ my ($main, $name) = @_;
+ my @params;
+ my $sql = 'SELECT r.repository_id, r.name, r.owner_uid, r.owner_gid, r.quota, r.quota_used, o.object_id, o.date_creation, o.description, o.state FROM vhffs_repository r INNER JOIN vhffs_object o ON o.object_id = r.object_id WHERE r.name = ?';
+
+ my $dbh = $main->get_db_object();
+ @params = $dbh->selectrow_array($sql, undef, $name);
+
+ return _new Vhffs::Services::Repository($main, @params);
+}
+
+sub _new {
+ my ($class, $main, $repository_id, $name, $owner_uid, $owner_gid, $quota, $quota_used, $oid, $date_creation, $description, $state) = @_;
+
+ my $self = $class->SUPER::_new($main, $oid, $owner_uid, $date_creation, $description, $state, Vhffs::Constants::TYPE_REPOSITORY);
+ return undef unless(defined $self);
+
+ $self->{repository_id} = $repository_id;
+ $self->{name} = $name;
+ $self->{owner_gid} = $owner_gid;
+ $self->{quota} = $quota;
+ $self->{quota_used} = $quota_used;
+
+ return $self;
+}
+
sub commit
{
my $self = shift;
@@ -181,38 +246,35 @@
sub getall
{
- my $vhffs = shift;
- my $state = shift;
- my $name = shift;
- my $group = shift;
+ my ($vhffs, $state, $name, $group) = @_;
- my $query;
- my $request;
+ my $repos = [];
+ my @params;
- my $objs;
- my $result;
- my $tmp;
+ my $sql = 'SELECT r.repository_id, r.name, r.owner_uid, r.owner_gid, r.quota, r.quota_used, o.object_id, o.date_creation, o.description, o.state FROM vhffs_repository r, vhffs_object o WHERE r.object_id = o.object_id';
+ if(defined($state)) {
+ $sql .= ' AND o.state = ?';
+ push(@params, $state);
+ }
+ if(defined $name) {
+ $sql = ' AND r.name = ?';
+ push(@params, $name);
+ }
+ if(defined($group)) {
+ $sql = ' AND r.owner_gid = ?';
+ push(@params, $group->get_gid);
+ }
+ $sql .= ' ORDER BY r.name';
+
+ my $dbh = $vhffs->get_db_object();
- $query = "SELECT r.name, r.object_id FROM vhffs_repository r, vhffs_object o WHERE r.object_id = o.object_id";
- $query.= " AND o.state='".$state."'" if( defined $state );
- $query.= " AND r.name LIKE '%".$name."%'" if( defined $name );
- $query.= " AND r.owner_gid='".$group->get_gid."'" if( defined $group );
- $query .= " ORDER BY r.name";
- $request = $vhffs->{'db'}->prepare( $query );
- my $rows = $request->execute;
+ my $sth = $dbh->prepare($sql);
+ $sth->execute(@params) or return undef;
- return undef if( $rows == 0);
-
- while( $result = $request->fetchrow_hashref )
- {
-
- $tmp = new Vhffs::Services::Repository( $vhffs , $result->{'name'} );
- if( ( defined ( $tmp ) ) && ( $tmp->fetch > 0 ) )
- {
- push @{$objs} , $tmp;
- }
- }
- return $objs;
+ while(my $r = $sth->fetchrow_arrayref()) {
+ push(@$repos, _new Vhffs::Services::Repository($vhffs, @$r));
+ }
+ return $repos;
}
@@ -295,27 +357,21 @@
sub getall_per_group
{
- my $main = shift;
- my $group = shift;
+ my ($main, $group) = @_;
my @result;
- my $repos;
- return undef if ( $group->fetch < 0 );
+ my $repos = [];
+ return undef if ( ! defined $group );
- my $query = "SELECT r.name , r.object_id, o.state FROM vhffs_repository r, vhffs_object o WHERE o.object_id=r.object_id AND r.owner_gid='".$group->get_gid."'";
+ my $sql = 'SELECT r.repository_id, r.name, r.owner_uid, r.owner_gid, r.quota, r.quota_used, o.object_id, o.date_creation, o.description, o.state FROM vhffs_repository r INNER JOIN vhffs_object o ON o.object_id = r.object_id WHERE r.owner_gid = ?';
- my $request = $main->{'db'}->prepare( $query ) or return -1;
+ my $dbh = $main->get_db_object();
+ my $sth = $dbh->prepare($sql);
+ $sth->execute($group->get_gid) or return undef;
-
- return undef if ( $request->execute() <= 0);
-
- my $reposs = $request->fetchall_hashref( 'name' );
- foreach $repos ( %{$reposs} )
- {
- my $repo = new Vhffs::Services::Repository( $main , $repos );
- push( @result , $repo ) if( $repo->fetch > 0 );
- }
-
- return \@result;
+ while(my $r = $sth->fetchrow_arrayref()) {
+ push(@$repos, _new Vhffs::Services::Repository($main, @$r));
+ }
+ return $repos;
}
Modified: branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql
===================================================================
--- branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql 2007-03-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/vhffs-backend/src/pgsql/initdb.sql 2007-03-07 15:08:29 UTC (rev 505)
@@ -298,6 +298,7 @@
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);
+ALTER TABLE vhffs_repository ADD CONSTRAINT vhffs_repository_unique_name UNIQUE (name);
-- 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/admin/repository/edit_submit.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/admin/repository/edit_submit.pl 2007-03-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/vhffs-panel/admin/repository/edit_submit.pl 2007-03-07 15:08:29 UTC (rev 505)
@@ -81,7 +81,7 @@
my $message = gettext( "CGI ERROR !");
$template->param( MESSAGE => $message );
}
-elsif( ( ! defined ( $object = new Vhffs::Services::Repository( $vhffs , $name ) ) ) || ( $object->fetch < 0 ) )
+elsif( ! defined ( $object = Vhffs::Services::Repository::get_by_reponame( $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/repository/delete.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/repository/delete.pl 2007-03-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/vhffs-panel/repository/delete.pl 2007-03-07 15:08:29 UTC (rev 505)
@@ -67,13 +67,13 @@
my $templatedir = $vhffs->get_config->get_templatedir;
-my $repo = new Vhffs::Services::Repository( $vhffs , $repo_name , $user , $group );
+my $repo = Vhffs::Services::Repository::get_by_reponame( $vhffs , $repo_name );
-if( ( ! defined $repo_name ) || ( ! defined $repo ) || ( ! defined $sure ) )
+if( ( ! defined $repo_name ) || ( ! defined $sure ) )
{
$message = sprintf( gettext("CGI Error ! %s"), $repo_name );
}
-elsif( $repo->fetch < 0 )
+elsif( ! defined $repo )
{
$message = gettext( "Cannot retrieve informations about this Download repository" );
}
Modified: branches/vhffs_4.1/vhffs-panel/repository/prefs_save.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/repository/prefs_save.pl 2007-03-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/vhffs-panel/repository/prefs_save.pl 2007-03-07 15:08:29 UTC (rev 505)
@@ -67,13 +67,13 @@
my $templatedir = $vhffs->get_config->get_templatedir;
-my $repo = new Vhffs::Services::Repository( $vhffs , $repo_name, $user , $group );
+my $repo = Vhffs::Services::Repository::get_by_reponame( $vhffs , $repo_name );
-if( ( ! defined $repo_name ) || ( ! defined $repo ) )
+if( ! defined $repo_name )
{
$message = sprintf( gettext("CGI Error ! %s"), $repo_name );
}
-elsif( $repo->fetch < 0 )
+elsif( ! defined $repo )
{
$message = gettext( "Cannot retrieve informations about this Download repository" );
}
Modified: branches/vhffs_4.1/vhffs-panel/repository/quota_used.pl
===================================================================
--- branches/vhffs_4.1/vhffs-panel/repository/quota_used.pl 2007-03-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/vhffs-panel/repository/quota_used.pl 2007-03-07 15:08:29 UTC (rev 505)
@@ -62,7 +62,7 @@
my $templatedir = $vhffs->get_config->get_templatedir;
my $template;
my $subtemplate;
-my $repo = new Vhffs::Services::Repository( $vhffs , $reponame , '401' );
+my $repo = Vhffs::Services::Repository::get_by_reponame( $vhffs , $reponame );
my $status;
my $quota;
@@ -82,7 +82,7 @@
$status = 0;
-if( ( ! defined $repo ) || ( $repo->fetch < 0 ) )
+if( ! defined $repo )
{
$gd = GD::Image->new(70,100);
$white = $gd->colorAllocate(255,255,255);
Modified: branches/vhffs_4.1/vhffs-robots/src/delete_repository.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/delete_repository.pl 2007-03-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/vhffs-robots/src/delete_repository.pl 2007-03-07 15:08:29 UTC (rev 505)
@@ -47,7 +47,7 @@
foreach $repo ( @{$repos} )
{
- if( ( defined $repo ) && ( $repo->fetch > 0 ))
+ if( defined $repo )
{
if( Vhffs::Robots::Repository::delete_repository( $repo ) > 0 )
{
Modified: branches/vhffs_4.1/vhffs-robots/src/fix_quota_repository.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/fix_quota_repository.pl 2007-03-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/vhffs-robots/src/fix_quota_repository.pl 2007-03-07 15:08:29 UTC (rev 505)
@@ -58,7 +58,7 @@
foreach $group ( @{$groups} )
{
- if( $group->fetch > 0 )
+ if( defined $group )
{
$quota = 0;
$blocks = 0;
@@ -69,7 +69,7 @@
{
foreach $repo ( @{$repos} )
{
- if( $repo->fetch > 0)
+ if( defined $repo )
{
$quota += $repo->get_quota;
$blocks += $repo->get_quota * 1024;
Modified: branches/vhffs_4.1/vhffs-robots/src/refused_repository.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/refused_repository.pl 2007-03-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/vhffs-robots/src/refused_repository.pl 2007-03-07 15:08:29 UTC (rev 505)
@@ -61,7 +61,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-robots/src/update_quota_used_repository.pl
===================================================================
--- branches/vhffs_4.1/vhffs-robots/src/update_quota_used_repository.pl 2007-03-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/vhffs-robots/src/update_quota_used_repository.pl 2007-03-07 15:08:29 UTC (rev 505)
@@ -56,7 +56,7 @@
foreach $group ( @{$groups} )
{
- if( $group->fetch > 0 )
+ if( defined $group )
{
$repos = Vhffs::Services::Repository::getall_per_group( $vhffs, $group);
if( defined $repos )
@@ -69,11 +69,8 @@
# set this space usedto all repositories of this group
foreach $repo ( @{$repos} )
{
- if( $repo->fetch > 0)
- {
- $repo->set_quota_used( $su );
- $repo->commit;
- }
+ $repo->set_quota_used( $su );
+ $repo->commit;
}
Vhffs::Robots::vhffs_log( sprintf( "Update quota used for repositories of group %s to %s MB" , $group->get_groupname , $su ) , $vhffs);
Added: branches/vhffs_4.1/vhffs-tests/src/Services/Repository.pl
===================================================================
--- branches/vhffs_4.1/vhffs-tests/src/Services/Repository.pl 2007-03-06 16:52:23 UTC (rev 504)
+++ branches/vhffs_4.1/vhffs-tests/src/Services/Repository.pl 2007-03-07 15:08:29 UTC (rev 505)
@@ -0,0 +1,33 @@
+use strict;
+use Vhffs::Tests::Main;
+use Vhffs::Tests::Utils;
+use Vhffs::Constants;
+use Vhffs::User;
+use Vhffs::Services::Repository;
+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, 'repogroup1', $user1->get_uid, undef, 'Test group for repositories');
+isa_ok($group1, 'Vhffs::Group', '$group1');
+my $group2 = Vhffs::Group::create($main, 'repogroup2', $user1->get_uid, undef, 'Test group for repositories');
+isa_ok($group2, 'Vhffs::Group', '$group1');
+
+my $repo1 = Vhffs::Services::Repository::create($main, 'repo1', 'Test repo 1', $user1, $group1);
+isa_ok($repo1, 'Vhffs::Services::Repository', '$repo1');
+cmp_ok($repo1->get_name, 'eq', 'repo1', 'name is the one defined while creating object');
+cmp_ok($repo1->get_owneruid, '==', $user1->get_uid, 'uid matches');
+cmp_ok($repo1->get_ownergid, '==', $group1->get_gid, 'gid matches');
+
+my @repos = @{Vhffs::Services::Repository::getall($main)};
+cmp_ok(scalar(@repos), '==', 1, 'Total : 1 Repository Service');
+is_deeply($repos[0], $repo1, 'getall return correct Repository objects');
+
+cmp_ok(@{Vhffs::Services::Repository::getall($main, Vhffs::Constants::ACTIVATED)}, '==', '0', 'No ACTIVATED Repository');
+