Skip to content

Commit

Permalink
fix(targetticket): harmonize comumns name and type wih glpi ticket it…
Browse files Browse the repository at this point in the history
…emtype

Signed-off-by: btry <tbugier@teclib.com>
  • Loading branch information
btry committed Sep 15, 2018
1 parent 1dd58b9 commit 9dc1da5
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 40 deletions.
6 changes: 3 additions & 3 deletions inc/form.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1406,8 +1406,8 @@ public function duplicate() {
foreach ($tab_questions as $id => $value) {
$update_target_ticket['name'] = str_replace('##question_' . $id . '##', '##question_' . $value . '##', $update_target_ticket['name']);
$update_target_ticket['name'] = str_replace('##answer_' . $id . '##', '##answer_' . $value . '##', $update_target_ticket['name']);
$update_target_ticket['comment'] = str_replace('##question_' . $id . '##', '##question_' . $value . '##', $update_target_ticket['comment']);
$update_target_ticket['comment'] = str_replace('##answer_' . $id . '##', '##answer_' . $value . '##', $update_target_ticket['comment']);
$update_target_ticket['content'] = str_replace('##question_' . $id . '##', '##question_' . $value . '##', $update_target_ticket['content']);
$update_target_ticket['content'] = str_replace('##answer_' . $id . '##', '##answer_' . $value . '##', $update_target_ticket['content']);
}

// update time to resolve rule
Expand Down Expand Up @@ -1439,7 +1439,7 @@ public function duplicate() {

$new_target_ticket = new PluginFormcreatorTargetTicket();
$update_target_ticket['title'] = Toolbox::addslashes_deep($update_target_ticket['name']);
$update_target_ticket['comment'] = Toolbox::addslashes_deep($update_target_ticket['comment']);
$update_target_ticket['content'] = Toolbox::addslashes_deep($update_target_ticket['content']);
if (!$new_target_ticket->update($update_target_ticket)) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/target.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function prepareInputForAdd($input) {
$targetticket = new PluginFormcreatorTargetTicket();
$id_targetticket = $targetticket->add([
'name' => $input['name'],
'comment' => '##FULLFORM##'
'content' => '##FULLFORM##'
]);
$input['items_id'] = $id_targetticket;

Expand Down
18 changes: 9 additions & 9 deletions inc/targetticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ public function showForm($options = []) {
echo '<tr class="line0">';
echo '<td><strong>' . __('Description') . ' <span style="color:red;">*</span></strong></td>';
echo '<td colspan="3">';
echo '<textarea name="comment" style="width:700px;" rows="15">' . $this->fields['comment'] . '</textarea>';
echo '<textarea name="content" style="width:700px;" rows="15">' . $this->fields['content'] . '</textarea>';
if (version_compare(PluginFormcreatorCommon::getGlpiVersion(), 9.4) >= 0 || $CFG_GLPI["use_rich_text"]) {
Html::initEditorSystem('comment');
Html::initEditorSystem('content');
}
echo '</td>';
echo '</tr>';
Expand Down Expand Up @@ -845,13 +845,13 @@ public function prepareInputForUpdate($input) {
}

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

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

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

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

$content = $target_data['comment'];
$content = $target_data['content'];
$content = str_replace("##question_$uuid##", "##question_$id##", $content);
$content = str_replace("##answer_$uuid##", "##answer_$id##", $content);
$target_data['comment'] = $content;
$target_data['content'] = $content;
}
}

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

$content = $target_data['comment'];
$content = $target_data['content'];
$content = str_replace("##question_$id##", "##question_$uuid##", $content);
$content = str_replace("##answer_$id##", "##answer_$uuid##", $content);
$target_data['comment'] = $content;
$target_data['content'] = $content;
}
}

