bulk change GID, RT#86006
[freeside.git] / FS / bin / freeside-svc_acct-bulk_change
1 #!/usr/bin/perl -w
2
3 use strict;
4 use vars qw( $opt_p $opt_g );
5 use Getopt::Std;
6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw( qsearch ); #qsearchs );
8 use FS::cust_svc;
9
10 my $user = shift or die &usage;
11 adminsuidsetup $user;
12
13 getopts('p:g:');
14
15 my @svc_x = ();
16 if ( $opt_p ) {
17   push @svc_x, map { $_->svc_acct } qsearch('cust_svc', { svcpart=>$opt_p } );
18   die "no services with svcpart $opt_p found\n" unless @svc_x;
19 } else {
20   die &usage;
21 }
22
23 foreach my $svc_x ( @svc_x ) {
24   next if $opt_g && $svc_x->gid == $opt_g;
25   $svc_x->gid($opt_g) if $opt_g;
26   my $error = $svc_x->replace;
27   die $error if $error;
28 }
29
30 sub usage {
31   return "Usage:\n\n  freeside-svc_acct-bulk_change user -p svcpart -g gid\n";
32 }
33
34 =head1 NAME
35
36 freeside-svc_acct-bulk_change - Command line tool to make bulk changes to svc_acct (account) records
37
38 =head1 SYNOPSIS
39
40   freeside-svc_acct-bulk_change user -p svcpart -g gid
41
42 =head1 DESCRIPTION
43
44   For the servcies of the given svcpart, changes the GID as specified.
45
46   Note: Unless you are changing the GID to match an new, fixed value in the
47   service definition, you will need to enable the B<svc_acct-edit_gid>
48   configuration setting prior to running this script.
49
50 =head1 SEE ALSO
51
52 L<FS::svc_acct>
53
54 =cut
55
56 1;