165 lines
4.1 KiB
Perl
165 lines
4.1 KiB
Perl
#!/usr/bin/env perl
|
|
|
|
$|++; # disable output buffering
|
|
our ($webguiRoot, $configFile, $state, $emailFile, $groupId, $existingUsersGroupId );
|
|
|
|
BEGIN {
|
|
$webguiRoot = "..";
|
|
unshift (@INC, $webguiRoot."/lib");
|
|
}
|
|
|
|
use strict;
|
|
use Pod::Usage;
|
|
use Getopt::Long;
|
|
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,
|
|
);
|
|
|
|
my $session = start( $webguiRoot, $configFile );
|
|
|
|
open my $fh, "<$emailFile" || die "Cannot open email file [$emailFile]";
|
|
|
|
while ( my $email = <$fh> ) {
|
|
$email =~ s{\s}{}gxmsi;
|
|
|
|
if ( $email !~ m/^[^@]+\@[^@]+$/ ) {
|
|
print "Skipping email address [$email] because it looks wrong.\n";
|
|
next;
|
|
}
|
|
|
|
print "Processing email address [$email]...\n";
|
|
|
|
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";
|
|
|
|
finish($session);
|
|
|
|
#----------------------------------------------------------------------------
|
|
# Your sub here
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub start {
|
|
my $webguiRoot = shift;
|
|
my $configFile = shift;
|
|
my $session = WebGUI::Session->open($webguiRoot,$configFile);
|
|
$session->user({userId=>3});
|
|
|
|
## If your script is adding or changing content you need these lines, otherwise leave them commented
|
|
#
|
|
# my $versionTag = WebGUI::VersionTag->getWorking($session);
|
|
# $versionTag->set({name => 'Name Your Tag'});
|
|
#
|
|
##
|
|
|
|
return $session;
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub finish {
|
|
my $session = shift;
|
|
|
|
## If your script is adding or changing content you need these lines, otherwise leave them commented
|
|
#
|
|
# my $versionTag = WebGUI::VersionTag->getWorking($session);
|
|
# $versionTag->commit;
|
|
##
|
|
|
|
$session->var->end;
|
|
$session->close;
|
|
}
|
|
|
|
__END__
|
|
|
|
|
|
=head1 NAME
|
|
|
|
utility - A template for WebGUI utility scripts
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
utility --configFile config.conf ...
|
|
|
|
utility --help
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
This WebGUI utility script helps you...
|
|
|
|
=head1 ARGUMENTS
|
|
|
|
=head1 OPTIONS
|
|
|
|
=over
|
|
|
|
=item B<--configFile config.conf>
|
|
|
|
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
|
|
|
|
=item B<--man>
|
|
|
|
Shows this document
|
|
|
|
=back
|
|
|
|
=head1 AUTHOR
|
|
|
|
Copyright 2010-2011 United Knowledge B.V.
|
|
|
|
=cut
|
|
|
|
#vim:ft=perl
|