work around missing id, RT#83146
[freeside.git] / FS / bin / freeside-reset-fixed
1 #!/usr/bin/perl -w
2
3 use strict;
4 use vars qw($opt_p $opt_s $opt_r);
5 use Getopt::Std;
6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearch qsearchs);
8 use FS::cust_svc;
9 use FS::svc_Common;
10
11 getopts('p:s:r');
12
13 my $user = shift or die &usage;
14 adminsuidsetup $user;
15
16 die &usage
17   if ($opt_p && $opt_s);
18
19 $FS::Record::nowarn_identical = 1;
20 $FS::svc_Common::noexport_hack = 1
21   unless $opt_r;
22
23 my @svc_x = ();
24 if ( $opt_s ) {
25   $opt_s =~ /^(\d+)$/ or die "invalid svcnum";
26   my $cust_svc = qsearchs('cust_svc', { svcnum => $1 } )
27     or die "svcnum $opt_s not found\n";
28   push @svc_x, $cust_svc->svc_x;
29 } elsif ( $opt_p ) {
30   $opt_p =~ /^(\d+)$/ or die "invalid svcpart";
31   push @svc_x, map { $_->svc_x } qsearch('cust_svc', { svcpart => $1 } );
32   die "no services with svcpart $opt_p found\n" unless @svc_x;
33 } else {
34   push @svc_x, map { $_->svc_x } qsearch('cust_svc', {} );
35   die "no services found\n" unless @svc_x;
36 }
37
38 foreach my $svc_x ( @svc_x ) {
39   my $result = $svc_x->setfixed;
40   die $result unless ref($result);
41   my $error = $svc_x->replace
42     if $svc_x->modified;     
43   die $error if $error;
44 }
45
46
47 sub usage {
48   die "Usage:\n\n  freeside-reset-fixed user [ -s svcnum | -p svcpart ] [ -r ]\n";
49 }
50
51 =head1 NAME
52
53 freeside-reset-fixed - Command line tool to set the fixed columns for existing services
54
55 =head1 SYNOPSIS
56
57   freeside-reset-fixed user [ -s svcnum | -p svcpart ] [ -r ]
58
59 =head1 DESCRIPTION
60
61   Resets the fixed columns for the specified service part or service number.
62   Re-exports the service if -r is specified.
63
64 =head1 SEE ALSO
65
66 L<freeside-reexport>, L<FS::part_svc>
67
68 =cut
69