Expand Down
2 changes: 1 addition & 1 deletion install/mysql/plugin_formcreator_empty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targettickets` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL DEFAULT '',
`tickettemplates_id` int(11) DEFAULT NULL,
`comment` text,
`content` longtext,
`due_date_rule` enum('answer','ticket','calcul') DEFAULT NULL,
`due_date_question` int(11) DEFAULT NULL,
`due_date_value` tinyint(4) DEFAULT NULL,
Expand Down
3 changes: 3 additions & 0 deletions install/update_2.6_2.7.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,7 @@ function plugin_formcreator_update_2_7(Migration $migration) {
$migration->changeField($table, 'backoutplancontent', 'backoutplancontent', 'longtext');
$migration->changeField($table, 'checklistcontent', 'checklistcontent', 'longtext');

// Update target target columns
$table = 'glpi_plugin_formcreator_targettickets';
$migration->changeField($table, 'comment', 'content', 'longtext');
}
2 changes: 1 addition & 1 deletion tests/src/CommonTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ protected function _checkTarget($target = []) {
protected function _checkTargetTicket($targetticket = []) {
$keys = [
'title',
'comment',
'content',
'due_date_rule',
'due_date_question',
'due_date_value',
Expand Down
2 changes: 2 additions & 0 deletions tests/suite-integration/PluginFormcreatorTargetTicket.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,15 @@ public function testUrgency() {
$targetTicketsData = [
[
'name' => 'target 1',
'content' => '##FULLFORM##',
'itemtype' => 'PluginFormcreatorTargetTicket',
'urgency_rule' => 'answer',
'urgency_question' => 'custom urgency',
'expected' => 5
],
[
'name' => 'target 2',
'content' => '##FULLFORM##',
'itemtype' => 'PluginFormcreatorTargetTicket',
'urgency_rule' => 'none',
'urgency_question' => '',
Expand Down
68 changes: 43 additions & 25 deletions tests/suite-unit/PluginFormcreatorForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,31 +225,49 @@ public function testExportForm() {
$item_targetTicket = new \PluginFormcreatorItem_TargetTicket();

// create objects
$forms_id = $form->add(['name' => "test export form",
'is_active' => true,
'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER]);
$sections_id = $form_section->add(['name' => "test export section",
'plugin_formcreator_forms_id' => $forms_id]);
$questions_id_1 = $form_question->add(['name' => "test export question 1",
'fieldtype' => 'text',
'plugin_formcreator_sections_id' => $sections_id]);
$questions_id_2 = $form_question->add(['name' => "test export question 2",
'fieldtype' => 'textarea',
'plugin_formcreator_sections_id' => $sections_id]);
$form_condition->add(['plugin_formcreator_questions_id' => $questions_id_1,
'show_field' => $questions_id_2,
'show_condition' => '==',
'show_value' => 'test']);
$form_validator->add(['plugin_formcreator_forms_id' => $forms_id,
'itemtype' => 'User',
'items_id' => 2]);
$form_validator->add(['plugin_formcreator_forms_id' => $forms_id,
'itemtype' => 'User',
'items_id' => 3]);
$targets_id = $form_target->add(['plugin_formcreator_forms_id' => $forms_id,
'itemtype' => \PluginFormcreatorTargetTicket::class,
'name' => "test export target"]);
$targetTicket_id = $targetTicket->add(['name' => $form_target->getField('name'),
$forms_id = $form->add([
'name' => "test export form",
'is_active' => true,
'validation_required' => \PluginFormcreatorForm_Validator::VALIDATION_USER
]);
$sections_id = $form_section->add([
'name' => "test export section",
'plugin_formcreator_forms_id' => $forms_id
]);
$questions_id_1 = $form_question->add([
'name' => "test export question 1",
'fieldtype' => 'text',
'plugin_formcreator_sections_id' => $sections_id
]);
$questions_id_2 = $form_question->add([
'name' => "test export question 2",
'fieldtype' => 'textarea',
'plugin_formcreator_sections_id' => $sections_id
]);
$form_condition->add([
'plugin_formcreator_questions_id' => $questions_id_1,
'show_field' => $questions_id_2,
'show_condition' => '==',
'show_value' => 'test'
]);
$form_validator->add([
'plugin_formcreator_forms_id' => $forms_id,
'itemtype' => 'User',
'items_id' => 2
]);
$form_validator->add([
'plugin_formcreator_forms_id' => $forms_id,
'itemtype' => 'User',
'items_id' => 3
]);
$targets_id = $form_target->add([
'plugin_formcreator_forms_id' => $forms_id,
'itemtype' => \PluginFormcreatorTargetTicket::class,
'name' => "test export target"
]);
$targetTicket_id = $targetTicket->add([
'name' => $form_target->getField('name'),
'content' => '##FULLFORM##'
]);
$form_target->getFromDB($targets_id);
$targettickets_id = $form_target->fields['items_id'];
Expand Down

0 comments on commit 9dc1da5

Please sign in to comment.