Skip to content

Commit

Permalink
fix(filefield): documentt upload with GLPI 9.5
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed Jul 13, 2020
1 parent 4880b95 commit 9658946
Show file tree
Hide file tree
Showing 21 changed files with 63 additions and 20 deletions.
5 changes: 5 additions & 0 deletions inc/fieldinterface.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public function getValueForDesign();
*/
public function getValueForTargetText($richText);

/**
* Move uploaded files and make Document items
*/
public function moveUploads();

/**
* Gets the documents IDs
*
Expand Down
1 change: 1 addition & 0 deletions inc/fields/actorfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ public function getValueForTargetText($richText) {
return $value;
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/checkboxesfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ public function getValueForTargetText($richText) {
return $value;
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/datefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public function hasInput($input) {
return isset($input['formcreator_field_' . $this->question->getID()]);
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/datetimefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public function getValueForTargetText($richText) {
return Toolbox::addslashes_deep(Html::convDateTime($this->value));
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];;
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/descriptionfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ public function getValueForTargetText($richText) {
return '';
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/dropdownfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ public function getValueForTargetText($richText) {
return $value;
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/emailfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public function getValueForTargetText($richText) {
return Toolbox::addslashes_deep($this->value);
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
39 changes: 19 additions & 20 deletions inc/fields/filefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,25 @@ public function getValueForTargetText($richText) {
return $this->value;
}

public function moveUploads()
{
$key = 'formcreator_field_' . $this->question->getID();
if (!is_array($this->uploads) || !isset($this->uploads["_$key"])) {
return;
}
$answer_value = [];
$index = 0;
foreach ($this->uploads["_$key"] as $document) {
$document = Toolbox::stripslashes_deep($document);
if (is_file(GLPI_TMP_DIR . '/' . $document)) {
$prefix = $this->uploads['_prefix_formcreator_field_' . $this->question->getID()][$index];
$answer_value[] = $this->saveDocument($document, $prefix);
}
$index++;
}
$this->uploadData = $answer_value;
}

public function getDocumentsForTarget() {
return $this->uploadData;
}
Expand Down Expand Up @@ -210,26 +229,6 @@ public function parseAnswerValues($input, $nonDestructive = false) {
return false;
}

if (PLUGIN_FORMCREATOR_TEXTAREA_FIX && version_compare(GLPI_VERSION, '9.5.0-dev') < 0) {
$answer_value = [];
$index = 0;
if ($nonDestructive) {
$index = count($input["_$key"]);
} else {
foreach ($input["_$key"] as $document) {
$document = Toolbox::stripslashes_deep($document);
if (is_file(GLPI_TMP_DIR . '/' . $document)) {
$prefix = $input['_prefix_formcreator_field_' . $this->question->getID()][$index];
$answer_value[] = $this->saveDocument($document, $prefix);
}
$index++;
}
}
$this->uploadData = $answer_value;
$this->value = __('Attached document', 'formcreator');

return true;
}
if ($this->hasInput($input)) {
$this->value = __('Attached document', 'formcreator');
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/floatfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public function getValueForTargetText($richText) {
return Toolbox::addslashes_deep($this->value);
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/hiddenfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public function hasInput($input) {
return isset($input['formcreator_field_' . $this->question->getID()]);
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/hostnamefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public function hasInput($input) {
return false;
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/integerfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public function getValueForTargetText($richText) {
return Toolbox::addslashes_deep($this->value);
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/ipfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ public function getValueForTargetText($richText) {
return Toolbox::addslashes_deep($this->value);
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/multiselectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ public function getValueForTargetText($richText) {
return $value;
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/radiosfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ public function getValueForTargetText($richText) {
return $this->value;
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/requesttypefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public function getValueForTargetText($richText) {
return $available[$this->value];
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/textfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public function getValueForTargetText($richText) {
return $this->value;
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/timefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ public function getValueForTargetText($richText) {
return Toolbox::addslashes_deep($date->format('H:i'));
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions inc/fields/urgencyfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ public function getValueForTargetText($richText) {
return $available[$this->value];
}

public function moveUploads() {}

public function getDocumentsForTarget() {
return [];
}
Expand Down
4 changes: 4 additions & 0 deletions inc/formanswer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class PluginFormcreatorFormAnswer extends CommonDBTM
const STATUS_REFUSED = 102;
const STATUS_ACCEPTED = 103;

/** @var $questionFields PluginFormcreatorField[] fields of the form answers */
private $questionFields = [];

private $questions = [];

public static function getStatuses() {
Expand Down Expand Up @@ -1105,7 +1107,9 @@ public function getFullForm($richText = false) {

public function post_addItem() {
// Save questions answers
/** @var PluginFormcreatorField $field */
foreach ($this->questionFields as $questionId => $field) {
$field->moveUploads();
$answer = new PluginFormcreatorAnswer();
$answer->add([
'plugin_formcreator_formanswers_id' => $this->getID(),
Expand Down

0 comments on commit 9658946

Please sign in to comment.