[vhffs-dev] [529] All services and objects creations are now in transaction => no more orphan objects.

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


Revision: 529
Author:   beuss
Date:     2007-03-25 17:27:38 +0000 (Sun, 25 Mar 2007)

Log Message:
-----------
All services and objects creations are now in transaction => no more orphan objects.

Modified Paths:
--------------
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Group.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Cvs.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/DNS.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Httpd.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mail.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mailing.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mysql.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Postgres.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Repository.pm
    branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Svn.pm


Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Group.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Group.pm	2007-03-25 17:24:45 UTC (rev 528)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Group.pm	2007-03-25 17:27:38 UTC (rev 529)
@@ -94,23 +94,51 @@
         }
     }
 
+    my $groupconf = $main->get_config->get_users;
+    my $group;
 
     my $dbh = $main->get_db_object;
-    my $groupconf = $main->get_config->get_users;
+    local $dbh->{RaiseError} = 1;
+    local $dbh->{PrintError} = 0;
 
-    my $parent = Vhffs::Object::create($main, $owner_uid, $description, undef, Vhffs::Constants::TYPE_GROUP);
-    return undef unless(defined $parent);
+    # Avoid an error if we're already in a transaction
+    # (eg. when creating user).
+    my $transaction_started;
+    if($dbh->{AutoCommit}) {
+        # AutoCommit is on => we're not yet in a
+        # transaction, let's start one
+        $dbh->begin_work;
+        $transaction_started = 1;
+    } else {
+        # We're already in a transaction, ensure that
+        # we don't corrupt it.
+        $transaction_started = 0;
+    }
+
+    eval {
+        my $parent = Vhffs::Object::create($main, $owner_uid, $description, undef, Vhffs::Constants::TYPE_GROUP);
+        die('Unable to create parent object') unless(defined $parent);
     
-    my $quota = $groupconf->{default_quota} || 10;
-    # Special case : sometimes, gid can be passed to create
-    # to avoid updates (cf Vhffs::User::create)
-    ($gid) = $dbh->selectrow_array('SELECT nextval(\'vhffs_groups_gid_seq\')') unless defined $gid;
+        my $quota = $groupconf->{default_quota} || 10;
+        # Special case : sometimes, gid can be passed to create
+        # to avoid updates (cf Vhffs::User::create)
+        ($gid) = $dbh->selectrow_array('SELECT nextval(\'vhffs_groups_gid_seq\')') unless defined $gid;
     
-    my $query = 'INSERT INTO vhffs_groups(gid, groupname, passwd, quota, quota_used, owner_uid, uid_mod, object_id) VALUES(?, ?, NULL, ?, 0, ?, ?, ?)';
-    my $sth = $dbh->prepare( $query ) or return undef;
-    $sth->execute($gid, $groupname, $quota, $owner_uid, $owner_uid, $parent->get_oid) or return undef;
+        my $query = 'INSERT INTO vhffs_groups(gid, groupname, passwd, quota, quota_used, owner_uid, uid_mod, object_id) VALUES(?, ?, NULL, ?, 0, ?, ?, ?)';
+        my $sth = $dbh->prepare( $query );
+        $sth->execute($gid, $groupname, $quota, $owner_uid, $owner_uid, $parent->get_oid);
 
-    return get_by_gid($main, $gid);
+        $dbh->commit if($transaction_started);
+        $group = get_by_gid($main, $gid);
+    };
+
+    if($transaction_started && $@) {
+        warn "Unable to create group $groupname: $@\n";
+        $dbh->rollback;
+    }
+
+    return $group;
+
 }
 
 sub remove_user

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-25 17:24:45 UTC (rev 528)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Cvs.pm	2007-03-25 17:27:38 UTC (rev 529)
@@ -94,16 +94,31 @@
     return undef unless(defined($user) && defined($group));
     return undef unless(check_cvsroot($cvsroot));
 
-    my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_CVS);
+    my $cvs;
+    my $dbh = $main->get_db_object();
+    local $dbh->{RaiseError} = 1;
+    local $dbh->{PrintError} = 0;
+    $dbh->begin_work;
+    eval {
 
-    return undef unless(defined($parent));
+        my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_CVS);
 
