[freeside-commits] branch FREESIDE_4_BRANCH updated. 530cf58617cbab6cb8b081c4031f0f528530fd0b
Ivan
ivan at 420.am
Sat Mar 18 18:14:34 PDT 2017
The branch, FREESIDE_4_BRANCH has been updated
via 530cf58617cbab6cb8b081c4031f0f528530fd0b (commit)
from 3e50b720f8c35210b0e55864b3cd83d1595eeff6 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 530cf58617cbab6cb8b081c4031f0f528530fd0b
Author: Ivan Kohler <ivan at freeside.biz>
Date: Sat Mar 18 18:14:33 2017 -0700
asterisk v12 CDRs, RT#71704
diff --git a/FS/bin/freeside-cdr-asterisk_sql b/FS/bin/freeside-cdr-asterisk_sql
index 4b5bcc8..a266f14 100755
--- a/FS/bin/freeside-cdr-asterisk_sql
+++ b/FS/bin/freeside-cdr-asterisk_sql
@@ -12,7 +12,7 @@ use Getopt::Std;
$DEBUG = 0;
my %opt;
-getopts('e:H:U:P:D:T:', \%opt);
+getopts('e:H:U:P:D:T:V:', \%opt);
my $user = shift or die &usage;
my $engine = $opt{e} || 'mysql';
@@ -42,10 +42,17 @@ if ( $engine =~ /^mysql/ ) {
}
}
-my @cols = (qw(
- calldate clid src dst dcontext channel lastapp lastdata duration
+my @cols = ();
+if ( $opt{V} > 12 ) {
+ push @cols, qw( start answer end );
+} else {
+ push @cols, qw( calldate );
+}
+
+push @cols, qw(
+ clid src dst dcontext channel lastapp lastdata duration
billsec disposition amaflags accountcode userfield
-));
+);
# check for existence of uniqueid
if ( $engine =~ /^mysql/ ) {
@@ -70,19 +77,29 @@ my $cdr_batch = new FS::cdr_batch({
my $error = $cdr_batch->insert;
die $error if $error;
my $cdrbatchnum = $cdr_batch->cdrbatchnum;
+
my $imports = 0;
my $updates = 0;
-my $row;
-while ( $row = $sth->fetchrow_hashref ) {
+while ( my $row = $sth->fetchrow_hashref ) {
+
my $cdr = FS::cdr->new($row);
- $cdr->startdate(str2time($cdr->calldate));
+
+ if ( $opt{V} > 12 ) {
+ $cdr->calldate($cdr->start);
+ $cdr->startdate(str2time($cdr->start));
+ $cdr->answerdate(str2time($cdr->answer));
+ $cdr->enddate(str2time($cdr->end));
+ } else {
+ $cdr->startdate(str2time($cdr->calldate));
+ }
+
$cdr->cdrbatchnum($cdrbatchnum);
+
my $error = $cdr->insert;
if ($error) {
warn "failed import: $error\n";
- }
- else {
+ } else {
$imports++;
if( $dbi->do("UPDATE cdr SET freesidestatus = 'done'
WHERE calldate = ? AND src = ? AND dst = ?",
@@ -97,13 +114,14 @@ while ( $row = $sth->fetchrow_hashref ) {
warn "failed to set status: ".$dbi->errstr."\n";
}
}
+
}
warn "Done.\nImported $imports CDRs, marked $updates CDRs as done.\n";
$dbi->disconnect;
sub usage {
- "Usage: \n freeside-cdr-asterisk_sql\n\t-e mysql|Pg|... [ -H host ]\n\t-D database\n\t-U user\n\t-P password\n\tfreesideuser\n";
+ "Usage: \n freeside-cdr-asterisk_sql\n\t-e mysql|Pg|... [ -H host ]n\t-D database\n\t[ -T table ]\n\t[ -V asterisk_version]\n\t-U user\n\t-P password\n\tfreesideuser\n";
}
=head1 NAME
@@ -112,7 +130,7 @@ freeside-cdr-asterisk_sql - Import CDRs from an Asterisk SQL database
=head1 SYNOPSIS
- freeside-cdr-asterisk_sql -e mysql|Pg|... [ -H host ] -D database [ -T table ] -U user -P password [ -s ] freesideuser
+ freeside-cdr-asterisk_sql -e mysql|Pg|... [ -H host ] -D database [ -T table ][ -V asterisk_version ] -U user -P password freesideuser
=head1 DESCRIPTION
@@ -130,6 +148,8 @@ Imports CDR records from an Asterisk SQL database.
-P: password
+-V: Asterisk version. Values of 12 or higher have a new database schema. Currently defaults to 11, but may default to 12+ or be required in a future, so best to always specify the version.
+
=cut
1;
-----------------------------------------------------------------------
Summary of changes:
FS/bin/freeside-cdr-asterisk_sql | 42 ++++++++++++++++++++++++++++----------
1 file changed, 31 insertions(+), 11 deletions(-)
More information about the freeside-commits
mailing list