diff options
author | Mark Wells <mark@freeside.biz> | 2015-01-13 22:12:25 -0800 |
---|---|---|
committer | Mark Wells <mark@freeside.biz> | 2015-01-13 22:12:33 -0800 |
commit | 6f26e3a7b5b0411601553fa38d1bfbe59fb02bad (patch) | |
tree | 9fd6129ff2daf2fceac335f087708c058777cce5 /bin | |
parent | 3737dfd3e904c8b309ab6f773205d1bdc1ab2d5c (diff) |
voip.ms CDR import, #31835
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/cdr-voip_ms.import | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/bin/cdr-voip_ms.import b/bin/cdr-voip_ms.import new file mode 100755 index 000000000..1b4805d0c --- /dev/null +++ b/bin/cdr-voip_ms.import @@ -0,0 +1,70 @@ +#!/usr/bin/perl + +use strict; +use FS::Misc::Getopt; +use FS::cdr_batch; +use FS::part_export; +use FS::Record qw(qsearch qsearchs dbh); +use Date::Format 'time2str'; + +### +# parse command line +### + +our %opt; +getopts(''); + +$FS::UID::AutoCommit = 0; + +my @exports = qsearch('part_export', { exporttype => 'voip_ms' }); +if (!@exports) { + die "There are no voip.ms exports configured.\n"; +} + +foreach my $part_export (@exports) { + debug "Account #".$part_export->option('account'); + + if (!$opt{start}) { + # find the most recently downloaded batch + my $exportnum = $part_export->exportnum; + my $most_recent = qsearchs({ + 'table' => 'cdr_batch', + 'hashref' => { 'cdrbatch' => {op=>'like', + value=>'voip_ms-' . $exportnum . '-%'} + }, + 'order_by' => 'ORDER BY _date DESC LIMIT 1', + }); + if ( $most_recent ) { + $most_recent->cdrbatch =~ /-(\d+)$/; # extract the end timestamp + $opt{start} = $1; + debug "Downloading records since most recent batch: ". + time2str('%Y-%m-%d', $opt{start}); + } else { + $opt{start} = 0; + debug "Downloading records since time = zero."; + } + } + + $opt{end} ||= time; + + my $error_or_batch = $part_export->import_cdrs( $opt{start}, $opt{end} ); + if ( ref $error_or_batch ) { + debug "Created batch #".$error_or_batch->cdrbatchnum; + dbh->commit; + } elsif ( $error_or_batch ) { + warn $error_or_batch; + dbh->rollback; + } else { + debug "No CDRs found." + } +} + +sub usage { + "Usage: \n cdr-voip_ms.import [ options ] user + Options: + -v: be verbose + -s date: start date (defaults to the most recent batch date) + -e date: end date +"; +} + |