Skip to content

Commit 22809ce

Browse files
committed
fix(dropdown): change to ticket category
changing from an other droptown causes php warnings also add upgrade code Signed-off-by: btry <tbugier@teclib.com>
1 parent 91cc6ce commit 22809ce

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

inc/question.class.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,9 @@ function plugin_formcreator_hideAllParameters() {
961961
];
962962
dropdown::showFromArray('show_ticket_categories', $ticketCategoriesOptions, [
963963
'rand' => $rand,
964-
'value' => $decodedValues['show_ticket_categories']
964+
'value' => isset($decodedValues['show_ticket_categories'])
965+
? $decodedValues['show_ticket_categories']
966+
: 'both'
965967
]);
966968
echo '</td>';
967969
echo '<td>';
@@ -972,7 +974,9 @@ function plugin_formcreator_hideAllParameters() {
972974
echo '<td>';
973975
dropdown::showNumber('show_ticket_categories_depth', [
974976
'rand' => $rand,
975-
'value' => $decodedValues['show_ticket_categories_depth'],
977+
'value' => isset($decodedValues['show_ticket_categories_depth'])
978+
? $decodedValues['show_ticket_categories_depth']
979+
: 0,
976980
'min' => 1,
977981
'max' => 16,
978982
'toadd' => [0 => __('No limit', 'formcreator')],

install/update_2.6_2.7.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,24 @@ function plugin_formcreator_update_2_7(Migration $migration) {
8888
$id = $row['id'];
8989
$DB->query("UPDATE `glpi_plugin_formcreator_questions` SET `name`='$name' WHERE `id` = '$id'");
9090
}
91+
92+
// Add properties for dropdown of ticket categories
93+
$request = [
94+
'FROM' => 'glpi_plugin_formcreator_questions',
95+
'WHERE' => [
96+
'fieldtype' => 'dropdown'
97+
],
98+
];
99+
foreach ($DB->request($request) as $row) {
100+
$values = json_decode($row['values'], true);
101+
if (!isset($values['show_ticket_categories'])) {
102+
$values['show_ticket_categories'] = 'both';
103+
}
104+
if (!isset($values['show_ticket_categories_depth'])) {
105+
$values['show_ticket_categories_depth'] = '0';
106+
}
107+
$id = $row['id'];
108+
$values = json_encode($values);
109+
$DB->query("UPDATE `glpi_plugin_formcreator_questions` SET `values`='$values' WHERE `id` = '$id'");
110+
}
91111
}

0 commit comments

Comments
 (0)