[vhffs-dev] [1005] Deleting a group now delete all objects owned by the group, fixes bug #205

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


Revision: 1005
Author:   gradator
Date:     2007-10-18 16:19:01 +0000 (Thu, 18 Oct 2007)

Log Message:
-----------
Deleting a group now delete all objects owned by the group, fixes bug #205

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Group.pm
    trunk/vhffs-api/src/Vhffs/Object.pm
    trunk/vhffs-panel/group/delete.pl
    trunk/vhffs-robots/src/group_delete.pl
    trunk/vhffs-robots/src/mail_delete.pl


Modified: trunk/vhffs-api/src/Vhffs/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Group.pm	2007-10-18 06:15:43 UTC (rev 1004)
+++ trunk/vhffs-api/src/Vhffs/Group.pm	2007-10-18 16:19:01 UTC (rev 1005)
@@ -556,6 +556,26 @@
     return \@result;
 }
 
+
+# Get all objects of the group
+sub getall_objects
+{
+	my $self = shift;
+
+	my $query = 'SELECT object_id FROM vhffs_object WHERE owner_gid=?';
+	my $request = $self->get_main->get_db_object->prepare( $query ) or return -1;
+	return undef unless $request->execute( $self->get_gid );
+
+	my @objects;
+	my $rows = $request->fetchall_arrayref();
+
+	foreach (@$rows) {
+		push @objects , Vhffs::Object::get_by_oid( $self->get_main, @$_ );
+	}
+	return \@objects;
+}
+
+
 =pod
 
 =head2 get_by_gid

Modified: trunk/vhffs-api/src/Vhffs/Object.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Object.pm	2007-10-18 06:15:43 UTC (rev 1004)
+++ trunk/vhffs-api/src/Vhffs/Object.pm	2007-10-18 16:19:01 UTC (rev 1005)
@@ -612,6 +612,7 @@
 	return $result;
 }
 
