[freeside-commits] branch FREESIDE_4_BRANCH updated. c1a35163e317512c0cae49f16080fc974278b952

Ivan ivan at 420.am
Wed Dec 2 04:21:20 PST 2015


The branch, FREESIDE_4_BRANCH has been updated
       via  c1a35163e317512c0cae49f16080fc974278b952 (commit)
      from  cb74d5397d8be2de069099f568653a565701c451 (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 c1a35163e317512c0cae49f16080fc974278b952
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Wed Dec 2 04:21:18 2015 -0800

    alias mysql import to generic one, RT#39250

diff --git a/FS/bin/freeside-cdr-mysql b/FS/bin/freeside-cdr-mysql
index 608a8dc..3519fb7 100755
--- a/FS/bin/freeside-cdr-mysql
+++ b/FS/bin/freeside-cdr-mysql
@@ -1,88 +1,2 @@
-#!/usr/bin/perl
-
-use strict;
-use vars qw( $DEBUG );
-use Date::Parse 'str2time';
-use Date::Format 'time2str';
-use FS::UID qw(adminsuidsetup dbh);
-use FS::cdr;
-use DBI;
-use Getopt::Std;
-
-my %opt;
-getopts('H:U:P:D:T:', \%opt);
-my $user = shift or die &usage;
-
-my $dsn = 'dbi:mysql';
-$dsn .= ":database=$opt{D}" if $opt{D};
-$dsn .= ":host=$opt{H}" if $opt{H};
-
-my $mysql = DBI->connect($dsn, $opt{U}, $opt{P}) 
-  or die $DBI::errstr;
-
-adminsuidsetup $user;
-
-my $fsdbh = FS::UID::dbh;
-
-# check for existence of freesidestatus
-my $table = $opt{T} || 'cdr';
-my $status = $mysql->selectall_arrayref("SHOW COLUMNS FROM $table WHERE Field = 'freesidestatus'");
-if( ! @$status ) {
-  print "Adding freesidestatus column...\n";
-  $mysql->do("ALTER TABLE $table ADD COLUMN freesidestatus varchar(32)")
-    or die $mysql->errstr;
-}
-else {
-  print "freesidestatus column present\n";
-}
-
-my @cols = ( qw( 
-calldate clid src dst dcontext channel lastapp lastdata duration 
-    billsec disposition amaflags accountcode uniqueid userfield) );
-my $sql = 'SELECT '.join(',', @cols). " FROM $table WHERE freesidestatus IS NULL";
-my $sth = $mysql->prepare($sql);
-$sth->execute;
-print "Importing ".$sth->rows." records...\n";
-
-my $cdr_batch = new FS::cdr_batch({ 
-    'cdrbatch' => 'mysql-import-'. time2str('%Y/%m/%d-%T',time),
-  });
-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 ) {
-  my $cdr = FS::cdr->new($row);
-  $cdr->startdate(str2time($cdr->calldate));
-  $cdr->cdrbatchnum($cdrbatchnum);
-  my $error = $cdr->insert;
-  if($error) {
-    print "failed import: $error\n";
-  }
-  else {
-    $imports++;
-    if( $mysql->do("UPDATE cdr SET freesidestatus = 'done' 
-        WHERE calldate = ? AND src = ? AND dst = ?",
-                undef,
-                $row->{'calldate'},
-                $row->{'src'},
-                $row->{'dst'},
-
-      ) ) {
-        $updates++;
-    }
-    else {
-      print "failed to set status: ".$mysql->errstr."\n";
-    }
-  }
-}
-print "Done.\nImported $imports CDRs, marked $updates CDRs as done.\n";
-$mysql->disconnect;
-
-sub usage {
-  "Usage: \n  cdr-mysql.import\n\t[ -H host ]\n\t-D database\n\t-U user\n\t-P password\n\tfreesideuser\n";
-}
-
+#!/bin/sh
+freeside-cdr-sql.import -e mysql "$@"

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

Summary of changes:
 FS/bin/freeside-cdr-mysql |   90 +--------------------------------------------
 1 file changed, 2 insertions(+), 88 deletions(-)




More information about the freeside-commits mailing list