diff --git a/lib/NGCP/BulkProcessor/Projects/Export/Ama/Ccs/settings.cfg b/lib/NGCP/BulkProcessor/Projects/Export/Ama/Ccs/settings.cfg index dbb3a4be..a58b407e 100644 --- a/lib/NGCP/BulkProcessor/Projects/Export/Ama/Ccs/settings.cfg +++ b/lib/NGCP/BulkProcessor/Projects/Export/Ama/Ccs/settings.cfg @@ -15,6 +15,7 @@ export_cdr_rollover_fsn = 1 use_tempfiles = 1 make_dir = 1 ama_filename_format = %1$sP%3$02d%4$02d%5$02d%6$02d%7$02d%9$02dAMA%10$s +copy_output_path = files_owner = files_group = files_mask = @@ -34,4 +35,4 @@ primary_alias_pattern = 431976 switch_number_pattern = 43 switch_number_replacement = -terminating_open_digits_6001 = 04319558290 \ No newline at end of file +terminating_open_digits_6001 = 4319558290 \ No newline at end of file diff --git a/lib/NGCP/BulkProcessor/Projects/Export/Ama/Ccs/settings.debug.cfg b/lib/NGCP/BulkProcessor/Projects/Export/Ama/Ccs/settings.debug.cfg index 2248094c..088bc722 100644 --- a/lib/NGCP/BulkProcessor/Projects/Export/Ama/Ccs/settings.debug.cfg +++ b/lib/NGCP/BulkProcessor/Projects/Export/Ama/Ccs/settings.debug.cfg @@ -17,6 +17,7 @@ export_cdr_conditions = { 'accounting.cdr.id' => { 'IN' => '(51,53, 87,89, 55, 7 use_tempfiles = 1 make_dir = 1 ama_filename_format = %1$sdebug/P%3$02d%4$02d%5$02d%6$02d%7$02d%9$02dAMA.debug%10$s +copy_output_path = /home/rkrenn/temp/export_copy files_owner = files_group = files_mask = @@ -36,4 +37,4 @@ ivr_duration_limit = 5 switch_number_pattern = 43 switch_number_replacement = -terminating_open_digits_6001 = 04319558290 \ No newline at end of file +terminating_open_digits_6001 = 4319558290 \ No newline at end of file diff --git a/lib/NGCP/BulkProcessor/Projects/Export/Ama/Format/File.pm b/lib/NGCP/BulkProcessor/Projects/Export/Ama/Format/File.pm index 1aba8f77..4f44de05 100644 --- a/lib/NGCP/BulkProcessor/Projects/Export/Ama/Format/File.pm +++ b/lib/NGCP/BulkProcessor/Projects/Export/Ama/Format/File.pm @@ -4,9 +4,11 @@ use strict; ## no critic use File::Basename qw(fileparse); +use File::Copy qw(); use NGCP::BulkProcessor::Projects::Export::Ama::Format::Settings qw( $output_path + $copy_output_path $ama_filename_format $use_tempfiles $tempfile_path @@ -29,6 +31,7 @@ use NGCP::BulkProcessor::Logging qw( use NGCP::BulkProcessor::LogError qw( fileerror + filewarn ); use NGCP::BulkProcessor::Utils qw(tempfilename makepath); @@ -114,10 +117,10 @@ sub add_record { sub get_filename { my $self = shift; - my ($show_tempfilename) = @_; + my ($show_tempfilename,$basepath) = @_; return $self->{tempfilename} if ($use_tempfiles and $show_tempfilename); return sprintf($ama_filename_format, - $output_path, + $basepath // $output_path, $self->{now}->year, substr($self->{now}->year,-2), $self->{now}->month, @@ -139,10 +142,17 @@ sub _rename { my $self = shift; my ($filename) = @_; my $result = rename($self->{tempfilename},$filename); - _chownmod($filename,$files_owner,$files_group,oct(666),$files_mask) if $result; + #_chownmod($filename,$files_owner,$files_group,oct(666),$files_mask) if $result; return $result; } +sub _copy { + + my ($source_filename,$target_filename) = @_; + File::Copy::cp($source_filename,$target_filename) or die ($!); + +} + sub _makedir { my ($filename) = @_; @@ -186,6 +196,13 @@ sub flush { if (defined $commit_cb) { if (&$commit_cb(@_)) { if (not $use_tempfiles or $self->_rename(_makedir($filename))) { + _chownmod($filename,$files_owner,$files_group,oct(666),$files_mask); + eval { + _copy($filename,_makedir($self->get_filename(0,$copy_output_path))) if $copy_output_path; + }; + if ($@) { + filewarn("failed to create copy of $filename: " . $@,getlogger(__PACKAGE__)); + } return 1; } else { my $err = $!; diff --git a/lib/NGCP/BulkProcessor/Projects/Export/Ama/Format/Settings.pm b/lib/NGCP/BulkProcessor/Projects/Export/Ama/Format/Settings.pm index fa9c052d..5f44a84f 100644 --- a/lib/NGCP/BulkProcessor/Projects/Export/Ama/Format/Settings.pm +++ b/lib/NGCP/BulkProcessor/Projects/Export/Ama/Format/Settings.pm @@ -36,6 +36,7 @@ our @EXPORT_OK = qw( update_settings $output_path + $copy_output_path $tempfile_path $domestic_destination_pattern @@ -53,6 +54,7 @@ our @EXPORT_OK = qw( ); our $output_path = $working_path . 'output/'; +our $copy_output_path = undef; our $tempfile_path = $working_path . 'temp/'; our $use_tempfiles = 0; @@ -79,7 +81,7 @@ sub update_settings { #&$configurationinfocode("testinfomessage",$configlogger); - $result &= _prepare_working_paths(1); + $result &= _prepare_working_paths($data,1); $use_tempfiles = $data->{use_tempfiles} if exists $data->{use_tempfiles}; $make_dir = $data->{make_dir} if exists $data->{make_dir}; @@ -109,12 +111,16 @@ sub update_settings { sub _prepare_working_paths { - my ($create) = @_; + my ($data,$create) = @_; my $result = 1; my $path_result; ($path_result,$output_path) = create_path($working_path . 'output',$output_path,$create,\&fileerror,getlogger(__PACKAGE__)); $result &= $path_result; + if ($data->{copy_output_path}) { + ($path_result,$copy_output_path) = create_path($data->{copy_output_path},$copy_output_path,$create,\&fileerror,getlogger(__PACKAGE__)); + $result &= $path_result; + } ($path_result,$tempfile_path) = create_path($working_path . 'temp',$output_path,$create,\&fileerror,getlogger(__PACKAGE__)); $result &= $path_result;