diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 73fa3cf6703..28b598f090e 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1219,7 +1219,7 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$nohook=0,$object=n } else dol_syslog("Failed to remove file ".$filename, LOG_WARNING); // TODO Failure to remove can be because file was already removed or because of permission - // If error because of not exists, we must should return true and we should return false if this is a permission problem + // If error because it does not exists, we should return true, and we should return false if this is a permission problem } } else dol_syslog("No files to delete found", LOG_DEBUG); diff --git a/htdocs/ecm/class/ecmfiles.class.php b/htdocs/ecm/class/ecmfiles.class.php index f1c0b6b1448..df76bac3e9b 100644 --- a/htdocs/ecm/class/ecmfiles.class.php +++ b/htdocs/ecm/class/ecmfiles.class.php @@ -285,6 +285,8 @@ class EcmFiles extends CommonObject */ public function fetch($id, $ref = '', $relativepath = '', $hashoffile='', $hashforshare='', $src_object_type='', $src_object_id=0) { + global $conf; + dol_syslog(__METHOD__, LOG_DEBUG); $sql = 'SELECT'; @@ -317,25 +319,31 @@ class EcmFiles extends CommonObject }*/ if ($relativepath) { $sql .= " AND t.filepath = '" . $this->db->escape(dirname($relativepath)) . "' AND t.filename = '".$this->db->escape(basename($relativepath))."'"; + $sql .= " AND t.entity = ".$conf->entity; // unique key include the entity so each company has its own index } - elseif (! empty($ref)) { + elseif (! empty($ref)) { // hash of file path $sql .= " AND t.ref = '".$this->db->escape($ref)."'"; + $sql .= " AND t.entity = ".$conf->entity; // unique key include the entity so each company has its own index } - elseif (! empty($hashoffile)) { + elseif (! empty($hashoffile)) { // hash of content $sql .= " AND t.label = '".$this->db->escape($hashoffile)."'"; + $sql .= " AND t.entity = ".$conf->entity; // unique key include the entity so each company has its own index } elseif (! empty($hashforshare)) { $sql .= " AND t.share = '".$this->db->escape($hashforshare)."'"; + //$sql .= " AND t.entity = ".$conf->entity; // hashforshare already unique } elseif ($src_object_type && $src_object_id) { - $sql.= " AND t.src_object_type ='".$this->db->escape($src_object_type)."' AND t.src_object_id = ".$this->db->escape($src_object_id); + // Warning: May return several record, and only first one is returned ! + $sql .= " AND t.src_object_type ='".$this->db->escape($src_object_type)."' AND t.src_object_id = ".$this->db->escape($src_object_id); + $sql .= " AND t.entity = ".$conf->entity; } else { - $sql .= ' AND t.rowid = '.$this->db->escape($id); + $sql .= ' AND t.rowid = '.$this->db->escape($id); // rowid already unique } - // When we search on hash of content, we take the first one. Solve also hash conflict. - $this->db->plimit(1); + + $this->db->plimit(1); // When we search on src or on hash of content (hashforfile) to solve hash conflict when several files has same content, we take first one only $this->db->order('t.rowid', 'ASC'); $resql = $this->db->query($sql);