From 82e3ce898bc2aa11ce5cbc6bc48c408c6a5b91c3 Mon Sep 17 00:00:00 2001 From: Kirill Solomko Date: Wed, 13 Mar 2019 10:53:43 +0100 Subject: [PATCH] TT#55104 fix sound files update_model error handling * API SoundFiles transcoding error is now handled correctly * Fix cases in Role/API/SoundFiles that used last instead of return Change-Id: I2636d654b3b405645761dda834c8215514bf50e2 --- lib/NGCP/Panel/Role/API/SoundFiles.pm | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/NGCP/Panel/Role/API/SoundFiles.pm b/lib/NGCP/Panel/Role/API/SoundFiles.pm index f2784af5ce..71a960bf5f 100644 --- a/lib/NGCP/Panel/Role/API/SoundFiles.pm +++ b/lib/NGCP/Panel/Role/API/SoundFiles.pm @@ -35,7 +35,7 @@ sub _item_rs { my ($self, $c) = @_; my $item_rs = $c->model('DB')->resultset('voip_sound_files')->search( - {}, + {}, { prefetch => ['handle', 'set'], }); @@ -131,8 +131,7 @@ sub update_item { $resource->{loopplay} = ($resource->{loopplay} eq "true" || is_int($resource->{loopplay}) && $resource->{loopplay}) ? 1 : 0; - - my $set_rs = $c->model('DB')->resultset('voip_sound_sets')->search({ + my $set_rs = $c->model('DB')->resultset('voip_sound_sets')->search({ id => $resource->{set_id}, }); if($c->user->roles eq "admin") { @@ -145,11 +144,11 @@ sub update_item { unless($set) { $c->log->error("invalid set_id '$$resource{set_id}'"); $self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Sound set does not exist"); - last; + return; } my $handle_rs = $c->model('DB')->resultset('voip_sound_handles')->search({ - 'me.name' => $resource->{handle}, + 'me.name' => $resource->{handle}, }); my $handle; if($set->contract_id) { @@ -186,13 +185,17 @@ sub update_item { } catch ($e) { $c->log->error("Failed to clear audio cache for " . $group_name . " at appserver",); $self->error($c, HTTP_UNPROCESSABLE_ENTITY, 'Failed to clear audio cache.'); - last; + return; } $resource->{codec} = 'WAV'; $resource->{data} = $recording; $resource = $self->transcode_data($c, 'WAV', $resource); - last unless($resource); + unless ($resource) { + $c->log->error("Failed to transcode sound file",); + $self->error($c, HTTP_UNPROCESSABLE_ENTITY, 'Failed to transcode sound file'); + return; + } delete $resource->{handle}; try {