journal cdrbatch -> cdrbatchnum upgrade
[freeside.git] / FS / FS / cdr.pm
index c61a7b3..f545632 100644 (file)
@@ -32,7 +32,7 @@ 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]';
@@ -1659,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;
 
@@ -1733,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...
   }
@@ -1864,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(
@@ -1894,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
@@ -1932,4 +1950,3 @@ L<FS::Record>, schema.html from the base documentation.
 =cut
 
 1;
-