diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php
index a82024d86cf..1e07f5c2b0a 100644
--- a/htdocs/core/class/html.formfile.class.php
+++ b/htdocs/core/class/html.formfile.class.php
@@ -997,11 +997,41 @@ class FormFile
$filearray[$key]['position']=999999; // File not indexed are at end. So if we add a file, it will not replace an existing position
$filearray[$key]['cover']=0;
$filearray[$key]['acl']='';
- $filearray[$key]['rowid']=0;
- // TODO Add entry into database
-
- //...
-
+
+ $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $filearray[$key]['fullname']);
+ if (! preg_match('/(\/temp\/|\/thumbs|\.meta$)/', $rel_filetorenameafter)) // If not a tmp file
+ {
+ dol_syslog("list_of_documents We found a file not indexed into database. We add it");
+ include DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
+ $ecmfile=new EcmFiles($this->db);
+
+ // Add entry into database
+ $filename = basename($rel_filename);
+ $rel_dir = dirname($rel_filename);
+ $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
+ $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
+
+ $ecmfile->filepath = $rel_dir;
+ $ecmfile->filename = $filename;
+ $ecmfile->label = md5_file(dol_osencode($filearray[$key]['fullname'])); // $destfile is a full path to file
+ $ecmfile->fullpath_orig = $filearray[$key]['fullname'];
+ $ecmfile->gen_or_uploaded = 'unknown';
+ $ecmfile->description = ''; // indexed content
+ $ecmfile->keyword = ''; // keyword content
+ $result = $ecmfile->create($user);
+ if ($result < 0)
+ {
+ setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
+ }
+ else
+ {
+ $filearray[$key]['rowid']=$result;
+ }
+ }
+ else
+ {
+ $filearray[$key]['rowid']=0; // Should not happened
+ }
}
}
diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php
index a4273644fdf..8b338f8aea1 100644
--- a/htdocs/core/lib/files.lib.php
+++ b/htdocs/core/lib/files.lib.php
@@ -652,7 +652,6 @@ function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1)
{
setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
}
- $result = $ecmfile->create($user);
}
elseif ($result < 0)
{
diff --git a/htdocs/core/tpl/ajaxrow.tpl.php b/htdocs/core/tpl/ajaxrow.tpl.php
index c970631f907..d0a7b45efea 100644
--- a/htdocs/core/tpl/ajaxrow.tpl.php
+++ b/htdocs/core/tpl/ajaxrow.tpl.php
@@ -29,6 +29,7 @@ $table_element_line=(empty($table_element_line)?$object->table_element_line:$tab
$nboflines=(isset($object->lines)?count($object->lines):(isset($tasksarray)?count($tasksarray):(empty($nboflines)?0:$nboflines)));
$forcereloadpage=empty($conf->global->MAIN_FORCE_RELOAD_PAGE)?0:1;
$tagidfortablednd=(empty($tagidfortablednd)?'tablelines':$tagidfortablednd);
+$filepath=(empty($filepath)?'':$filepath);
if (GETPOST('action') != 'editline' && $nboflines > 1) { ?>