This commit was generated by cvs2svn to compensate for changes in r3921,
[freeside.git] / FS / bin / freeside-reexport
1 #!/usr/bin/perl -w
2
3 use strict;
4 use vars qw($opt_s $opt_u $opt_p);
5 use Getopt::Std;
6 use FS::UID qw(adminsuidsetup);
7 use FS::Record qw(qsearch qsearchs);
8 use FS::part_export;
9 use FS::svc_acct;
10 use FS::cust_svc;
11
12 my $user = shift or die &usage;
13 adminsuidsetup $user;
14
15 my $export_x = shift or die &usage;
16 my @part_export;
17 if ( $export_x =~ /^(\d+)$/ ) {
18   @part_export = qsearchs('part_export', { exportnum=>$1 } )
19     or die "exportnum $export_x not found\n";
20 } else {
21   @part_export = qsearch('part_export', { exporttype=>$export_x } )
22     or die "no exports of type $export_x found\n";
23 }
24
25 getopts('s:u:p:');
26
27 my @svc_x = ();
28 if ( $opt_s ) {
29   my $cust_svc = qsearchs('cust_svc', { svcnum=>$opt_s } )
30     or die "svcnum $opt_s not found\n";
31   push @svc_x, $cust_svc->svc_x;
32 } elsif ( $opt_u ) {
33   my $svc_x = qsearchs('svc_acct', { username=>$opt_u } )
34     or die "username $opt_u not found\n";
35   push @svc_x, $svc_x;
36 } elsif ( $opt_p ) {
37   push @svc_x, map { $_->svc_x } qsearch('cust_svc', { svcpart=>$opt_p } );
38   die "no services with svcpart $opt_p found\n" unless @svc_x;
39 }
40
41 foreach my $part_export ( @part_export ) {
42   foreach my $svc_x ( @svc_x ) {
43     my $error = $part_export->export_insert($svc_x);
44     die $error if $error;
45   }
46 }
47
48
49 sub usage {
50   die "Usage:\n\n  freeside-reexport user exportnum|exporttype [ -s svcnum | -u username | -p svcpart ]\n";
51 }
52
53 =head1 NAME
54
55 freeside-reexport - Command line tool to re-trigger export jobs for existing services
56
57 =head1 SYNOPSIS
58
59   freeside-reexport user exportnum|exporttype [ -s svcnum | -u username | -p svcpart ]
60
61 =head1 DESCRIPTION
62
63   Re-queues the export job for the specified exportnum or exporttype(s) and
64   specified service (selected by svcnum or username).
65
66 =head1 SEE ALSO
67
68 L<freeside-sqlradius-reset>, L<FS::part_export>
69
70 =cut
71