Skip to content

Commit 18bbc0a

Browse files
committed
Fix escalation condition and recipient removal
1 parent 17b5bc3 commit 18bbc0a

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

application/forms/EventRuleConfigElements/EscalationCondition.php

+12-26
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ protected function assemble(): void
5151
['value' => (string) $defaultCount]
5252
);
5353

54+
$this->addElement('hidden', 'remove-position');
55+
5456
$addCondition = $this->createElement(
5557
'submitButton',
5658
'add-condition',
@@ -76,7 +78,6 @@ protected function assemble(): void
7678
for ($i = 1; $i <= $conditionCount; $i++) {
7779
$colName = 'column_' . $i;
7880
$opName = 'operator_' . $i;
79-
$typeName = 'type_' . $i;
8081
$valName = 'val_' . $i;
8182

8283
$col = $this->createElement(
@@ -126,18 +127,6 @@ protected function assemble(): void
126127
]
127128
);
128129

129-
if (
130-
$this->getPopulatedValue($typeName) !== 'incident_severity'
131-
&& $this->getPopulatedValue($valName) !== null
132-
) {
133-
$this->clearPopulatedValue($typeName);
134-
$this->clearPopulatedValue($valName);
135-
}
136-
137-
$this->addElement('hidden', $typeName, [
138-
'value' => 'incident_severity'
139-
]);
140-
141130
break;
142131
case 'incident_age':
143132
$val = $this->createElement(
@@ -166,18 +155,6 @@ protected function assemble(): void
166155
]
167156
);
168157

169-
if (
170-
$this->getPopulatedValue($typeName) !== 'incident_age'
171-
&& $this->getPopulatedValue($valName) !== null
172-
) {
173-
$this->clearPopulatedValue($typeName);
174-
$this->clearPopulatedValue($valName);
175-
}
176-
177-
$this->addElement('hidden', $typeName, [
178-
'value' => 'incident_age'
179-
]);
180-
181158
break;
182159
default:
183160
$val = $this->createElement('text', $valName, [
@@ -197,6 +174,7 @@ protected function assemble(): void
197174

198175
$removePosition = (int) $this->getValue('remove');
199176
if ($removePosition) {
177+
$this->getElement('remove-position')->setValue($removePosition);
200178
unset($this->conditions[$removePosition]);
201179
$conditionCount -= 1;
202180
if ($conditionCount === 1 && ! $this->allowZeroConditions && $removePosition === 2) {
@@ -207,7 +185,7 @@ protected function assemble(): void
207185
$this->conditions[$nextCount]->conditionType->setName('column_' . $n);
208186
$this->conditions[$nextCount]->operator->setName('operator_' . $n);
209187
$this->conditions[$nextCount]->conditionVal->setName('val_' . $n);
210-
if ($conditionCount === 1) {
188+
if ($conditionCount === 1 && ! $this->allowZeroConditions) {
211189
$this->conditions[$nextCount]->removeButton = null;
212190
} elseif ($this->conditions[$nextCount]->removeButton) {
213191
$this->conditions[$nextCount]->removeButton->setValue((string) $n);
@@ -275,9 +253,17 @@ public function getCondition(): string
275253
$filter = Filter::any();
276254
/** @var int $count */
277255
$count = $this->getValue('condition-count');
256+
$removePosition = $this->getValue('remove-position');
257+
if ($removePosition) {
258+
$count += 1;
259+
}
278260

279261
if ($count > 0) { // if count is 0, loop runs in reverse direction
280262
foreach (range(1, $count) as $count) {
263+
if ($count === (int) $removePosition) {
264+
continue;
265+
}
266+
281267
$chosenType = $this->getValue('column_' . $count, 'placeholder');
282268

283269
$filterStr = $chosenType

application/forms/EventRuleConfigElements/EscalationRecipient.php

+11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ protected function assemble(): void
2424
{
2525
$this->addElement('hidden', 'recipient-count', ['value' => '1']);
2626

27+
$this->addElement('hidden', 'remove-position');
28+
2729
$addRecipientButton = $this->createElement(
2830
'submitButton',
2931
'add-recipient',
@@ -105,6 +107,7 @@ protected function assemble(): void
105107

106108
$removePosition = (int) $this->getValue('remove');
107109
if ($removePosition) {
110+
$this->getElement('remove-position')->setValue($removePosition);
108111
unset($this->recipients[$removePosition]);
109112
$recipientCount -= 1;
110113
if ($recipientCount === 1 && $removePosition === 2) {
@@ -201,9 +204,17 @@ public function getRecipients(): array
201204
{
202205
/** @var int $count */
203206
$count = $this->getValue('recipient-count');
207+
$removePosition = $this->getValue('remove-position');
208+
if ($removePosition) {
209+
$count += 1;
210+
}
204211

205212
$values = [];
206213
for ($i = 1; $i <= $count; $i++) {
214+
if ($i === (int) $removePosition) {
215+
continue;
216+
}
217+
207218
$value = [];
208219
$value['channel_id'] = $this->getValue('val_' . $i);
209220
$value['id'] = $this->getValue('id_' . $i);

application/forms/EventRuleConfigForm.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,15 +247,15 @@ protected function assemble(): void
247247

248248
if ($noZeroEscalationConditions === true) {
249249
foreach ($escalations as $escalation) {
250-
$escalation->getCondition()
250+
$escalation->condition
251251
->setAllowZeroConditions(true);
252252
}
253253

254254
$this->getElement('zero-condition-escalation')
255255
->setValue(null);
256256
} elseif ($zeroConditionEscalation) {
257257
$escalations[$zeroConditionEscalation]
258-
->getCondition()
258+
->condition
259259
->setAllowZeroConditions(true);
260260
}
261261

0 commit comments

Comments
 (0)