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
}

0 commit comments

Comments
 (0)