-    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;
+        die('Unable to create parent object') unless(defined($parent));
 
-    return get_by_cvsroot($main, $cvsroot);
+        my $sql = 'INSERT INTO vhffs_cvs(cvsroot, owner_uid, owner_gid, public, object_id) VALUES (?, ?, ?, TRUE, ?)';
+        my $sth = $dbh->prepare($sql);
+        $sth->execute($cvsroot, $user->get_uid, $group->get_gid, $parent->get_oid);
 
+        $dbh->commit;
+        $cvs = get_by_cvsroot($main, $cvsroot);
+    };
+
+    if($@) {
+        warn "Error creating cvs service: $@\n";
+        $dbh->rollback;
+    }
+    return $cvs;
+
 }
 
 sub commit

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/DNS.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/DNS.pm	2007-03-25 17:24:45 UTC (rev 528)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/DNS.pm	2007-03-25 17:27:38 UTC (rev 529)
@@ -107,24 +107,39 @@
     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, undef, Vhffs::Constants::TYPE_DNS);
+    my $dbh = $main->get_db_object();
+    local $dbh->{RaiseError} = 1;
+    local $dbh->{PrintError} = 0;
+    $dbh->begin_work;
+    my $self;
 
-    return undef unless(defined $parent);
+    eval {
 
-    my $sql = 'INSERT INTO vhffs_dns (domain, owner_uid, owner_gid, object_id, ns, mbox, serial, refresh, retry, expire, minimum, ttl) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
-    my ($day, $month, $year);
-    (undef,undef,undef,$day,$month,$year) = localtime(time);
-    my $serial = sprintf('%.4u%.2u%.2u01',$year+1900,$month+1,$day);
+        my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_DNS);
 
-    my $dbh = $main->get_db_object();
+        die('Unable to create parent object') unless(defined $parent);
 
-    my $sth = $dbh->prepare($sql);
+        my $sql = 'INSERT INTO vhffs_dns (domain, owner_uid, owner_gid, object_id, ns, mbox, serial, refresh, retry, expire, minimum, ttl) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
+        my ($day, $month, $year);
+        (undef,undef,undef,$day,$month,$year) = localtime(time);
+        my $serial = sprintf('%.4u%.2u%.2u01',$year+1900,$month+1,$day);
 
-    $sth->execute($domain, $user->get_uid, $group->get_gid, $parent->get_oid, $conf->{default_ns1}, $conf->{default_mbox}, $serial, 
-        $conf->{default_refresh}, $conf->{default_retry}, $conf->{default_expire}, $conf->{default_minimum}, $conf->{default_minimum}) or return undef;
+        my $sth = $dbh->prepare($sql);
 
-    my $self = get_by_domainname($main, $domain);
+        $sth->execute($domain, $user->get_uid, $group->get_gid, $parent->get_oid, $conf->{default_ns1}, $conf->{default_mbox}, $serial, 
+            $conf->{default_refresh}, $conf->{default_retry}, $conf->{default_expire}, $conf->{default_minimum}, $conf->{default_minimum});
 
