MT#57987 /api/rewriterules calculate priority on create

* when a new rewrite rule is created and the priority attribute
  is not specified, only the first rewrite rule of the same rewrite
  rule set is set as 50, and the following are as:
  "MAX(priority) of the same rewrite rule set"+1

Change-Id: I1f1ae275e00918a34a625409987f21044b3b940f
mr12.0
Kirill Solomko 2 years ago
parent ae99153421
commit b7c22618c8

@ -69,6 +69,21 @@ sub create_item {
my $item;
try {
unless ($form->values->{priority}) {
my $res = $c->model('DB')->resultset('voip_rewrite_rules')->search({
set_id => $form->values->{set_id},
},{
columns => [
{ max_priority => \'MAX(priority)' },
]
})->first;
if ($res) {
my %cols = $res->get_inflated_columns;
if ($cols{max_priority}) {
$resource->{priority} = $cols{max_priority} + 1;
}
}
}
$item = $schema->resultset('voip_rewrite_rules')->create($resource);
} catch($e) {
$c->log->error("failed to create rewriterule: $e"); # TODO: user, message, trace, ...

Loading…
Cancel
Save