Can get first image from index using a path without name

This commit is contained in:
Laurent Destailleur 2020-06-18 15:07:43 +02:00
parent 6c2d70d43b
commit 6e761d5c98

View File

@ -56,9 +56,9 @@ class EcmFiles extends CommonObject
/** /**
* hash of file content (md5_file(dol_osencode($destfull)) * hash of file content (md5_file(dol_osencode($destfull))
* @var string Ecm Files label * @var string Ecm Files label
*/ */
public $label; public $label;
public $share; // hash for file sharing, empty by default (example: getRandomPassword(true)) public $share; // hash for file sharing, empty by default (example: getRandomPassword(true))
@ -85,13 +85,13 @@ class EcmFiles extends CommonObject
public $date_m = ''; public $date_m = '';
/** /**
* @var int ID * @var int ID
*/ */
public $fk_user_c; public $fk_user_c;
/** /**
* @var int ID * @var int ID
*/ */
public $fk_user_m; public $fk_user_m;
public $acl; public $acl;
@ -126,50 +126,50 @@ class EcmFiles extends CommonObject
// Clean parameters // Clean parameters
if (isset($this->ref)) { if (isset($this->ref)) {
$this->ref = trim($this->ref); $this->ref = trim($this->ref);
} }
if (isset($this->label)) { if (isset($this->label)) {
$this->label = trim($this->label); $this->label = trim($this->label);
} }
if (isset($this->share)) { if (isset($this->share)) {
$this->share = trim($this->share); $this->share = trim($this->share);
} }
if (isset($this->entity)) { if (isset($this->entity)) {
$this->entity = trim($this->entity); $this->entity = trim($this->entity);
} }
if (isset($this->filename)) { if (isset($this->filename)) {
$this->filename = preg_replace('/\.noexe$/', '', trim($this->filename)); $this->filename = preg_replace('/\.noexe$/', '', trim($this->filename));
} }
if (isset($this->filepath)) { if (isset($this->filepath)) {
$this->filepath = trim($this->filepath); $this->filepath = trim($this->filepath);
$this->filepath = preg_replace('/[\\/]+$/', '', $this->filepath); // Remove last / $this->filepath = preg_replace('/[\\/]+$/', '', $this->filepath); // Remove last /
} }
if (isset($this->fullpath_orig)) { if (isset($this->fullpath_orig)) {
$this->fullpath_orig = trim($this->fullpath_orig); $this->fullpath_orig = trim($this->fullpath_orig);
} }
if (isset($this->description)) { if (isset($this->description)) {
$this->description = trim($this->description); $this->description = trim($this->description);
} }
if (isset($this->keywords)) { if (isset($this->keywords)) {
$this->keywords = trim($this->keywords); $this->keywords = trim($this->keywords);
} }
if (isset($this->cover)) { if (isset($this->cover)) {
$this->cover = trim($this->cover); $this->cover = trim($this->cover);
} }
if (isset($this->gen_or_uploaded)) { if (isset($this->gen_or_uploaded)) {
$this->gen_or_uploaded = trim($this->gen_or_uploaded); $this->gen_or_uploaded = trim($this->gen_or_uploaded);
} }
if (isset($this->extraparams)) { if (isset($this->extraparams)) {
$this->extraparams = trim($this->extraparams); $this->extraparams = trim($this->extraparams);
} }
if (isset($this->fk_user_c)) { if (isset($this->fk_user_c)) {
$this->fk_user_c = trim($this->fk_user_c); $this->fk_user_c = trim($this->fk_user_c);
} }
if (isset($this->fk_user_m)) { if (isset($this->fk_user_m)) {
$this->fk_user_m = trim($this->fk_user_m); $this->fk_user_m = trim($this->fk_user_m);
} }
if (isset($this->acl)) { if (isset($this->acl)) {
$this->acl = trim($this->acl); $this->acl = trim($this->acl);
} }
if (isset($this->src_object_type)) { if (isset($this->src_object_type)) {
$this->src_object_type = trim($this->src_object_type); $this->src_object_type = trim($this->src_object_type);
@ -304,7 +304,7 @@ class EcmFiles extends CommonObject
* *
* @param int $id Id object * @param int $id Id object
* @param string $ref Hash of file name (filename+filepath). Not always defined on some version. * @param string $ref Hash of file name (filename+filepath). Not always defined on some version.
* @param string $relativepath Relative path of file from document directory. Example: path/path2/file * @param string $relativepath Relative path of file from document directory. Example: 'path/path2/file' or 'path/path2/*'
* @param string $hashoffile Hash of file content. Take the first one found if same file is at different places. This hash will also change if file content is changed. * @param string $hashoffile Hash of file content. Take the first one found if same file is at different places. This hash will also change if file content is changed.
* @param string $hashforshare Hash of file sharing. * @param string $hashforshare Hash of file sharing.
* @param string $src_object_type src_object_type to search * @param string $src_object_type src_object_type to search
@ -342,12 +342,16 @@ class EcmFiles extends CommonObject
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
$sql .= ' WHERE 1 = 1'; $sql .= ' WHERE 1 = 1';
/* Fetching this table depends on filepath+filename, it must not depends on entity because filesystem on disk does not know what is Dolibarr entities /* Fetching this table depends on filepath+filename, it must not depends on entity because filesystem on disk does not know what is Dolibarr entities
if (! empty($conf->multicompany->enabled)) { if (! empty($conf->multicompany->enabled)) {
$sql .= " AND entity IN (" . getEntity('ecmfiles') . ")"; $sql .= " AND entity IN (" . getEntity('ecmfiles') . ")";
}*/ }*/
if ($relativepath) { if ($relativepath) {
$relativepathwithnoexe = preg_replace('/\.noexe$/', '', $relativepath); // We must never have the .noexe into the database $relativepathwithnoexe = preg_replace('/\.noexe$/', '', $relativepath); // We must never have the .noexe into the database
$sql .= " AND t.filepath = '".$this->db->escape(dirname($relativepath))."' AND t.filename = '".$this->db->escape(basename($relativepathwithnoexe))."'"; $sql .= " AND t.filepath = '".$this->db->escape(dirname($relativepath))."'";
$filename = basename($relativepathwithnoexe);
if ($filename != '*') {
$sql .= " AND t.filename = '".$this->db->escape($filename)."'";
}
$sql .= " AND t.entity = ".$conf->entity; // unique key include the entity so each company has its own index $sql .= " AND t.entity = ".$conf->entity; // unique key include the entity so each company has its own index
} elseif (!empty($ref)) { // hash of file path } elseif (!empty($ref)) { // hash of file path
$sql .= " AND t.ref = '".$this->db->escape($ref)."'"; $sql .= " AND t.ref = '".$this->db->escape($ref)."'";
@ -468,9 +472,9 @@ class EcmFiles extends CommonObject
} }
$sql .= ' WHERE 1 = 1'; $sql .= ' WHERE 1 = 1';
/* Fetching this table depends on filepath+filename, it must not depends on entity /* Fetching this table depends on filepath+filename, it must not depends on entity
if (! empty($conf->multicompany->enabled)) { if (! empty($conf->multicompany->enabled)) {
$sql .= " AND entity IN (" . getEntity('ecmfiles') . ")"; $sql .= " AND entity IN (" . getEntity('ecmfiles') . ")";
}*/ }*/
if (count($sqlwhere) > 0) { if (count($sqlwhere) > 0) {
$sql .= ' AND '.implode(' '.$filtermode.' ', $sqlwhere); $sql .= ' AND '.implode(' '.$filtermode.' ', $sqlwhere);
} }
@ -807,7 +811,7 @@ class EcmFiles extends CommonObject
return $this->LibStatut($this->status, $mode); return $this->LibStatut($this->status, $mode);
} }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/** /**
* Return the status * Return the status
* *
@ -817,7 +821,7 @@ class EcmFiles extends CommonObject
*/ */
public static function LibStatut($status, $mode = 0) public static function LibStatut($status, $mode = 0)
{ {
// phpcs:enable // phpcs:enable
global $langs; global $langs;
return ''; return '';
} }
@ -863,9 +867,9 @@ class EcmFiles extends CommonObject
class EcmfilesLine class EcmfilesLine
{ {
/** /**
* @var string ECM files line label * @var string ECM files line label
*/ */
public $label; public $label;
/** /**
* @var int Entity * @var int Entity
@ -890,13 +894,13 @@ class EcmfilesLine
public $date_m = ''; public $date_m = '';
/** /**
* @var int ID * @var int ID
*/ */
public $fk_user_c; public $fk_user_c;
/** /**
* @var int ID * @var int ID
*/ */
public $fk_user_m; public $fk_user_m;
public $acl; public $acl;