Skip to content

Commit 9dc1da5

Browse files
committed
fix(targetticket): harmonize comumns name and type wih glpi ticket itemtype
Signed-off-by: btry <tbugier@teclib.com>
1 parent 1dd58b9 commit 9dc1da5

File tree

8 files changed

+63
-40
lines changed

8 files changed

+63
-40
lines changed

inc/form.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,8 +1406,8 @@ public function duplicate() {
14061406
foreach ($tab_questions as $id => $value) {
14071407
$update_target_ticket['name'] = str_replace('##question_' . $id . '##', '##question_' . $value . '##', $update_target_ticket['name']);
14081408
$update_target_ticket['name'] = str_replace('##answer_' . $id . '##', '##answer_' . $value . '##', $update_target_ticket['name']);
1409-
$update_target_ticket['comment'] = str_replace('##question_' . $id . '##', '##question_' . $value . '##', $update_target_ticket['comment']);
1410-
$update_target_ticket['comment'] = str_replace('##answer_' . $id . '##', '##answer_' . $value . '##', $update_target_ticket['comment']);
1409+
$update_target_ticket['content'] = str_replace('##question_' . $id . '##', '##question_' . $value . '##', $update_target_ticket['content']);
1410+
$update_target_ticket['content'] = str_replace('##answer_' . $id . '##', '##answer_' . $value . '##', $update_target_ticket['content']);
14111411
}
14121412

14131413
// update time to resolve rule
@@ -1439,7 +1439,7 @@ public function duplicate() {
14391439

14401440
$new_target_ticket = new PluginFormcreatorTargetTicket();
14411441
$update_target_ticket['title'] = Toolbox::addslashes_deep($update_target_ticket['name']);
1442-
$update_target_ticket['comment'] = Toolbox::addslashes_deep($update_target_ticket['comment']);
1442+
$update_target_ticket['content'] = Toolbox::addslashes_deep($update_target_ticket['content']);
14431443
if (!$new_target_ticket->update($update_target_ticket)) {
14441444
return false;
14451445
}

inc/target.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function prepareInputForAdd($input) {
153153
$targetticket = new PluginFormcreatorTargetTicket();
154154
$id_targetticket = $targetticket->add([
155155
'name' => $input['name'],
156-
'comment' => '##FULLFORM##'
156+
'content' => '##FULLFORM##'
157157
]);
158158
$input['items_id'] = $id_targetticket;
159159

inc/targetticket.class.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ public function showForm($options = []) {
116116
echo '<tr class="line0">';
117117
echo '<td><strong>' . __('Description') . ' <span style="color:red;">*</span></strong></td>';
118118
echo '<td colspan="3">';
119-
echo '<textarea name="comment" style="width:700px;" rows="15">' . $this->fields['comment'] . '</textarea>';
119+
echo '<textarea name="content" style="width:700px;" rows="15">' . $this->fields['content'] . '</textarea>';
120120
if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI["use_rich_text"]) {
121-
Html::initEditorSystem('comment');
121+
Html::initEditorSystem('content');
122122
}
123123
echo '</td>';
124124
echo '</tr>';
@@ -845,13 +845,13 @@ public function prepareInputForUpdate($input) {
845845
}
846846

847847
// - comment is required
848-
if (empty($input['comment'])) {
848+
if (strlen($input['content']) < 1) {
849849
Session::addMessageAfterRedirect(__('The description cannot be empty!', 'formcreator'), false, ERROR);
850850
return [];
851851
}
852852

853853
if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI['use_rich_text']) {
854-
$input['comment'] = Html::entity_decode_deep($input['comment']);
854+
$input['content'] = Html::entity_decode_deep($input['content']);
855855
}
856856

857857
switch ($input['destination_entity']) {
@@ -1109,7 +1109,7 @@ public function save(PluginFormcreatorForm_Answer $formanswer) {
11091109
$data['name'] = addslashes($this->fields['name']);
11101110
$data['name'] = $this->parseTags($data['name'], $formanswer);
11111111

1112-
$data['content'] = addslashes($this->fields['comment']);
1112+
$data['content'] = addslashes($this->fields['content']);
11131113
$data['content'] = str_replace("\r\n", '\r\n', $data['content']);
11141114
if (strpos($data['content'], '##FULLFORM##') !== false) {
11151115
$data['content'] = str_replace('##FULLFORM##', $formanswer->getFullForm(), $data['content']);
@@ -1497,10 +1497,10 @@ public static function import($targetitems_id = 0, $target_data = []) {
14971497
$content = str_replace("##answer_$uuid##", "##answer_$id##", $content);
14981498
$target_data['name'] = $content;
14991499

1500-
$content = $target_data['comment'];
1500+
$content = $target_data['content'];
15011501
$content = str_replace("##question_$uuid##", "##question_$id##", $content);
15021502
$content = str_replace("##answer_$uuid##", "##answer_$id##", $content);
1503-
$target_data['comment'] = $content;
1503+
$target_data['content'] = $content;
15041504
}
15051505
}
15061506

@@ -1563,10 +1563,10 @@ public function export($remove_uuid = false) {
15631563
$content = str_replace("##answer_$id##", "##answer_$uuid##", $content);
15641564
$target_data['name'] = $content;
15651565

1566-
$content = $target_data['comment'];
1566+
$content = $target_data['content'];
15671567
$content = str_replace("##question_$id##", "##question_$uuid##", $content);
15681568
$content = str_replace("##answer_$id##", "##answer_$uuid##", $content);
1569-
$target_data['comment'] = $content;
1569+
$target_data['content'] = $content;
15701570
}
15711571
}
15721572

install/mysql/plugin_formcreator_empty.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targettickets` (
196196
`id` int(11) NOT NULL AUTO_INCREMENT,
197197
`name` varchar(255) NOT NULL DEFAULT '',
198198
`tickettemplates_id` int(11) DEFAULT NULL,
199-
`comment` text,
199+
`content` longtext,
200200
`due_date_rule` enum('answer','ticket','calcul') DEFAULT NULL,
201201
`due_date_question` int(11) DEFAULT NULL,
202202
`due_date_value` tinyint(4) DEFAULT NULL,

install/update_2.6_2.7.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,7 @@ function plugin_formcreator_update_2_7(Migration $migration) {
168168
$migration->changeField($table, 'backoutplancontent', 'backoutplancontent', 'longtext');
169169
$migration->changeField($table, 'checklistcontent', 'checklistcontent', 'longtext');
170170

171+
// Update target target columns
172+
$table = 'glpi_plugin_formcreator_targettickets';
173+
$migration->changeField($table, 'comment', 'content', 'longtext');
171174
}

tests/src/CommonTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ protected function _checkTarget($target = []) {
330330
protected function _checkTargetTicket($targetticket = []) {
331331
$keys = [
332332
'title',
333-
'comment',
333+
'content',
334334
'due_date_rule',
335335
'due_date_question',
336336
'due_date_value',

tests/suite-integration/PluginFormcreatorTargetTicket.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,15 @@ public function testUrgency() {
176176
$targetTicketsData = [
177177
[
178178
'name' => 'target 1',
179+
'content' => '##FULLFORM##',
179180
'itemtype' => 'PluginFormcreatorTargetTicket',
180181
'urgency_rule' => 'answer',
181182
'urgency_question' => 'custom urgency',
182183
'expected' => 5
183184
],
184185
[
185186
'name' => 'target 2',
187+
'content' => '##FULLFORM##',
186188
'itemtype' => 'PluginFormcreatorTargetTicket',
187189
'urgency_rule' => 'none',
188190
'urgency_question' => '',

tests/suite-unit/PluginFormcreatorForm.php

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -225,31 +225,49 @@ public function testExportForm() {
225225
$item_targetTicket = new \PluginFormcreatorItem_TargetTicket();
226226

227227
// create objects
228-
$forms_id = $form->add(['name' => "test export form",
229-
'is_active' => true,
230-
'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER]);
231-
$sections_id = $form_section->add(['name' => "test export section",
232-
'plugin_formcreator_forms_id' => $forms_id]);
233-
$questions_id_1 = $form_question->add(['name' => "test export question 1",
234-
'fieldtype' => 'text',
235-
'plugin_formcreator_sections_id' => $sections_id]);
236-
$questions_id_2 = $form_question->add(['name' => "test export question 2",
237-
'fieldtype' => 'textarea',
238-
'plugin_formcreator_sections_id' => $sections_id]);
239-
$form_condition->add(['plugin_formcreator_questions_id' => $questions_id_1,
240-
'show_field' => $questions_id_2,
241-
'show_condition' => '==',
242-
'show_value' => 'test']);
243-
$form_validator->add(['plugin_formcreator_forms_id' => $forms_id,
244-
'itemtype' => 'User',
245-
'items_id' => 2]);
246-
$form_validator->add(['plugin_formcreator_forms_id' => $forms_id,
247-
'itemtype' => 'User',
248-
'items_id' => 3]);
249-
$targets_id = $form_target->add(['plugin_formcreator_forms_id' => $forms_id,
250-
'itemtype' => \PluginFormcreatorTargetTicket::class,
251-
'name' => "test export target"]);
252-
$targetTicket_id = $targetTicket->add(['name' => $form_target->getField('name'),
228+
$forms_id = $form->add([
229+
'name' => "test export form",
230+
'is_active' => true,
231+
'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER
232+
]);
233+
$sections_id = $form_section->add([
234+
'name' => "test export section",
235+
'plugin_formcreator_forms_id' => $forms_id
236+
]);
237+
$questions_id_1 = $form_question->add([
238+
'name' => "test export question 1",
239+
'fieldtype' => 'text',
240+
'plugin_formcreator_sections_id' => $sections_id
241+
]);
242+
$questions_id_2 = $form_question->add([
243+
'name' => "test export question 2",
244+
'fieldtype' => 'textarea',
245+
'plugin_formcreator_sections_id' => $sections_id
246+
]);
247+
$form_condition->add([
248+
'plugin_formcreator_questions_id' => $questions_id_1,
249+
'show_field' => $questions_id_2,
250+
'show_condition' => '==',
251+
'show_value' => 'test'
252+
]);
253+
$form_validator->add([
254+
'plugin_formcreator_forms_id' => $forms_id,
255+
'itemtype' => 'User',
256+
'items_id' => 2
257+
]);
258+
$form_validator->add([
259+
'plugin_formcreator_forms_id' => $forms_id,
260+
'itemtype' => 'User',
261+
'items_id' => 3
262+
]);
263+
$targets_id = $form_target->add([
264+
'plugin_formcreator_forms_id' => $forms_id,
265+
'itemtype' => \PluginFormcreatorTargetTicket::class,
266+
'name' => "test export target"
267+
]);
268+
$targetTicket_id = $targetTicket->add([
269+
'name' => $form_target->getField('name'),
270+
'content' => '##FULLFORM##'
253271
]);
254272
$form_target->getFromDB($targets_id);
255273
$targettickets_id = $form_target->fields['items_id'];

0 commit comments

Comments
 (0)