+
 sub get_group
 {
     my $self = shift;

Modified: trunk/vhffs-panel/group/delete.pl
===================================================================
--- trunk/vhffs-panel/group/delete.pl	2007-10-18 06:15:43 UTC (rev 1004)
+++ trunk/vhffs-panel/group/delete.pl	2007-10-18 16:19:01 UTC (rev 1005)
@@ -74,10 +74,6 @@
 {
 	$message = gettext( 'This object will NOT be DELETED' );
 }
-elsif( $group->is_empty != 1 )
-{
-	$message = gettext( 'Error, your group is not empty. Please remove all objects from this group and try again' );
-}
 else
 {
 	$group->set_status( Vhffs::Constants::TO_DELETE );

Modified: trunk/vhffs-robots/src/group_delete.pl
===================================================================
--- trunk/vhffs-robots/src/group_delete.pl	2007-10-18 06:15:43 UTC (rev 1004)
+++ trunk/vhffs-robots/src/group_delete.pl	2007-10-18 16:19:01 UTC (rev 1005)
@@ -35,123 +35,33 @@
 use Vhffs::Main;
 use Vhffs::Group;
 use Vhffs::Constants;
-use Vhffs::Services::Cvs;
-use Vhffs::Services::DNS;
-use Vhffs::Services::Web;
-use Vhffs::Services::MailingList;
-use Vhffs::Services::Mail;
-use Vhffs::Services::Mysql;
-use Vhffs::Services::Pgsql;
-use Vhffs::Services::Svn;
 use Vhffs::Robots;
 
 
 my $vhffs = init Vhffs::Main;
 
-Vhffs::Robots::lock( $vhffs , "usergroup" );
+Vhffs::Robots::lock( $vhffs , 'usergroup' );
 
 my $groups = Vhffs::Group::getall( $vhffs , Vhffs::Constants::TO_DELETE );
-my $group;
-my $objects;
-my $object;
-my $ok;
-
-foreach $group ( @{$groups} )
+foreach my $group ( @{$groups} )
 {
-	Vhffs::Robots::vhffs_log( sprintf(  "Will try to delete group %s",  $group->get_groupname), $vhffs);
-	$ok = 1;
-
-    $objects = Vhffs::Services::Cvs::getall( $vhffs , undef , undef , $group );
-	$ok = 0 if( @$objects != 0 );
-    foreach $object ( @{$objects} )
-    {
-		Vhffs::Robots::vhffs_log( sprintf( "Remain cvs for group %s before delete" , $group->get_groupname ), $vhffs);
-        $object->set_status( Vhffs::Constants::TO_DELETE );
-		$object->commit;
-    }
-
-    $objects = Vhffs::Services::Svn::getall( $vhffs , undef , undef , $group );
-	$ok = 0 if( @$objects != 0);
-    foreach $object ( @{$objects} )
-    {
-		Vhffs::Robots::vhffs_log( sprintf( "Remain svn for group %s before delete" , $group->get_groupname ), $vhffs);
-        $object->set_status( Vhffs::Constants::TO_DELETE );
-		$object->commit;
-    }
-
-    $objects = Vhffs::Services::DNS::getall( $vhffs , undef , undef , $group );
-	$ok = 0 if( @$objects != 0);
-    foreach $object ( @{$objects} )
-    {
-		Vhffs::Robots::vhffs_log( sprintf( "Remain dns for group %s before delete" , $group->get_groupname ), $vhffs);
-        $object->set_status( Vhffs::Constants::TO_DELETE );
-		$object->commit;
-    }
-
-    $objects = Vhffs::Services::Mysql::getall( $vhffs , undef , undef , $group );
-	$ok = 0 if( @$objects != 0 );
-    foreach $object ( @{$objects} )
-    {
-		Vhffs::Robots::vhffs_log( sprintf( "Remain mysql for group %s before delete" , $group->get_groupname ), $vhffs);
-        $object->set_status( Vhffs::Constants::TO_DELETE );
-		$object->commit;
-    }
-
-    $objects = Vhffs::Services::Pgsql::getall( $vhffs , undef , undef , $group );
-	$ok = 0 if( @$objects != 0 );
-   foreach $object ( @{$objects} )
-   {
-		Vhffs::Robots::vhffs_log( sprintf( "Remain pgsql for group %s before delete" , $group->get_groupname ), $vhffs);
-        $object->set_status( Vhffs::Constants::TO_DELETE );
-		$object->commit;
-   }
-
-
-    $objects = Vhffs::Services::Web::getall( $vhffs , undef , undef , $group );
-	$ok = 0 if( @$objects != 0 );
-   foreach $object ( @{$objects} )
-   {
-		Vhffs::Robots::vhffs_log( sprintf( "Remain website for group %s before delete" , $group->get_groupname ), $vhffs);
-        $object->set_status( Vhffs::Constants::TO_DELETE );
-		$object->commit;
-   }
-    
-	$objects = Vhffs::Services::MailingList::getall( $vhffs , undef , undef , $group );
-	$ok = 0 if( @$objects != 0);
-   foreach $object ( @{$objects} )
-   {
-		Vhffs::Robots::vhffs_log( sprintf( "Remain list for group %s before delete" , $group->get_groupname ), $vhffs);
-        $object->set_status( Vhffs::Constants::TO_DELETE );
-		$object->commit;
-   }
-
-
-	$objects = Vhffs::Services::Mail::getall( $vhffs , undef , undef , $group );
-	$ok = 0 if( @$objects != 0 );
-   foreach $object ( @{$objects} )
-   {
-		Vhffs::Robots::vhffs_log( sprintf( "Remain mail for group %s before delete" , $group->get_groupname ), $vhffs);
-        $object->set_status( Vhffs::Constants::TO_DELETE );
-		if( $object->commit < 0 )
+	if( $group->is_empty )  {
+		Vhffs::Robots::vhffs_log( sprintf( 'Deleted group %s' , $group->get_groupname ), $vhffs);
+		Vhffs::Robots::Group::delete( $vhffs , $group );
+	}
+	else {
+		foreach my $object ( @{$group->getall_objects} )
 		{
-			Vhffs::Robots::vhffs_log( "Error in delete group" , $vhffs);
+			if( $group->get_oid != $object->get_oid  &&  $object->get_status != Vhffs::Constants::TO_DELETE)  {
+				$object->set_status( Vhffs::Constants::TO_DELETE );
+				$object->commit;
+			}
 		}
-   }
 
-
-	if( $ok == 1 )
-	{
-		Vhffs::Robots::vhffs_log( sprintf( "Delete group %s" , $group->get_groupname ), $vhffs);
-		Vhffs::Robots::Group::delete( $vhffs , $group );
+		Vhffs::Robots::vhffs_log( sprintf( 'Cannot delete group %s, items are remaining, delete status have been set to those items' , $group->get_groupname ), $vhffs);
 	}
-	else
-	{
-		Vhffs::Robots::vhffs_log( sprintf( "Cannot elete group %s, items remains" , $group->get_groupname ), $vhffs);
-	}
-
 }
 
-Vhffs::Robots::unlock( $vhffs , "usergroup" );
+Vhffs::Robots::unlock( $vhffs , 'usergroup' );
 
 exit( 0 );
-

Modified: trunk/vhffs-robots/src/mail_delete.pl
===================================================================
--- trunk/vhffs-robots/src/mail_delete.pl	2007-10-18 06:15:43 UTC (rev 1004)
+++ trunk/vhffs-robots/src/mail_delete.pl	2007-10-18 16:19:01 UTC (rev 1005)
@@ -65,10 +65,9 @@
 		Vhffs::Robots::vhffs_log( sprintf( "Delete mail domain %s" , $mail->get_domain ) , $vhffs);
 		if( $mail->get_dir && -d $mail->get_dir && chdir( $mail->get_dir ) )  {
 			my $cmd = 'rm -r '.$mail->get_dir;
-			print $cmd."\n";
-			#system( $cmd );
+			system( $cmd );
 		}
-		#$mail->delete;
+		$mail->delete;
 	}
 }
 


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