Skip to content

Commit 2b48e82

Browse files
committed
fix(filefield): documentt upload with GLPI 9.5
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
1 parent 108984b commit 2b48e82

21 files changed

+63
-20
lines changed

inc/fieldinterface.class.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ public function getValueForDesign();
107107
*/
108108
public function getValueForTargetText($richText);
109109

110+
/**
111+
* Move uploaded files and make Document items
112+
*/
113+
public function moveUploads();
114+
110115
/**
111116
* Gets the documents IDs
112117
*

inc/fields/actorfield.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ public function getValueForTargetText($richText) {
205205
return $value;
206206
}
207207

208+
public function moveUploads() {}
208209

209210
public function getDocumentsForTarget() {
210211
return [];

inc/fields/checkboxesfield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ public function getValueForTargetText($richText) {
287287
return $value;
288288
}
289289

290+
public function moveUploads() {}
291+
290292
public function getDocumentsForTarget() {
291293
return [];
292294
}

inc/fields/datefield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ public function hasInput($input) {
113113
return isset($input['formcreator_field_' . $this->question->getID()]);
114114
}
115115

116+
public function moveUploads() {}
117+
116118
public function getDocumentsForTarget() {
117119
return [];
118120
}

inc/fields/datetimefield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ public function getValueForTargetText($richText) {
116116
return Toolbox::addslashes_deep(Html::convDateTime($this->value));
117117
}
118118

119+
public function moveUploads() {}
120+
119121
public function getDocumentsForTarget() {
120122
return [];;
121123
}

inc/fields/descriptionfield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public function getValueForTargetText($richText) {
6868
return '';
6969
}
7070

71+
public function moveUploads() {}
72+
7173
public function getDocumentsForTarget() {
7274
return [];
7375
}

inc/fields/dropdownfield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ public function getValueForTargetText($richText) {
346346
return $value;
347347
}
348348

349+
public function moveUploads() {}
350+
349351
public function getDocumentsForTarget() {
350352
return [];
351353
}

inc/fields/emailfield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public function getRenderedHtml($canEdit = true) {
8787
return $html;
8888
}
8989

90+
public function moveUploads() {}
91+
9092
public function isValidValue($value) {
9193
if ($value === '') {
9294
return true;

inc/fields/filefield.class.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,25 @@ public function getValueForTargetText($richText) {
9292
return $this->value;
9393
}
9494

95+
public function moveUploads()
96+
{
97+
$key = 'formcreator_field_' . $this->question->getID();
98+
if (!is_array($this->uploads) || !isset($this->uploads["_$key"])) {
99+
return;
100+
}
101+
$answer_value = [];
102+
$index = 0;
103+
foreach ($this->uploads["_$key"] as $document) {
104+
$document = Toolbox::stripslashes_deep($document);
105+
if (is_file(GLPI_TMP_DIR . '/' . $document)) {
106+
$prefix = $this->uploads['_prefix_formcreator_field_' . $this->question->getID()][$index];
107+
$answer_value[] = $this->saveDocument($document, $prefix);
108+
}
109+
$index++;
110+
}
111+
$this->uploadData = $answer_value;
112+
}
113+
95114
public function getDocumentsForTarget() {
96115
return $this->uploadData;
97116
}
@@ -215,26 +234,6 @@ public function parseAnswerValues($input, $nonDestructive = false) {
215234
return false;
216235
}
217236

218-
if (PLUGIN_FORMCREATOR_TEXTAREA_FIX && version_compare(GLPI_VERSION, '9.5.0-dev') < 0) {
219-
$answer_value = [];
220-
$index = 0;
221-
if ($nonDestructive) {
222-
$index = count($input["_$key"]);
223-
} else {
224-
foreach ($input["_$key"] as $document) {
225-
$document = Toolbox::stripslashes_deep($document);
226-
if (is_file(GLPI_TMP_DIR . '/' . $document)) {
227-
$prefix = $input['_prefix_formcreator_field_' . $this->question->getID()][$index];
228-
$answer_value[] = $this->saveDocument($document, $prefix);
229-
}
230-
$index++;
231-
}
232-
}
233-
$this->uploadData = $answer_value;
234-
$this->value = __('Attached document', 'formcreator');
235-
236-
return true;
237-
}
238237
if ($this->hasInput($input)) {
239238
$this->value = __('Attached document', 'formcreator');
240239
}

inc/fields/floatfield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ public function getValueForTargetText($richText) {
118118
return Toolbox::addslashes_deep($this->value);
119119
}
120120

121+
public function moveUploads() {}
122+
121123
public function getDocumentsForTarget() {
122124
return [];
123125
}

inc/fields/hiddenfield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ public function hasInput($input) {
111111
return isset($input['formcreator_field_' . $this->question->getID()]);
112112
}
113113

114+
public function moveUploads() {}
115+
114116
public function getDocumentsForTarget() {
115117
return [];
116118
}

inc/fields/hostnamefield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public function hasInput($input) {
5858
return false;
5959
}
6060

61+
public function moveUploads() {}
62+
6163
public function getDocumentsForTarget() {
6264
return [];
6365
}

inc/fields/integerfield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public function serializeValue() {
3939
return strval((int) $this->value);
4040
}
4141

42+
public function moveUploads() {}
43+
4244
public function isValidValue($value) {
4345
if (strlen($value) == 0) {
4446
return true;

inc/fields/ipfield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ public function getValueForTargetText($richText) {
9191
return Toolbox::addslashes_deep($this->value);
9292
}
9393

94+
public function moveUploads() {}
95+
9496
public function getDocumentsForTarget() {
9597
return [];
9698
}

inc/fields/multiselectfield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public function hasInput($input) {
6666
return isset($input['formcreator_field_' . $this->question->getID()]);
6767
}
6868

69+
public function moveUploads() {}
70+
6971
public static function getName() {
7072
return __('Multiselect', 'formcreator');
7173
}

inc/fields/radiosfield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ public function getValueForTargetText($richText) {
209209
return $this->value;
210210
}
211211

212+
public function moveUploads() {}
213+
212214
public function getDocumentsForTarget() {
213215
return [];
214216
}

inc/fields/requesttypefield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ public function getValueForTargetText($richText) {
156156
return $available[$this->value];
157157
}
158158

159+
public function moveUploads() {}
160+
159161
public function getDocumentsForTarget() {
160162
return [];
161163
}

inc/fields/textfield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ public function getValueForTargetText($richText) {
123123
return Toolbox::addslashes_deep($this->value);
124124
}
125125

126+
public function moveUploads() {}
127+
126128
public function getDocumentsForTarget() {
127129
return [];
128130
}

inc/fields/timefield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ public function getValueForTargetText($richText) {
131131
return Toolbox::addslashes_deep($date->format('H:i'));
132132
}
133133

134+
public function moveUploads() {}
135+
134136
public function getDocumentsForTarget() {
135137
return [];
136138
}

inc/fields/urgencyfield.class.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ public function getValueForTargetText($richText) {
168168
return $available[$this->value];
169169
}
170170

171+
public function moveUploads() {}
172+
171173
public function getDocumentsForTarget() {
172174
return [];
173175
}

inc/formanswer.class.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class PluginFormcreatorFormAnswer extends CommonDBTM
4949
const STATUS_REFUSED = 102;
5050
const STATUS_ACCEPTED = 103;
5151

52+
/** @var $questionFields PluginFormcreatorField[] fields of the form answers */
5253
private $questionFields = [];
54+
5355
private $questions = [];
5456

5557
public static function getStatuses() {
@@ -1091,7 +1093,9 @@ public function getFullForm($richText = false) {
10911093

10921094
public function post_addItem() {
10931095
// Save questions answers
1096+
/** @var PluginFormcreatorField $field */
10941097
foreach ($this->questionFields as $questionId => $field) {
1098+
$field->moveUploads();
10951099
$answer = new PluginFormcreatorAnswer();
10961100
$answer->add([
10971101
'plugin_formcreator_formanswers_id' => $this->getID(),

0 commit comments

Comments
 (0)