Skip to content

Commit cee504c

Browse files
authored
fix(targetticket): allow more itemtypes to associated elements (#3155)
1 parent 7ece642 commit cee504c

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

inc/targetticket.class.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ protected function showAssociateSettings($rand) {
11891189
* @return array
11901190
*/
11911191
protected function setTargetAssociatedItem(array $data, PluginFormcreatorFormAnswer $formanswer) : array {
1192-
global $DB, $CFG_GLPI;
1192+
global $DB;
11931193

11941194
switch ($this->fields['associate_rule']) {
11951195
case self::ASSOCIATE_RULE_ANSWER:
@@ -1265,6 +1265,7 @@ protected function setTargetAssociatedItem(array $data, PluginFormcreatorFormAns
12651265
]
12661266
]);
12671267

1268+
$valid_associated_itemtypes = $_SESSION["glpiactiveprofile"]["helpdesk_item_type"];
12681269
foreach ($answers as $answer) {
12691270
// Skip if the object type is not valid asset type
12701271
$question = new PluginFormcreatorQuestion();
@@ -1273,7 +1274,7 @@ protected function setTargetAssociatedItem(array $data, PluginFormcreatorFormAns
12731274
$field = $question->getSubField();
12741275
$field->deserializeValue($answer['answer']);
12751276
$itemtype = $field->getSubItemtype();
1276-
if (!in_array($itemtype, $CFG_GLPI['asset_types'])) {
1277+
if (!in_array($itemtype, $valid_associated_itemtypes)) {
12771278
continue;
12781279
}
12791280

tests/3-unit/PluginFormcreatorTargetTicket.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,17 +1064,15 @@ public function providerSetTargetAssociatedItem_1() {
10641064
}
10651065

10661066
public function providerSetTargetAssociatedItem_LastItem() {
1067-
global $CFG_GLPI;
1068-
10691067
// Prepare form
1070-
$validItemtype = $CFG_GLPI["asset_types"][0];
1071-
if (array_search(Computer::getType(), $CFG_GLPI['asset_types']) === false) {
1072-
$CFG_GLPI['asset_types'][] = Computer::getType();
1068+
$validItemtype = $_SESSION["glpiactiveprofile"]["helpdesk_item_type"][0];
1069+
if (array_search(Computer::getType(), $_SESSION["glpiactiveprofile"]["helpdesk_item_type"]) === false) {
1070+
$_SESSION["glpiactiveprofile"]["helpdesk_item_type"][] = Computer::getType();
10731071
}
10741072
$invalidItemtype = Monitor::getType();
10751073

10761074
// Ensure an itemtype is not in the asset types
1077-
$CFG_GLPI['asset_types'] = array_filter($CFG_GLPI['asset_types'], function ($itemtype) use ($invalidItemtype) {
1075+
$_SESSION["glpiactiveprofile"]["helpdesk_item_type"] = array_filter($_SESSION["glpiactiveprofile"]["helpdesk_item_type"], function ($itemtype) use ($invalidItemtype) {
10781076
return ($itemtype != $invalidItemtype);
10791077
});
10801078

@@ -1384,7 +1382,7 @@ public function providerSetTargetLocation_NotSet() {
13841382

13851383
$form1 = $this->getForm();
13861384

1387-
$instance1 = new PluginFormcreatorTargetTicket();
1385+
$instance1 = $this->newTestedInstance();
13881386
$instance1->add([
13891387
'name' => 'foo',
13901388
'target_name' => '',
@@ -1438,7 +1436,7 @@ public function providerSetTargetLocation_LastItem() {
14381436
'fieldtype' => 'dropdown',
14391437
'itemtype' => $validItemtype
14401438
]);
1441-
$instance1 = new PluginFormcreatorTargetTicket();
1439+
$instance1 = $this->newTestedInstance();
14421440
$instance1->add([
14431441
'name' => 'foo',
14441442
'target_name' => '',

0 commit comments

Comments
 (0)