TT#69853 support resetting .ama export status by call-id(s)

Change-Id: Iac1ceaf333a6e431cb59fc03e8015d337d0ac692
changes/65/34865/1
Rene Krenn 6 years ago
parent 5d38bd26f7
commit 8b934eb8b2

@ -173,23 +173,33 @@ sub upsert_row {
sub update_export_status {
my ($status_id,$export_status,$start_time_from,$start_time_to) = @_;
my ($status_id,$export_status,$start_time_from,$start_time_to,$call_ids) = @_;
check_table();
my $db = &$get_db();
my $table = $db->tableidentifier($tablename);
my $stmt = 'UPDATE ' . $table . ' SET ' . $db->columnidentifier('export_status') . ' = ?' .
' WHERE ' . $db->columnidentifier('status_id') . ' = ? AND ' . $db->columnidentifier('export_status') . ' != ?';
my $stmt = 'UPDATE ' . $table . ' s JOIN accounting.cdr c on s.cdr_id = c.id SET s.export_status = ?' .
' WHERE s.status_id = ? AND s.export_status != ?';
my @params = ($export_status,$status_id,$export_status);
if (defined $start_time_from) {
$stmt .= ' AND ' . $db->columnidentifier('cdr_start_time') . ' >= UNIX_TIMESTAMP(?)';
$stmt .= ' AND s.cdr_start_time >= UNIX_TIMESTAMP(?)';
push(@params,$start_time_from);
}
if (defined $start_time_to) {
$stmt .= ' AND ' . $db->columnidentifier('cdr_start_time') . ' < UNIX_TIMESTAMP(?)';
$stmt .= ' AND s.cdr_start_time < UNIX_TIMESTAMP(?)';
push(@params,$start_time_to);
}
if (defined $call_ids and (scalar @$call_ids) > 0) {
my @terms = ();
foreach my $callid (@$call_ids) {
my $call_id = NGCP::BulkProcessor::Dao::Trunk::accounting::cdr::get_callidprefix($callid);
$call_id =~ s/%/\\%/g;
push(@terms,'c.call_id LIKE ?');
push(@params,$call_id . '%');
}
$stmt .= ' AND (' . join(" OR ", @terms) . ')';
}
my $count;
if ($count = $db->db_do($stmt,@params)) {

@ -120,7 +120,7 @@ my $rowcount : shared = 0;
sub reset_export_status {
my ($from,$to) = @_;
my ($from,$to,$call_ids) = @_;
my $result = 1;
my $context = { tid => threadid(), warning_count => 0, error_count => 0, };
@ -128,7 +128,7 @@ sub reset_export_status {
my $updated;
eval {
$updated = NGCP::BulkProcessor::Dao::Trunk::accounting::cdr_export_status_data::update_export_status($context->{export_status_id},
$NGCP::BulkProcessor::Dao::Trunk::accounting::cdr_export_status_data::UNEXPORTED,$from,$to);
$NGCP::BulkProcessor::Dao::Trunk::accounting::cdr_export_status_data::UNEXPORTED,$from,$to,$call_ids);
};
if ($@) {
if ($skip_errors) {

@ -79,6 +79,7 @@ my @TASK_OPTS = ();
my $tasks = [];
my $from = undef,
my $to = undef;
my $call_ids = [];
my $cleanup_task_opt = 'cleanup';
push(@TASK_OPTS,$cleanup_task_opt);
@ -115,9 +116,11 @@ sub init {
"force" => \$force,
"from=s" => \$from,
"to=s" => \$to,
"call-id=s" => $call_ids,
); # or scripterror('error in command line arguments',getlogger(getscriptpath()));
$tasks = removeduplicates($tasks,1);
$call_ids = removeduplicates($call_ids);
my $result = load_config($configfile);
init_log();
@ -264,10 +267,13 @@ sub reset_export_status_task {
my ($messages) = @_;
my ($result) = (0);
eval {
($result) = reset_export_status($from,$to);
($result) = reset_export_status($from,$to,$call_ids);
};
my $err = $@;
my $fromto = 'from ' . ($from ? $from : '-') . ' to ' . ($to ? $to : '-');
if (defined $call_ids and (scalar @$call_ids) > 0) {
$fromto = ", call-id(s)\n" . join("\n",@$call_ids);
}
if ($err or !$result) {
push(@$messages,"reset export status $fromto INCOMPLETE");
} else {

Loading…
Cancel
Save