+        $dbh->commit;
+        $self = get_by_domainname($main, $domain);
+    };
+
+    # Something went wrong, let's cancel everything
+    if($@) {
+        warn "Error creating domain $domain: $@\n";
+        $dbh->rollback;
+        return undef;
+    }
+
     # Fill in default information defined in configuration.
     if( defined $conf->{init} ) {
         my ($ip, $name, $prio);

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Httpd.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Httpd.pm	2007-03-25 17:24:45 UTC (rev 528)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Httpd.pm	2007-03-25 17:27:38 UTC (rev 529)
@@ -68,23 +68,36 @@
 
 sub create
 {
-    return old_create(@_) if($_[0]->isa('Vhffs::Services::Httpd'));
     my ($main, $servername, $description, $user, $group) = @_;
     return undef unless(defined($user) && defined($group));
     return undef unless(Vhffs::Functions::check_domain_name($servername));
 
-    my $parent =  Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_HTTPD);
+    my $web;
+    my $dbh = $main->get_db_object();
+    local $dbh->{RaiseError} = 1;
+    local $dbh->{PrintError} = 0;
+    $dbh->begin_work;
+
+    eval {
+        my $parent =  Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_HTTPD);
     
-    return undef unless(defined($parent));
+        die('Unable to create parent object') unless(defined($parent));
 
-    my $sql = 'INSERT INTO vhffs_httpd(servername, crawl, owner_http, owner_rev, owner_uid, owner_gid, trafic, alert_state, alert_limit, object_id) VALUES(?, 1, ?, ?, ?, ?, 0, 0, 0, ?)';
+        my $sql = 'INSERT INTO vhffs_httpd(servername, crawl, owner_http, owner_rev, owner_uid, owner_gid, trafic, alert_state, alert_limit, object_id) VALUES(?, 1, ?, ?, ?, ?, 0, 0, 0, ?)';
 
-    my $dbh = $main->get_db_object();
 
-    my $sth = $dbh->prepare($sql);
-    $sth->execute($servername, $user->get_uid, $user->get_uid, $user->get_uid, $group->get_gid, $parent->get_oid) or return undef;
+        my $sth = $dbh->prepare($sql);
+        $sth->execute($servername, $user->get_uid, $user->get_uid, $user->get_uid, $group->get_gid, $parent->get_oid);
 
-    return get_by_servername($main, $servername);
+        $dbh->commit;
+        $web = get_by_servername($main, $servername);
+    };
+
+    if($@) {
+        warn "Unable to create webarea $servername: $@\n";
+        $dbh->rollback;
+    }
+    return $web;
 }
 
 sub commit

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mail.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mail.pm	2007-03-25 17:24:45 UTC (rev 528)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mail.pm	2007-03-25 17:27:38 UTC (rev 529)
@@ -94,17 +94,32 @@
     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, undef, Vhffs::Constants::TYPE_MAIL);
+    my $mail;
+    my $dbh = $main->get_db_object();
+    local $dbh->{RaiseError} = 1;
+    local $dbh->{PrintError} = 0;
+    $dbh->begin_work;
 
-    return undef unless(defined $parent);
+    eval {
+        my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_MAIL);
 
-    my $sql = 'INSERT INTO vhffs_mxdomain(domain, unix_user, boxes_path, max_popbox, catchall, owner_uid, owner_gid, object_id) VALUES(?, \'exim\', ?, 0, \'\', ?, ?, ?)';
-    my $domain_hash = Vhffs::Functions::hash_mxdomain($domain);
-    my $dbh = $main->get_db_object();
-    my $sth = $dbh->prepare($sql);
-    return undef unless($sth->execute($domain, $domain_hash, $user->get_uid(), $group->get_gid, $parent->get_oid));
+        die('Unable to create parent object') unless(defined $parent);
 
-    return get_by_mxdomain($main, $domain);
+        my $sql = 'INSERT INTO vhffs_mxdomain(domain, unix_user, boxes_path, max_popbox, catchall, owner_uid, owner_gid, object_id) VALUES(?, \'exim\', ?, 0, \'\', ?, ?, ?)';
+        my $domain_hash = Vhffs::Functions::hash_mxdomain($domain);
+        my $sth = $dbh->prepare($sql);
+        $sth->execute($domain, $domain_hash, $user->get_uid(), $group->get_gid, $parent->get_oid);
+
+        $dbh->commit;
+        $mail = get_by_mxdomain($main, $domain);
+    };
+
+    if($@) {
+        warn "Unable to create mail domain $domain: $@\n";
+        $dbh->rollback;
+    }
+
+    return $mail;
 }
 
 # Commit all changes of the current instance in the database

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mailing.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mailing.pm	2007-03-25 17:24:45 UTC (rev 528)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mailing.pm	2007-03-25 17:27:38 UTC (rev 529)
@@ -72,18 +72,35 @@
     return undef unless(Vhffs::Functions::check_domain_name($domain));
     $admin = $user->get_mail() unless(defined $admin);
 
+    my $ml;
+
     my $dbh = $main->get_db_object();
