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 108984b commit 2b48e82
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 @@ -107,6 +107,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 @@ -205,6 +205,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 @@ -287,6 +287,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 @@ -113,6 +113,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 @@ -116,6 +116,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 @@ -68,6 +68,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 @@ -346,6 +346,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 @@ -87,6 +87,8 @@ public function getRenderedHtml($canEdit = true) {
return $html;
}

public function moveUploads() {}

public function isValidValue($value) {
if ($value === '') {
return true;
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 @@ -92,6 +92,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 @@ -215,26 +234,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 @@ -118,6 +118,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 @@ -111,6 +111,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 @@ -58,6 +58,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 @@ -39,6 +39,8 @@ public function serializeValue() {
return strval((int) $this->value);
}

public function moveUploads() {}

public function isValidValue($value) {
if (strlen($value) == 0) {
return true;
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 @@ -91,6 +91,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 @@ -66,6 +66,8 @@ public function hasInput($input) {
return isset($input['formcreator_field_' . $this->question->getID()]);
}

public function moveUploads() {}

public static function getName() {
return __('Multiselect', 'formcreator');
}
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 @@ -209,6 +209,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 @@ -123,6 +123,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/timefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,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 @@ -168,6 +168,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 @@ -1091,7 +1093,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 2b48e82

Please sign in to comment.