Skip to content

Commit 9658946

Browse files
committed
fix(filefield): documentt upload with GLPI 9.5
Signed-off-by: Thierry Bugier <[email protected]>
1 parent 4880b95 commit 9658946

21 files changed

+63
-20
lines changed

inc/fieldinterface.class.php

+5
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ public function getValueForDesign();
9999
*/
100100
public function getValueForTargetText($richText);
101101

102+
/**
103+
* Move uploaded files and make Document items
104+
*/
105+
public function moveUploads();
106+
102107
/**
103108
* Gets the documents IDs
104109
*

inc/fields/actorfield.class.php

+1
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ public function getValueForTargetText($richText) {
200200
return $value;
201201
}
202202

203+
public function moveUploads() {}
203204

204205
public function getDocumentsForTarget() {
205206
return [];

inc/fields/checkboxesfield.class.php

+2
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ public function getValueForTargetText($richText) {
269269
return $value;
270270
}
271271

272+
public function moveUploads() {}
273+
272274
public function getDocumentsForTarget() {
273275
return [];
274276
}

inc/fields/datefield.class.php

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public function hasInput($input) {
7474
return isset($input['formcreator_field_' . $this->question->getID()]);
7575
}
7676

77+
public function moveUploads() {}
78+
7779
public function getDocumentsForTarget() {
7880
return [];
7981
}

inc/fields/datetimefield.class.php

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public function getValueForTargetText($richText) {
7777
return Toolbox::addslashes_deep(Html::convDateTime($this->value));
7878
}
7979

80+
public function moveUploads() {}
81+
8082
public function getDocumentsForTarget() {
8183
return [];;
8284
}

inc/fields/descriptionfield.class.php

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ public function getValueForTargetText($richText) {
7070
return '';
7171
}
7272

73+
public function moveUploads() {}
74+
7375
public function getDocumentsForTarget() {
7476
return [];
7577
}

inc/fields/dropdownfield.class.php

+2
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ public function getValueForTargetText($richText) {
325325
return $value;
326326
}
327327

328+
public function moveUploads() {}
329+
328330
public function getDocumentsForTarget() {
329331
return [];
330332
}

inc/fields/emailfield.class.php

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public function getValueForTargetText($richText) {
8181
return Toolbox::addslashes_deep($this->value);
8282
}
8383

84+
public function moveUploads() {}
85+
8486
public function getDocumentsForTarget() {
8587
return [];
8688
}

inc/fields/filefield.class.php

+19-20
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,25 @@ public function getValueForTargetText($richText) {
9090
return $this->value;
9191
}
9292

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

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

inc/fields/floatfield.class.php

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public function getValueForTargetText($richText) {
115115
return Toolbox::addslashes_deep($this->value);
116116
}
117117

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

inc/fields/hiddenfield.class.php

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public function hasInput($input) {
107107
return isset($input['formcreator_field_' . $this->question->getID()]);
108108
}
109109

110+
public function moveUploads() {}
111+
110112
public function getDocumentsForTarget() {
111113
return [];
112114
}

inc/fields/hostnamefield.class.php

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public function hasInput($input) {
5454
return false;
5555
}
5656

57+
public function moveUploads() {}
58+
5759
public function getDocumentsForTarget() {
5860
return [];
5961
}

inc/fields/integerfield.class.php

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public function getValueForTargetText($richText) {
115115
return Toolbox::addslashes_deep($this->value);
116116
}
117117

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

inc/fields/ipfield.class.php

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ public function getValueForTargetText($richText) {
8787
return Toolbox::addslashes_deep($this->value);
8888
}
8989

90+
public function moveUploads() {}
91+
9092
public function getDocumentsForTarget() {
9193
return [];
9294
}

inc/fields/multiselectfield.class.php

+2
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ public function getValueForTargetText($richText) {
239239
return $value;
240240
}
241241

242+
public function moveUploads() {}
243+
242244
public function getDocumentsForTarget() {
243245
return [];
244246
}

inc/fields/radiosfield.class.php

+2
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ public function getValueForTargetText($richText) {
216216
return $this->value;
217217
}
218218

219+
public function moveUploads() {}
220+
219221
public function getDocumentsForTarget() {
220222
return [];
221223
}

inc/fields/requesttypefield.class.php

+2
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

+2
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ public function getValueForTargetText($richText) {
115115
return $this->value;
116116
}
117117

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

inc/fields/timefield.class.php

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ public function getValueForTargetText($richText) {
128128
return Toolbox::addslashes_deep($date->format('H:i'));
129129
}
130130

131+
public function moveUploads() {}
132+
131133
public function getDocumentsForTarget() {
132134
return [];
133135
}

inc/fields/urgencyfield.class.php

+2
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ public function getValueForTargetText($richText) {
163163
return $available[$this->value];
164164
}
165165

166+
public function moveUploads() {}
167+
166168
public function getDocumentsForTarget() {
167169
return [];
168170
}

inc/formanswer.class.php

+4
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() {
@@ -1105,7 +1107,9 @@ public function getFullForm($richText = false) {
11051107

11061108
public function post_addItem() {
11071109
// Save questions answers
1110+
/** @var PluginFormcreatorField $field */
11081111
foreach ($this->questionFields as $questionId => $field) {
1112+
$field->moveUploads();
11091113
$answer = new PluginFormcreatorAnswer();
11101114
$answer->add([
11111115
'plugin_formcreator_formanswers_id' => $this->getID(),

0 commit comments

Comments
 (0)