Added option to add existing users to another group than new users.

Added documentation.
This commit is contained in:
Arjan Widlak 2011-01-19 12:38:19 +01:00
parent ed0398a2c0
commit 2a6e8f6193

View file

@ -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,10 +15,14 @@ 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,
'existingUsersGroupId=s' => \$existingUsersGroupId,
'state=s' => \$state,
'emailFile=s' => \$emailFile,
);
@ -40,17 +44,23 @@ 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 "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