Skip to content

Commit aaae034

Browse files
committed
fix(condition): condition loss if itil target edited
1 parent 3c86f14 commit aaae034

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

inc/abstractitiltarget.class.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,10 +1580,6 @@ public function prepareInputForUpdate($input) {
15801580
}
15811581
}
15821582

1583-
if (!$this->checkConditionSettings($input)) {
1584-
$input['show_rule'] = PluginFormcreatorCondition::SHOW_RULE_ALWAYS;
1585-
}
1586-
15871583
return $input;
15881584
}
15891585

inc/conditionnabletrait.class.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public function checkConditions(array $input): bool {
7878

7979
public function checkConditionSettings(array $input): bool {
8080
if (!isset($input['show_rule'])) {
81-
return false;
81+
// Inconsistency if show_rule set but no condition set
82+
return !isset($input['_conditions']);
8283
}
8384
$showRule = $input['show_rule'];
8485
if ($showRule == PluginFormcreatorCondition::SHOW_RULE_ALWAYS) {
@@ -114,12 +115,23 @@ public function updateConditions($input) : bool {
114115
$itemtype = $this->getType();
115116
$itemId = $this->getID();
116117

117-
// Delete all existing conditions for the question
118-
$this->deleteConditions();
119-
if ($this->fields['show_rule'] == PluginFormcreatorCondition::SHOW_RULE_ALWAYS) {
120-
// No condition ? Exit now !
118+
if (!isset($this->input['show_rule']) && isset($this->fields['show_rule']) && $this->fields['show_rule'] == PluginFormcreatorCondition::SHOW_RULE_ALWAYS) {
119+
// rule not changed and is currently "always show"
120+
$this->deleteConditions();
121+
return true;
122+
}
123+
if (!isset($this->input['show_rule']) && isset($this->fields['show_rule']) && $this->fields['show_rule'] != PluginFormcreatorCondition::SHOW_RULE_ALWAYS) {
124+
// Rule not changed and is not "always show"
121125
return true;
122126
}
127+
if (isset($this->input['show_rule']) && $this->input['show_rule'] == PluginFormcreatorCondition::SHOW_RULE_ALWAYS) {
128+
// rule changed to "always show"
129+
$this->deleteConditions();
130+
return true;
131+
}
132+
133+
// Delete all existing conditions for the question
134+
$this->deleteConditions();
123135

124136
$input = $input['_conditions'];
125137

tests/3-unit/PluginFormcreatorTargetTicket.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,6 @@ public function providerPrepareInputForAdd() {
13091309
'content' => '##FULLFORM##',
13101310
'type_rule' => \PluginFormcreatorTargetTicket::REQUESTTYPE_SPECIFIC,
13111311
'type_question' => \Ticket::INCIDENT_TYPE,
1312-
'show_rule' => \PluginFormcreatorCondition::SHOW_RULE_ALWAYS,
13131312
'source_rule' => \PluginFormcreatorTargetTicket::REQUESTSOURCE_SPECIFIC,
13141313
'source_question' => $sourceId,
13151314
],
@@ -1330,7 +1329,6 @@ public function providerPrepareInputForAdd() {
13301329
'content' => '##FULLFORM##',
13311330
'type_rule' => \PluginFormcreatorTargetTicket::REQUESTTYPE_SPECIFIC,
13321331
'type_question' => \Ticket::DEMAND_TYPE,
1333-
'show_rule' => \PluginFormcreatorCondition::SHOW_RULE_ALWAYS,
13341332
'source_rule' => \PluginFormcreatorTargetTicket::REQUESTSOURCE_NONE,
13351333
'source_question' => 0,
13361334
],

0 commit comments

Comments
 (0)