MT#15361 fix post soundfiles creating duplicate entry

Change-Id: I8f1201325119617fb25b6826ebf249c367a5b82b
changes/69/2769/2
Gerhard Jungwirth 11 years ago
parent a356152416
commit e8f19f7339

@ -152,17 +152,14 @@ sub POST :Allow {
my $form = $self->get_form($c);
my $item;
try {
my $tmp_item = $c->model('DB')->resultset('voip_sound_files')->search_rs({
set_id => $resource->{set_id},
handle_id => $resource->{handle_id},
})->first;
$item = $self->update_item($c, $tmp_item, undef, $resource, $form);
} catch($e) {
$c->log->error("failed to create soundfile: $e"); # TODO: user, message, trace, ...
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to create soundfile.");
last;
}
my $tmp_item = $self->item_rs($c)->search_rs({
set_id => $resource->{set_id},
'handle.name' => $resource->{handle},
},{
join => 'handle',
})->first;
$item = $self->update_item($c, $tmp_item, undef, $resource, $form);
last unless $item;
$guard->commit;

@ -158,7 +158,7 @@ sub update_item {
unless($handle) {
$c->log->error("invalid handle '$$resource{handle}', must be in group pbx, music_on_hold or digits for a customer sound set");
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Handle must be in group pbx, music_on_hold or digits for a customer sound set");
last;
return;
}
} else {
$handle_rs = $handle_rs->search({
@ -170,7 +170,7 @@ sub update_item {
unless($handle) {
$c->log->error("invalid handle '$$resource{handle}', must not be in group pbx for a system sound set");
$self->error($c, HTTP_UNPROCESSABLE_ENTITY, "Handle must not be in group pbx for a system sound set");
last;
return;
}
}
$resource->{handle_id} = $handle->id;
@ -196,10 +196,16 @@ sub update_item {
last unless($resource);
delete $resource->{handle};
if ($item) {
$item->update($resource);
} else {
$item = $c->model('DB')->resultset('voip_sound_files')->create($resource);
try {
if ($item) {
$item->update($resource);
} else {
$item = $c->model('DB')->resultset('voip_sound_files')->create($resource);
}
} catch($e) {
$c->log->error("failed to create soundfile: $e"); # TODO: user, message, trace, ...
$self->error($c, HTTP_INTERNAL_SERVER_ERROR, "Failed to create soundfile.");
return;
}
return $item;

Loading…
Cancel
Save