Skip to content

Commit 666d813

Browse files
committed
fix(textareadifield): error when deduplicating uploads
1 parent 3f51fbd commit 666d813

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

inc/field/textareafield.class.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ public function serializeValue(PluginFormcreatorFormAnswer $formanswer): string
191191
$key = 'formcreator_field_' . $this->question->getID();
192192
if (isset($this->uploads['_' . $key])) {
193193
$input = [$key => $this->value] + $this->uploads;
194+
// for each uploaded document, check if it already exists in DB
195+
foreach ($this->uploads['_tag_' . $key] as $docKey => $tag) {
196+
$document = new Document();
197+
$newTag = $tag;
198+
if ($document->getDuplicateOf($formanswer->fields['entities_id'], GLPI_TMP_DIR . '/' . $input['_' . $key][$docKey])) {
199+
$newTag = $document->fields['tag'];
200+
}
201+
$this->uploads['dedup'][$tag] = $newTag;
202+
}
194203
$input = $formanswer->addFiles(
195204
$input,
196205
[
@@ -203,11 +212,7 @@ public function serializeValue(PluginFormcreatorFormAnswer $formanswer): string
203212
// $this->value = $input[$key];
204213
$this->value = Sanitizer::unsanitize($this->value);
205214
foreach ($input['_tag'] as $docKey => $tag) {
206-
$document = new Document();
207-
$newTag = $tag;
208-
if ($document->getDuplicateOf($formanswer->fields['entities_id'], GLPI_TMP_DIR . '/' . $input['_' . $key][$docKey])) {
209-
$newTag = $document->fields['tag'];
210-
}
215+
$newTag = $this->uploads['dedup'][$tag];
211216
$regex = '/<img[^>]+' . preg_quote($tag, '/') . '[^<]+>/im';
212217
$this->value = preg_replace($regex, "#$newTag#", $this->value);
213218
}

0 commit comments

Comments
 (0)