From d0077bdceccf156ee79789ca5656afd017a9ac82 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Mon, 20 Jun 2011 18:26:39 -0500 Subject: [PATCH] allow specific expires dates for groups in userImport.pl --- docs/changelog/7.x.x.txt | 1 + sbin/userImport.pl | 29 +++++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index b735c4bc4..38560bcc3 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,5 +1,6 @@ 7.10.19 - Added ability to pass caller assetId to RenderThingMacro + - Allow specific expirations for groups in userImport.pl 7.10.18 - fixed #12138: Version tag gets create by entering and direct leaving diff --git a/sbin/userImport.pl b/sbin/userImport.pl index ccad6badc..de494dde4 100755 --- a/sbin/userImport.pl +++ b/sbin/userImport.pl @@ -82,7 +82,7 @@ if (!($^O =~ /^Win/i) && $> != 0 && !$override) { print "Starting up..." unless ($quiet); my $session = WebGUI::Session->open($webguiRoot,$configFile); $session->user({userId=>3}); -open(FILE,"<".$usersFile); +open(FILE,"<".$usersFile) || die("Could not open $usersFile for reading: $!"); print "OK\n" unless ($quiet); my $lineNumber = 0; @@ -90,6 +90,7 @@ my @field; my @profileFields = $session->db->buildArray("select fieldName from userProfileField"); while(my $line = ) { $lineNumber++; + chomp $line; next if $line eq ''; @@ -188,7 +189,25 @@ while(my $line = ) { } if ($user{groups}) { my @groups = split(/,/,$user{groups}); - $u->addToGroups(\@groups,$user{expireOffset}); + # Groups that have : in them have unique expiration dates + $u->addToGroups([grep { !/:/ } @groups],$user{expireOffset}); + for my $groupDef ( grep { /:/ } @groups ) { + my ( $groupId, $expireDate ) = split /:/, $groupDef, 2; + + # Calculate expiration offset + my $dtparse = DateTime::Format::Strptime->new( + pattern => '%F %T', + on_error => 'croak', + ); + + eval { + my $expireOffset = $dtparse->parse_datetime( $expireDate )->epoch - time; + $u->addToGroups( [$groupId], $expireOffset ); + }; + if ( $@ ) { + print "Could not add user $user{username} to group $groupId: $@"; + } + } } } } @@ -354,6 +373,12 @@ Specify a comma separated list of WebGUI Group Ids that each loaded user will be set to. It can be overridden in the import file for specific users. +You can specify a unique expiration date for a group by adding it +after the group ID, seperated by a colon. The date/time should be in +"YYYY-MM-DD HH:NN:SS" format. + + groupId:2000-01-01 01:00:00,groupId2:2001-01-02 02:00:00 + =item B<--ldapUrl uri> Specify the URI used to connect to the LDAP server for authentication.