[freeside-commits] branch master updated. 189f40043dc1e82373243acc73abd03f8151c87c

Ivan ivan at 420.am
Sat Jun 28 00:51:44 PDT 2014


The branch, master has been updated
       via  189f40043dc1e82373243acc73abd03f8151c87c (commit)
      from  6805930da094e93edb07c01f50a6a3c071d8ab5e (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 189f40043dc1e82373243acc73abd03f8151c87c
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Sat Jun 28 00:51:44 2014 -0700

    use a separate table for freesidestatus for IVR imports, RT#39055

diff --git a/FS/FS/cdr/Import.pm b/FS/FS/cdr/Import.pm
index 7a37758..472e220 100644
--- a/FS/FS/cdr/Import.pm
+++ b/FS/FS/cdr/Import.pm
@@ -74,11 +74,19 @@ sub dbi_import {
   #  else {
   #    print "freesidestatus column present\n";
   #  }
+  # or if using a status_table:
+  #      CREATE TABLE FREESIDE_BILLING (
+  #        BILLING_ID BIGINT,
+  #        FREESIDESTATUS VARCHAR(32)
+  #      )
 
   #my @cols = values %{ $args{column_map} };
-  my $sql = "SELECT * FROM $table ". # join(',', @cols). " FROM $table ".
+  my $sql = "SELECT * FROM $table "; # join(',', @cols). " FROM $table ".
+  $sql .=  'LEFT JOIN '. $args{status_table}.
+           ' USING ( '. $args{primary_key}. ' )'
+    if $args{status_table};
+  $sql .= ' WHERE freesidestatus IS NULL ';
 
-            ' WHERE freesidestatus IS NULL ';
   #$sql .= ' LIMIT '. $opt{L} if $opt{L};
   my $sth = $dbi->prepare($sql);
   $sth->execute or die $sth->errstr. " executing $sql";
@@ -111,19 +119,33 @@ sub dbi_import {
 
     #print $row->{$pkey},"\n" if $opt{v};
     my $error = $cdr->insert;
+
     if ($error) {
+
       #die $row->{$pkey} . ": failed import: $error\n";
       print $row->{$pkey} . ": failed import: $error\n";
+
     } else {
+
       $imported++;
 
-      my $updated = $dbi->do(
-        "UPDATE $table SET freesidestatus = 'done' WHERE $pkey = ?",
-        undef,
-        $row->{$pkey}
-      );
+      my $st_sql;
+      if ( $args{status_table} ) {
+
+        $st_sql = 
+          'INSERT INTO '. $args{status_table}. " ( $pkey, freesidestatus ) ".
+            " VALUES ( ?, 'done' )";
+
+      } else {
+
+        $st_sql = "UPDATE $table SET freesidestatus = 'done' WHERE $pkey = ?";
+
+      }
+
+      my $updated = $dbi->do($st_sql, undef, $row->{$pkey} );
       #$updates += $updated;
       die "failed to set status: ".$dbi->errstr."\n" unless $updated;
+
     }
 
     if ( $opt{L} && $imported >= $opt{L} ) {
diff --git a/bin/cdr-ivr.import b/bin/cdr-ivr.import
index 07c180b..9a4eb0d 100755
--- a/bin/cdr-ivr.import
+++ b/bin/cdr-ivr.import
@@ -5,11 +5,12 @@ use Date::Parse 'str2time';
 use FS::cdr::Import;
 
 FS::cdr::Import->dbi_import(
-  'dbd'         => 'Sybase',
-  'database'    => 'TEL_DATA',
-  'table'       => 'BILLING',
-  'primary_key' => 'BILLING_ID',
-  'column_map'  => { #freeside => IVR
+  'dbd'          => 'Sybase',
+  'database'     => 'TEL_DATA',
+  'table'        => 'BILLING',
+  'primary_key'  => 'BILLING_ID',
+  'status_table' => 'FREESIDE_BILLING',
+  'column_map'   => { #freeside => IVR
     'cdrid'             => 'BILLING_ID', #Primary key
     #'' => 'CALL_SESSION_ID', # Call Session Id (unique per call session – GUID)
     'uniqueid'          => 'CALL_ID', #

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/cdr/Import.pm |   36 +++++++++++++++++++++++++++++-------
 bin/cdr-ivr.import  |   11 ++++++-----
 2 files changed, 35 insertions(+), 12 deletions(-)




More information about the freeside-commits mailing list