NEW : Fill ECM src object fields in dol_add_file_process

This commit is contained in:
ATM-Nicolas 2020-10-14 16:59:05 +02:00
parent fe19eea540
commit 98eb11be62
2 changed files with 13 additions and 5 deletions

View File

@ -56,10 +56,10 @@ if (GETPOST('sendit', 'alpha') && !empty($conf->global->MAIN_UPLOAD_DOC))
if (!empty($upload_dirold) && !empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO)) if (!empty($upload_dirold) && !empty($conf->global->PRODUCT_USE_OLD_PATH_FOR_PHOTO))
{ {
$result = dol_add_file_process($upload_dirold, $allowoverwrite, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs); $result = dol_add_file_process($upload_dirold, $allowoverwrite, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs, $object);
} elseif (!empty($upload_dir)) } elseif (!empty($upload_dir))
{ {
$result = dol_add_file_process($upload_dir, $allowoverwrite, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs); $result = dol_add_file_process($upload_dir, $allowoverwrite, 1, 'userfile', GETPOST('savingdocmask', 'alpha'), null, '', $generatethumbs, $object);
} }
} }
} }

View File

@ -1506,9 +1506,10 @@ function dol_init_file_process($pathtoscan = '', $trackid = '')
* @param string $link Link to add (to add a link instead of a file) * @param string $link Link to add (to add a link instead of a file)
* @param string $trackid Track id (used to prefix name of session vars to avoid conflict) * @param string $trackid Track id (used to prefix name of session vars to avoid conflict)
* @param int $generatethumbs 1=Generate also thumbs for uploaded image files * @param int $generatethumbs 1=Generate also thumbs for uploaded image files
* @param Object $object Object used to set 'src_object_*' fields
* @return int <=0 if KO, >0 if OK * @return int <=0 if KO, >0 if OK
*/ */
function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesession = 0, $varfiles = 'addedfile', $savingdocmask = '', $link = null, $trackid = '', $generatethumbs = 1) function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesession = 0, $varfiles = 'addedfile', $savingdocmask = '', $link = null, $trackid = '', $generatethumbs = 1, $object = null)
{ {
global $db, $user, $conf, $langs; global $db, $user, $conf, $langs;
@ -1602,7 +1603,7 @@ function dol_add_file_process($upload_dir, $allowoverwrite = 0, $donotupdatesess
// Update index table of files (llx_ecm_files) // Update index table of files (llx_ecm_files)
if ($donotupdatesession == 1) if ($donotupdatesession == 1)
{ {
$result = addFileIntoDatabaseIndex($upload_dir, basename($destfile).($resupload == 2 ? '.noexe' : ''), $TFile['name'][$i], 'uploaded', 0); $result = addFileIntoDatabaseIndex($upload_dir, basename($destfile).($resupload == 2 ? '.noexe' : ''), $TFile['name'][$i], 'uploaded', 0, $object);
if ($result < 0) if ($result < 0)
{ {
if ($allowoverwrite) { if ($allowoverwrite) {
@ -1718,9 +1719,10 @@ function dol_remove_file_process($filenb, $donotupdatesession = 0, $donotdeletef
* @param string $fullpathorig Full path of origin for file (can be '') * @param string $fullpathorig Full path of origin for file (can be '')
* @param string $mode How file was created ('uploaded', 'generated', ...) * @param string $mode How file was created ('uploaded', 'generated', ...)
* @param int $setsharekey Set also the share key * @param int $setsharekey Set also the share key
* @param Object $object Object used to set 'src_object_*' fields
* @return int <0 if KO, 0 if nothing done, >0 if OK * @return int <0 if KO, 0 if nothing done, >0 if OK
*/ */
function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uploaded', $setsharekey = 0) function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uploaded', $setsharekey = 0, $object = null)
{ {
global $db, $user; global $db, $user;
@ -1743,6 +1745,12 @@ function addFileIntoDatabaseIndex($dir, $file, $fullpathorig = '', $mode = 'uplo
$ecmfile->gen_or_uploaded = $mode; $ecmfile->gen_or_uploaded = $mode;
$ecmfile->description = ''; // indexed content $ecmfile->description = ''; // indexed content
$ecmfile->keyword = ''; // keyword content $ecmfile->keyword = ''; // keyword content
if(! is_null($object) && ! empty($object->id)) {
$ecmfile->src_object_id = $object->id;
$ecmfile->src_object_type = $object->element;
}
if ($setsharekey) if ($setsharekey)
{ {
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';