FIX src_object_id and ttype not filed when uploading a file with API.

This commit is contained in:
Laurent Destailleur
2023-10-31 00:46:53 +01:00
parent ad1c363aa6
commit 85d36ddc58
2 changed files with 39 additions and 6 deletions

View File

@@ -580,7 +580,9 @@ class Documents extends DolibarrApi
} elseif (is_array($ecmfile->lines) && count($ecmfile->lines) > 0) {
$count = count($filearray);
for ($i = 0 ; $i < $count ; $i++) {
if ($filearray[$i]['name'] == $ecmfile->lines[$i]->filename) $filearray[$i] = array_merge($filearray[$i], (array) $ecmfile->lines[0]);
if ($filearray[$i]['name'] == $ecmfile->lines[$i]->filename) {
$filearray[$i] = array_merge($filearray[$i], (array) $ecmfile->lines[0]);
}
}
}
}
@@ -638,6 +640,8 @@ class Documents extends DolibarrApi
//var_dump($filename);
//var_dump($filecontent);exit;
$modulepartorig = $modulepart;
if (empty($modulepart)) {
throw new RestException(400, 'Modulepart not provided.');
}
@@ -875,7 +879,14 @@ class Documents extends DolibarrApi
throw new RestException(500, "Refused to deliver file ".$dest_file);
}
$result = dol_move($destfiletmp, $dest_file, 0, $overwriteifexists, 1, 1);
$moreinfo = array('note_private' => 'File uploaded using API /documents from IP '.getUserRemoteIP());
if (!empty($object) && is_object($object) && $object->id > 0) {
$moreinfo['src_object_type'] = $modulepartorig;
$moreinfo['src_object_id'] = $object->id;
}
// Move the temporary file at its final emplacement
$result = dol_move($destfiletmp, $dest_file, 0, $overwriteifexists, 1, 1, $moreinfo);
if (!$result) {
throw new RestException(500, "Failed to move file into '".$destfile."'");
}