-    my $sql = 'SELECT mxdomain_id FROM vhffs_mxdomain WHERE domain = ? AND owner_gid = ?';
-    return undef unless($domain eq $main->get_config()->get_service("mailing")->{'default_domain'} ||
+    local $dbh->{RaiseError} = 1;
+    local $dbh->{PrintError} = 0;
+    $dbh->begin_work;
+
+    eval {
+        my $sql = 'SELECT mxdomain_id FROM vhffs_mxdomain WHERE domain = ? AND owner_gid = ?';
+        die('Mail domain not found') unless($domain eq $main->get_config()->get_service("mailing")->{'default_domain'} ||
                             $dbh->do($sql, undef, $domain, $group->get_gid) > 0);
 
-    my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_ML);
-    return undef unless(defined $parent);
+        my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_ML);
+        die('Unable to create parent object') unless(defined $parent);
 
-    $sql = 'INSERT INTO vhffs_ml(local_part, domain, prefix, owner_uid, owner_gid, object_id, admin, open_post, open_archive, open_sub, reply_to, moderated) VALUES(?, ?, ?, ?, ?, ?, ?, FALSE, FALSE, TRUE, TRUE, FALSE)';
-    my $sth = $dbh->prepare($sql);
-    return undef unless($sth->execute($local, $domain, $local, $user->get_uid, $group->get_gid, $parent->get_oid, $admin));
-    return get_by_mladdress($main, $local, $domain);
+        $sql = 'INSERT INTO vhffs_ml(local_part, domain, prefix, owner_uid, owner_gid, object_id, admin, open_post, open_archive, open_sub, reply_to, moderated) VALUES(?, ?, ?, ?, ?, ?, ?, FALSE, FALSE, TRUE, TRUE, FALSE)';
+        my $sth = $dbh->prepare($sql);
+        $sth->execute($local, $domain, $local, $user->get_uid, $group->get_gid, $parent->get_oid, $admin);
+        $dbh->commit;
+        $ml = get_by_mladdress($main, $local, $domain);
+    };
+
+    if($@) {
+        warn "Unable to create mailing list $local\@$domain: $@\n";
+        $dbh->rollback;
+    }
+
+    return $ml;
+
 }
 
 =pod

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mysql.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mysql.pm	2007-03-25 17:24:45 UTC (rev 528)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Mysql.pm	2007-03-25 17:27:38 UTC (rev 529)
@@ -97,16 +97,32 @@
     return undef unless(defined($user) && defined($group));
     return undef unless(check_dbname($dbname) && check_dbpass($dbpass) && check_dbuser($dbuser));
 
-    my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_MYSQL);
+    my $mysql;
+    my $dbh = $main->get_db_object();
+    local $dbh->{RaiseError} = 1;
+    local $dbh->{PrintError} = 0;
+    $dbh->begin_work;
 
-    return undef unless defined ($parent);
+    eval {
 
-    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));
+        my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_MYSQL);
+        die('Unable to create parent object') unless defined ($parent);
 
-    return get_by_dbname($main, $dbname);
+        my $sql = 'INSERT INTO vhffs_mysql(dbname, dbuser, dbpass, owner_uid, owner_gid, object_id) VALUES(?, ?, ?, ?, ?, ?)';
+        my $sth = $dbh->prepare($sql);
+        $sth->execute($dbname, $dbuser, $dbpass, $user->get_uid, $group->get_gid, $parent->get_oid);
+
+        $dbh->commit;
+        $mysql = get_by_dbname($main, $dbname);
+    };
+
+    if($@) {
+        warn "Unable to create MySQL db $dbname: $@\n";
+        $dbh->rollback;
+    }
+
+    return $mysql;
+
 }
 
 sub commit

Modified: branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Postgres.pm
===================================================================
--- branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Postgres.pm	2007-03-25 17:24:45 UTC (rev 528)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Postgres.pm	2007-03-25 17:27:38 UTC (rev 529)
@@ -128,17 +128,33 @@
     my ($main, $dbname, $dbuser, $dbpass, $description, $user, $group) = @_;
     return undef unless(defined($user) && defined($group));
     return undef unless(check_dbname($dbname) && check_dbpass($dbpass) && check_dbuser($dbuser));
-    my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_PGSQL);
 
