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 #!/usr/bin/env perl
$|++; # disable output buffering $|++; # disable output buffering
our ($webguiRoot, $configFile, $state, $emailFile, $groupId ); our ($webguiRoot, $configFile, $state, $emailFile, $groupId, $existingUsersGroupId );
BEGIN { BEGIN {
$webguiRoot = ".."; $webguiRoot = "..";
@ -15,12 +15,16 @@ use WebGUI::Session;
use WebGUI::User; use WebGUI::User;
use WebGUI::User::SpecialState; use WebGUI::User::SpecialState;
# Set default value
$existingUsersGroupId = '';
# Get parameters here, including $help # Get parameters here, including $help
GetOptions( GetOptions(
'configFile=s' => \$configFile, 'configFile=s' => \$configFile,
'groupId=s' => \$groupId, 'groupId=s' => \$groupId,
'state=s' => \$state, 'existingUsersGroupId=s' => \$existingUsersGroupId,
'emailFile=s' => \$emailFile, 'state=s' => \$state,
'emailFile=s' => \$emailFile,
); );
my $session = start( $webguiRoot, $configFile ); my $session = start( $webguiRoot, $configFile );
@ -40,18 +44,24 @@ while ( my $email = <$fh> ) {
my $user = WebGUI::User->newByEmail( $session, $email ); my $user = WebGUI::User->newByEmail( $session, $email );
if ( $user ) { if ( $user ) {
print "\tEmail already has account. Skipping.\n"; 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 { else {
print "\tEmail has no account, creating special state $state.\n"; print "\tEmail has no account, creating special state $state.\n";
$user = WebGUI::User::SpecialState->create( $session ); $user = WebGUI::User::SpecialState->create( $session );
$user->update( { email => $email } ); $user->update( { email => $email } );
$user->addSpecialState( $state ); $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"; 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. since it will be looked up inside WebGUI's configuration directory.
This parameter is required. 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> =item B<--help>
Shows a short summary and usage Shows a short summary and usage
@ -132,7 +158,7 @@ Shows this document
=head1 AUTHOR =head1 AUTHOR
Copyright 2001-2009 Plain Black Corporation. Copyright 2010-2011 United Knowledge B.V.
=cut =cut