Skip to content

Commit 9658946

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

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
@@ -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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 19 additions & 20 deletions
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

Lines changed: 2 additions & 0 deletions
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
}

0 commit comments

Comments
 (0)