-
Notifications
You must be signed in to change notification settings - Fork 1
/
extendGroupMemberExpiration.pl
148 lines (103 loc) · 3.48 KB
/
extendGroupMemberExpiration.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com [email protected]
#-------------------------------------------------------------------
use strict;
use File::Basename ();
use File::Spec;
my $webguiRoot;
BEGIN {
#$webguiRoot = File::Spec->rel2abs(File::Spec->catdir(File::Basename::dirname(__FILE__), File::Spec->updir));
$webguiRoot = '/data/WebGUI';
unshift @INC, File::Spec->catdir($webguiRoot, 'lib');
}
$|++; # disable output buffering
our ($configFile, $help, $man);
use Pod::Usage;
use Getopt::Long;
use WebGUI::Session;
use WebGUI::Group;
# Get parameters here, including $help
GetOptions(
'F|configFile=s' => \$configFile,
'help' => \$help,
'man' => \$man,
);
pod2usage( verbose => 1 ) if $help;
pod2usage( verbose => 2 ) if $man;
pod2usage( msg => "Must specify a config file!" ) unless $configFile;
my $session = start( $webguiRoot, $configFile );
# Do your work here
for my $groupId ( @ARGV ) {
extendMemberExpiration( $groupId );
}
finish($session);
#----------------------------------------------------------------------------
# Your sub here
sub extendMemberExpiration {
my $groupId = shift ;
# increase expiration by 10 years ( 10*365*24*60*60 ) 315_360_000 seconds
my $group = WebGUI::Group->new($session,$groupId);
print "extending expiration date for ", scalar(()=$group->getUsers), " users in group '", $group->name, "' ... \n";
$session->db->write( q{
update groupings
set expireDate = expireDate + ?
where groupId = ?
}, [ 315_360_000, $groupId ] );
print " ... done\n";
}
#----------------------------------------------------------------------------
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<--help>
Shows a short summary and usage
=item B<--man>
Shows this document
=back
=head1 AUTHOR
Copyright 2001-2009 Plain Black Corporation.
=cut
#vim:ft=perl