From 2a6e8f6193dbc385e53df9d0fc5ffc8e4a4f2152 Mon Sep 17 00:00:00 2001 From: Arjan Widlak Date: Wed, 19 Jan 2011 12:38:19 +0100 Subject: [PATCH] Added option to add existing users to another group than new users. Added documentation. --- sbin/importSpecialState.pl | 46 +++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/sbin/importSpecialState.pl b/sbin/importSpecialState.pl index 91a0158..ff20fb1 100644 --- a/sbin/importSpecialState.pl +++ b/sbin/importSpecialState.pl @@ -1,7 +1,7 @@ #!/usr/bin/env perl $|++; # disable output buffering -our ($webguiRoot, $configFile, $state, $emailFile, $groupId ); +our ($webguiRoot, $configFile, $state, $emailFile, $groupId, $existingUsersGroupId ); BEGIN { $webguiRoot = ".."; @@ -15,12 +15,16 @@ use WebGUI::Session; use WebGUI::User; use WebGUI::User::SpecialState; +# Set default value +$existingUsersGroupId = ''; + # Get parameters here, including $help GetOptions( - 'configFile=s' => \$configFile, - 'groupId=s' => \$groupId, - 'state=s' => \$state, - 'emailFile=s' => \$emailFile, + 'configFile=s' => \$configFile, + 'groupId=s' => \$groupId, + 'existingUsersGroupId=s' => \$existingUsersGroupId, + 'state=s' => \$state, + 'emailFile=s' => \$emailFile, ); my $session = start( $webguiRoot, $configFile ); @@ -40,18 +44,24 @@ while ( my $email = <$fh> ) { my $user = WebGUI::User->newByEmail( $session, $email ); if ( $user ) { print "\tEmail already has account. Skipping.\n"; + if ( $existingUsersGroupId ) { + print "\tAdding user to group $existingUsersGroupId\n"; + $user->addToGroups( [ $existingUsersGroupId ] ); + } + else { + print "\tAdding user to group $groupId\n"; + $user->addToGroups( [ $groupId ] ); + } } else { print "\tEmail has no account, creating special state $state.\n"; $user = WebGUI::User::SpecialState->create( $session ); $user->update( { email => $email } ); $user->addSpecialState( $state ); + print "\tAdding user to group $groupId\n"; + $user->addToGroups( [ $groupId ] ); } - print "\tAdding user to group $groupId\n"; - - $user->addToGroups( [ $groupId ] ); - } print "Done\n\n"; @@ -120,6 +130,22 @@ The WebGUI config file to use. Only the file name needs to be specified, since it will be looked up inside WebGUI's configuration directory. This parameter is required. +=item B<--groupId> + +Add users to this group. If no existingUsersGroupId is given, all users, both new and existing users, are added to this group. If the --existingUsersGroupId is given, new users are added to this group, existing users are added to the existingUsersGroupId. + +=item B<--existingUsersGroupId> + +Add existing users to this group. + +=item B<--state> + +Set the so called specialState for this user. For all users disabeled accounts are created. SpecialState accounts can be transformed into regular accounts using the webgui_registration content handler. The special states are crm or Subscriber, for a user added via the crm or a newsletter subscription respectively. + +=item B<--emailFile> + +A text file with an emailadress on every line. + =item B<--help> Shows a short summary and usage @@ -132,7 +158,7 @@ Shows this document =head1 AUTHOR -Copyright 2001-2009 Plain Black Corporation. +Copyright 2010-2011 United Knowledge B.V. =cut