journal cdrbatch -> cdrbatchnum upgrade
[freeside.git] / FS / FS / cdr.pm
index 155090d..f545632 100644 (file)
@@ -28,10 +28,11 @@ use FS::rate_detail;
 # LRN lookup
 use LWP::UserAgent;
 use HTTP::Request::Common qw(POST);
+use IO::Socket::SSL;
 use Cpanel::JSON::XS qw(decode_json);
 
 @ISA = qw(FS::Record);
-@EXPORT_OK = qw( _cdr_date_parser_maker _cdr_min_parser_maker );
+@EXPORT_OK = qw( _cdr_date_parser_maker _cdr_min_parser_maker _cdr_date_parse );
 
 $DEBUG = 0;
 $me = '[FS::cdr]';
@@ -1498,7 +1499,13 @@ sub get_lrn {
   my $self = shift;
   my $field = shift;
 
-  my $ua = LWP::UserAgent->new;
+  my $ua = LWP::UserAgent->new(
+             'ssl_opts' => {
+               verify_hostname => 0,
+               SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
+             },
+           );
+
   my $url = 'https://ws.freeside.biz/get_lrn';
 
   my %content = ( 'support-key' => $support_key,
@@ -1652,7 +1659,12 @@ foreach my $INC ( @INC ) {
 
 tie my %import_formats, 'Tie::IxHash',
   map  { $_ => $cdr_info{$_}->{'name'} }
-  sort { $cdr_info{$a}->{'weight'} <=> $cdr_info{$b}->{'weight'} }
+  
+  #this is not doing anything useful anymore
+  #sort { $cdr_info{$a}->{'weight'} <=> $cdr_info{$b}->{'weight'} }
+  #so just sort alpha
+  sort { lc($cdr_info{$a}->{'name'}) cmp lc($cdr_info{$b}->{'name'}) }
+
   grep { exists($cdr_info{$_}->{'import_fields'}) }
   keys %cdr_info;
 
@@ -1726,6 +1738,14 @@ sub _cdr_date_parse {
     # Telos 2014-10-10T05:30:33Z
     ($year, $mon, $day, $hour, $min, $sec) = ( $1, $2, $3, $4, $5, $6 );
     $options{gmt} = 1;
+  } elsif ( $date =~ /^(\d+):(\d+):(\d+)\.\d+ \w+ (\w+) (\d+) (\d+)$/ ) {
+    ($hour, $min, $sec, $mon, $day, $year) = ( $1, $2, $3, $4, $5, $6 );
+    $mon = { # Acme Packet: 15:54:56.868 PST DEC 18 2017
+      # My best guess of month abbv they may use
+      JAN => '01', FEB => '02', MAR => '03', APR => '04',
+      MAY => '05', JUN => '06', JUL => '07', AUG => '08',
+      SEP => '09', OCT => '10', NOV => '11', DEC => '12'
+    }->{$mon};
   } else {
      die "unparsable date: $date"; #maybe we shouldn't die...
   }
@@ -1857,9 +1877,12 @@ sub process_batch_import {
 #
 # Used by FS::Upgrade to migrate to a new database.
 
+use FS::upgrade_journal;
 sub _upgrade_data {
   my ($class, %opts) = @_;
 
+  return if FS::upgrade_journal->is_done('cdr_cdrbatchnum');
+
   warn "$me upgrading $class\n" if $DEBUG;
 
   my $sth = dbh->prepare(
@@ -1887,6 +1910,8 @@ sub _upgrade_data {
     $sth->execute($cdrbatchnum{$cdrbatch}, $cdrbatch) or die $sth->errstr;
   }
 
+  FS::upgrade_journal->set_done('cdr_cdrbatchnum');
+
 }
 
 =item ip_addr_sql FIELD RANGE
@@ -1925,4 +1950,3 @@ L<FS::Record>, schema.html from the base documentation.
 =cut
 
 1;
-