FIX src_object_id and ttype not filed when uploading a file with API.
This commit is contained in:
parent
ad1c363aa6
commit
85d36ddc58
2 changed files with 39 additions and 6 deletions
|
|
@ -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."'");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -941,10 +941,11 @@ function dolCopyDir($srcfile, $destfile, $newmask, $overwriteifexists, $arrayrep
|
|||
* @param int $overwriteifexists Overwrite file if exists (1 by default)
|
||||
* @param int $testvirus Do an antivirus test. Move is canceled if a virus is found.
|
||||
* @param int $indexdatabase Index new file into database.
|
||||
* @param int $moreinfo Array with more information
|
||||
* @return boolean True if OK, false if KO
|
||||
* @see dol_move_uploaded_file()
|
||||
*/
|
||||
function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1)
|
||||
function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $testvirus = 0, $indexdatabase = 1, $moreinfo = array())
|
||||
{
|
||||
global $user, $db, $conf;
|
||||
$result = false;
|
||||
|
|
@ -1037,9 +1038,30 @@ function dol_move($srcfile, $destfile, $newmask = 0, $overwriteifexists = 1, $te
|
|||
$ecmfile->filename = $filename;
|
||||
$ecmfile->label = md5_file(dol_osencode($destfile)); // $destfile is a full path to file
|
||||
$ecmfile->fullpath_orig = $srcfile;
|
||||
$ecmfile->gen_or_uploaded = 'unknown';
|
||||
$ecmfile->description = ''; // indexed content
|
||||
$ecmfile->keywords = ''; // keyword content
|
||||
$ecmfile->gen_or_uploaded = 'upload';
|
||||
if (!empty($moreinfo) && !empty($moreinfo['description'])) {
|
||||
$ecmfile->description = $moreinfo['description']; // indexed content
|
||||
} else {
|
||||
$ecmfile->description = ''; // indexed content
|
||||
}
|
||||
if (!empty($moreinfo) && !empty($moreinfo['keywords'])) {
|
||||
$ecmfile->keywords = $moreinfo['keywords']; // indexed content
|
||||
} else {
|
||||
$ecmfile->keywords = ''; // keyword content
|
||||
}
|
||||
if (!empty($moreinfo) && !empty($moreinfo['note_private'])) {
|
||||
$ecmfile->note_private = $moreinfo['note_private'];
|
||||
}
|
||||
if (!empty($moreinfo) && !empty($moreinfo['note_public'])) {
|
||||
$ecmfile->note_public = $moreinfo['note_public'];
|
||||
}
|
||||
if (!empty($moreinfo) && !empty($moreinfo['src_object_type'])) {
|
||||
$ecmfile->src_object_type = $moreinfo['src_object_type'];
|
||||
}
|
||||
if (!empty($moreinfo) && !empty($moreinfo['src_object_id'])) {
|
||||
$ecmfile->src_object_id = $moreinfo['src_object_id'];
|
||||
}
|
||||
|
||||
$resultecm = $ecmfile->create($user);
|
||||
if ($resultecm < 0) {
|
||||
setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
|
||||
|
|
|
|||
Loading…
Reference in a new issue