[vhffs-dev] [2058] Reworking group robots (however group<> user methods were kept in the dark and need a rework^Wfull rewrite)

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


Revision: 2058
Author:   gradator
Date:     2012-02-25 19:48:38 +0100 (Sat, 25 Feb 2012)
Log Message:
-----------
Reworking group robots (however group<>user methods were kept in the dark and need a rework^Wfull rewrite)

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Group.pm
    trunk/vhffs-api/src/Vhffs/Robots/Group.pm
    trunk/vhffs-robots/Makefile.am

Added Paths:
-----------
    trunk/vhffs-robots/src/group.pl

Removed Paths:
-------------
    trunk/vhffs-robots/src/group_create.pl
    trunk/vhffs-robots/src/group_delete.pl

Modified: trunk/vhffs-api/src/Vhffs/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Group.pm	2012-02-25 17:48:14 UTC (rev 2057)
+++ trunk/vhffs-api/src/Vhffs/Group.pm	2012-02-25 18:48:38 UTC (rev 2058)
@@ -605,6 +605,8 @@
 
 Returns an array of all objects C<Vhffs::Object> owned by this group.
 
+Caution: it also returns the group itself.
+
 =cut
 sub getall_objects {
 	my $self = shift;

Modified: trunk/vhffs-api/src/Vhffs/Robots/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Group.pm	2012-02-25 17:48:14 UTC (rev 2057)
+++ trunk/vhffs-api/src/Vhffs/Robots/Group.pm	2012-02-25 18:48:38 UTC (rev 2058)
@@ -42,63 +42,102 @@
 use Vhffs::Constants;
 use Vhffs::Robots;
 
-sub create_groupdir
-{
-	my $main = shift;
+sub create {
 	my $group = shift;
+	return undef unless defined $group and $group->get_status == Vhffs::Constants::WAITING_FOR_CREATION;
 
-	return undef unless ( defined $main && defined $group );
+	my $vhffs = $group->get_main;
+	my $dir = $group->get_dir;
 
-	my $user = Vhffs::User::get_by_uid( $main , $group->get_owner_uid );
-	my $dir = $group->get_dir;
-	$group->add_history('Ok, Robots is going to create the directory');
-	File::Path::make_path( $dir, { error => \my $errors } );
-	unless( @$errors ) {
-		chown( $group->get_owner_uid , $group->get_gid , $dir );
-		chmod( 02770 , $dir );
-		$group->add_history('Ok, Robots finished the creation of the directory');
-		add_user( $user , $group , $main );
-		$group->set_status( Vhffs::Constants::ACTIVATED );
+	if( -e $dir ) {
+		$group->set_status( Vhffs::Constants::CREATION_ERROR );
 		$group->commit;
+		Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while creating group '.$group->get_groupname.' to the filesystem' );
+		return undef;
 	}
-	else {
-		$group->add_history( 'cannot create the group directory' );
-#		$group->set_status( Vhffs::Constants::CREATION_ERROR );
-#		$group->commit;
+
+	File::Path::make_path( $dir, { error => \my $errors });
+	if(@$errors) {
+		$group->set_status( Vhffs::Constants::CREATION_ERROR );
+		$group->commit;
+		Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while creating group '.$group->get_groupname.' to the filesystem: '.join(', ', @$errors) );
 		return undef;
 	}
 
-	return $dir;
+	chown $group->get_owner_uid, $group->get_gid, $dir;
+	chmod 02770, $dir;
+
+	# TODO: Rework that
+	add_user( $group->get_owner, $group, $vhffs );
+
+	Vhffs::Robots::vhffs_log( $vhffs, 'Created group '.$group->get_groupname );
+	$group->set_status( Vhffs::Constants::ACTIVATED );	
+	$group->commit;
 }
 
-
-sub delete_groupdir
-{
-	my $main = shift;
+sub delete {
 	my $group = shift;
+	return undef unless defined $group and $group->get_status == Vhffs::Constants::WAITING_FOR_DELETION;
 
-	return undef unless ( defined $main && defined $group );
-
+	my $vhffs = $group->get_main;
 	my $dir = $group->get_dir;
-	if( -d $dir )
-	{
-		Vhffs::Robots::archive_targz( $group, $dir );
 
-		File::Path::remove_tree( $dir, { error => \my $errors });
-		# Group directories are hashed on two levels, so we've potentially two empty directories to delete
-		$dir = File::Basename::dirname($dir);
-		rmdir $dir;
-		$dir = File::Basename::dirname($dir);
-		rmdir $dir;
+	Vhffs::Robots::archive_targz( $group, $dir );
 
-		if(@$errors) {
-			Vhffs::Robots::vhffs_log( $main, sprintf( 'Something went wrong during %s group deletion: %s', $group->get_groupname, join(', ', @$errors) ) );
+	# Remove users from group
+	# TODO: Rework that
+	foreach( @{$group->get_users} ) {
+		del_user( $_, $group, $vhffs );
+	}
+
+	# Recursively delete group objects, do not delete the group until this is done
+	unless( $group->is_empty )  {
+		foreach( @{$group->getall_objects} ) {
+			next if $group->get_oid == $_->get_oid;
+			next if $_->get_status == Vhffs::Constants::WAITING_FOR_DELETION;
+			$_->set_status( Vhffs::Constants::WAITING_FOR_DELETION );
+			$_->commit;
 		}
+
+		Vhffs::Robots::vhffs_log( $vhffs, 'Cannot delete group '.$group->get_groupname.' because it is not empty yet, delete status have been set to group items' );
+		return 1;
 	}
-	return 0;
+
+	File::Path::remove_tree( $dir, { error => \my $errors });
+	# Group directories are hashed on two levels, so we've potentially two empty directories to delete
+	my $parent = File::Basename::dirname($dir);
+	rmdir $parent;
+	$parent = File::Basename::dirname($parent);
+	rmdir $parent;
+
+	if(@$errors) {
+		$group->set_status( Vhffs::Constants::DELETION_ERROR );
+		$group->commit;
+		Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while removing group '.$group->get_groupname.' from the filesystem: '.join(', ', @$errors) );
+		return undef;
+	}
+
+	if( $group->delete ) {
+		Vhffs::Robots::vhffs_log( $vhffs, 'Deleted group '.$group->get_groupname );
+	} else {
+		$group->set_status( Vhffs::Constants::DELETION_ERROR );
+		$group->commit;
+		Vhffs::Robots::vhffs_log( $vhffs, 'An error occured while deleting group '.$group->get_groupname.' object' );
+		return undef;
+	}
+
+	return 1;
 }
 
+sub modify {
+	my $user = shift;
+	return undef unless defined $user and $user->get_status == Vhffs::Constants::WAITING_FOR_MODIFICATION;
+	$user->set_status( Vhffs::Constants::ACTIVATED );
+	$user->commit;
+}
 
+#TODO: Rework everything below this line
+
 =pod
 
 =head2 getall_user_group_to_delete
@@ -192,21 +231,4 @@
 	return 1;
 }
 
-sub delete
-{
-	my $vhffs = shift;
-	my $group = shift;
-	my $users = $group->get_users;
-	my $user;
-	foreach $user ( @{$users} )
-	{
-		del_user( $user , $group , $vhffs );
-	}
-
-	delete_groupdir( $vhffs , $group );
-	$group->delete;
-}
-
-
 1;
-

Modified: trunk/vhffs-robots/Makefile.am
===================================================================
--- trunk/vhffs-robots/Makefile.am	2012-02-25 17:48:14 UTC (rev 2057)
+++ trunk/vhffs-robots/Makefile.am	2012-02-25 18:48:38 UTC (rev 2058)
@@ -22,8 +22,7 @@
 
 dist_bots_SCRIPTS = \
 	src/dns.pl \
-	src/group_create.pl \
-	src/group_delete.pl \
+	src/group.pl \
 	src/group_quota.pl \
 	src/listengine_publicarchives.pl \
 	src/mail_create.pl \

Copied: trunk/vhffs-robots/src/group.pl (from rev 2056, trunk/vhffs-robots/src/group_create.pl)
===================================================================
--- trunk/vhffs-robots/src/group.pl	                        (rev 0)
+++ trunk/vhffs-robots/src/group.pl	2012-02-25 18:48:38 UTC (rev 2058)
@@ -0,0 +1,60 @@
+#!%PERL%
+
+# Copyright (c) vhffs project and its contributors
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without 
+# modification, are permitted provided that the following conditions 
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright 
+#   notice, this list of conditions and the following disclaimer.
+#2. Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in 
+#   the documentation and/or other materials provided with the 
+#   distribution.
+#3. Neither the name of vhffs nor the names of its contributors 
+#   may be used to endorse or promote products derived from this 
+#   software without specific prior written permission.
+#
+#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
+#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
+#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
+#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
+#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
+#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
+#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
+#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
+#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
+# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
+# POSSIBILITY OF SUCH DAMAGE.
+
+use strict;
+use utf8;
+
+use lib '%VHFFS_LIB_DIR%';
+use Vhffs::Robots::Group;
+
+my $vhffs = init Vhffs::Main;
+exit 1 unless defined $vhffs;
+
+Vhffs::Robots::lock( $vhffs, 'group' );
+
+my $repos = Vhffs::Group::getall( $vhffs, Vhffs::Constants::WAITING_FOR_CREATION );
+foreach ( @{$repos} ) {
+	Vhffs::Robots::Group::create( $_ );
+}
+
+$repos = Vhffs::Group::getall( $vhffs, Vhffs::Constants::WAITING_FOR_DELETION );
+foreach ( @{$repos} ) {
+	Vhffs::Robots::Group::delete( $_ );
+}
+
+$repos = Vhffs::Group::getall( $vhffs, Vhffs::Constants::WAITING_FOR_MODIFICATION );
+foreach ( @{$repos} ) {
+	Vhffs::Robots::Group::modify( $_ );
+}
+
+Vhffs::Robots::unlock( $vhffs, 'group' );
+exit 0;

Deleted: trunk/vhffs-robots/src/group_create.pl
===================================================================
--- trunk/vhffs-robots/src/group_create.pl	2012-02-25 17:48:14 UTC (rev 2057)
+++ trunk/vhffs-robots/src/group_create.pl	2012-02-25 18:48:38 UTC (rev 2058)
@@ -1,66 +0,0 @@
-#!%PERL%
-
-# Copyright (c) vhffs project and its contributors
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without 
-# modification, are permitted provided that the following conditions 
-# are met:
-#
-# 1. Redistributions of source code must retain the above copyright 
-#   notice, this list of conditions and the following disclaimer.
-#2. Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in 
-#   the documentation and/or other materials provided with the 
-#   distribution.
-#3. Neither the name of vhffs nor the names of its contributors 
-#   may be used to endorse or promote products derived from this 
-#   software without specific prior written permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
-#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
-#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
-#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
-#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
-#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
-#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
-# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
-# POSSIBILITY OF SUCH DAMAGE.
-
-use strict;
-use utf8;
-
-use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Main;
-use Vhffs::Group;
-use Vhffs::Robots;
-use Vhffs::Robots::Group;
-
-
-my $vhffs = init Vhffs::Main;
-
-Vhffs::Robots::lock( $vhffs , "usergroup" );
-
-my $groups = Vhffs::Group::getall( $vhffs , Vhffs::Constants::WAITING_FOR_CREATION );
-
-my $group;
-
-foreach $group ( @{$groups} )
-{
-	if( defined Vhffs::Robots::Group::create_groupdir( $vhffs , $group ) )
-	{
-		Vhffs::Robots::vhffs_log( $vhffs, sprintf( "create group %s " , $group->get_groupname ) );
-	}
-	else
-	{
-		Vhffs::Robots::vhffs_log( $vhffs, sprintf( "cannot create group %s " , $group->get_groupname ) );
-		print sprintf("robots::group_create: Cannot create group %s\n" , $group->get_groupname );
-	}
-}
-
-Vhffs::Robots::unlock( $vhffs , "usergroup" );
-
-exit 0;

Deleted: trunk/vhffs-robots/src/group_delete.pl
===================================================================
--- trunk/vhffs-robots/src/group_delete.pl	2012-02-25 17:48:14 UTC (rev 2057)
+++ trunk/vhffs-robots/src/group_delete.pl	2012-02-25 18:48:38 UTC (rev 2058)
@@ -1,69 +0,0 @@
-#!%PERL%
-# Copyright (c) vhffs project and its contributors
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without 
-# modification, are permitted provided that the following conditions 
-# are met:
-#
-# 1. Redistributions of source code must retain the above copyright 
-#   notice, this list of conditions and the following disclaimer.
-#2. Redistributions in binary form must reproduce the above copyright
-#   notice, this list of conditions and the following disclaimer in 
-#   the documentation and/or other materials provided with the 
-#   distribution.
-#3. Neither the name of vhffs nor the names of its contributors 
-#   may be used to endorse or promote products derived from this 
-#   software without specific prior written permission.
-#
-#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
-#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
-#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
-#FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
-#COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 
-#INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 
-#BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
-#LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
-#CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 
-# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
-# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
-# POSSIBILITY OF SUCH DAMAGE.
-
-use strict;
-use utf8;
-
-use lib '%VHFFS_LIB_DIR%';
-use Vhffs::Robots::Group;
-use Vhffs::Main;
-use Vhffs::Group;
-use Vhffs::Constants;
-use Vhffs::Robots;
-
-
-my $vhffs = init Vhffs::Main;
-
-Vhffs::Robots::lock( $vhffs , 'usergroup' );
-
-my $groups = Vhffs::Group::getall( $vhffs , Vhffs::Constants::WAITING_FOR_DELETION );
-foreach my $group ( @{$groups} )
-{
-	if( $group->is_empty )  {
-		Vhffs::Robots::vhffs_log( $vhffs, sprintf( 'Deleted group %s' , $group->get_groupname ));
-		Vhffs::Robots::Group::delete( $vhffs , $group );
-	}
-	else {
-		foreach my $object ( @{$group->getall_objects} )
-		{
-			if( $group->get_oid != $object->get_oid  &&  $object->get_status != Vhffs::Constants::WAITING_FOR_DELETION)  {
-				$object->set_status( Vhffs::Constants::WAITING_FOR_DELETION );
-				$object->commit;
-			}
-		}
-
-		Vhffs::Robots::vhffs_log( $vhffs, sprintf( 'Cannot delete group %s, items are remaining, delete status have been set to those items' , $group->get_groupname ));
-	}
-}
-
-Vhffs::Robots::unlock( $vhffs , 'usergroup' );
-
-exit( 0 );


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