-    return undef unless defined ($parent);
-
-    my $sql = 'INSERT INTO vhffs_pgsql(dbname, dbuser, dbpass, owner_uid, owner_gid, object_id) VALUES(?, ?, ?, ?, ?, ?)';
+    my $pg;
     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));
+    local $dbh->{RaiseError} = 1;
+    local $dbh->{PrintError} = 0;
+    $dbh->begin_work;
 
-    return get_by_dbname($main, $dbname);
+    eval {
 
+        my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_PGSQL);
+        die('Unable to create parent object') unless defined ($parent);
+
+        my $sql = 'INSERT INTO vhffs_pgsql(dbname, dbuser, dbpass, owner_uid, owner_gid, object_id) VALUES(?, ?, ?, ?, ?, ?)';
+        my $sth = $dbh->prepare($sql);
+        $sth->execute($dbname, $dbuser, $dbpass, $user->get_uid, $group->get_gid, $parent->get_oid);
+
+        $dbh->commit;
+        $pg = get_by_dbname($main, $dbname);
+    };
+
+    if($@) {
+        warn "Unable to create PostgreSQL database $dbname: $@\n";
+        $dbh->rollback;
+    }
+
+    return $pg;
+
 }
 
 sub commit

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-25 17:24:45 UTC (rev 528)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Repository.pm	2007-03-25 17:27:38 UTC (rev 529)
@@ -92,24 +92,36 @@
     return undef unless(defined($user) && defined($group));
     return undef unless(check_name($rname));
 
-    my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_REPOSITORY);
+    my $repo;
+    my $dbh = $main->get_db_object();
+    local $dbh->{RaiseError} = 1;
+    local $dbh->{PrintError} = 0;
+    $dbh->begin_work;
 
-    return undef unless(defined $parent);
+    eval {
+        my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_REPOSITORY);
+        die('Unable to create parent object') unless(defined $parent);
 
-    my $sql = 'INSERT INTO vhffs_repository(name, owner_uid, owner_gid, quota, quota_used, object_id) VALUES(?, ?, ?, ?, 0, ?)';
+        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);
+        #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);
 
-    my $sth = $dbh->prepare($sql);
+        $dbh->commit;
+        $repo =  get_by_reponame($main, $rname);
+    };
 
-    $sth->execute($rname, $user->get_uid, $group->get_gid, $quota, $parent->get_oid) or return undef;
+    if($@) {
+        warn "Unable to create repository $rname: $@\n";
+        $dbh->rollback;
+    }
 
-    return get_by_reponame($main, $rname);
+    return $repo;
 }
 
 =pod

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-25 17:24:45 UTC (rev 528)
+++ branches/vhffs_4.1/vhffs-api/src/Vhffs/Services/Svn.pm	2007-03-25 17:27:38 UTC (rev 529)
@@ -68,19 +68,32 @@
     return undef unless(defined($user) && defined($group));
     return undef unless(check_name($rname));
 
-    my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_SVN);
+    my $svn;
 
-    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();
+    local $dbh->{RaiseError} = 1;
+    local $dbh->{PrintError} = 0;
+    $dbh->begin_work;
 
-    my $sth = $dbh->prepare($sql);
+    eval {
+        my $parent = Vhffs::Object::create($main, $user->get_uid, $description, undef, Vhffs::Constants::TYPE_SVN);
 
-    $sth->execute($rname, $user->get_uid, $group->get_gid, $parent->get_oid) or return undef;
+        die('Unable to create parent object') unless(defined $parent);
 
-    return get_by_reponame($main, $rname);
+        my $sql = 'INSERT INTO vhffs_svn(reponame, owner_uid, owner_gid, public, object_id) VALUES(?, ?, ?, 1, ?)';
+        my $sth = $dbh->prepare($sql);
+        $sth->execute($rname, $user->get_uid, $group->get_gid, $parent->get_oid) or return undef;
+
+        $dbh->commit;
+        $svn = get_by_reponame($main, $rname);
+    };
+
+    if($@) {
+        warn "Unable to create svn repository $rname: $@\n";
+        $dbh->rollback;
+    }
+
+    return $svn;
 }
 
 sub get_by_reponame($$) {


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