diff --git a/htdocs/ecm/class/ecmfiles.class.php b/htdocs/ecm/class/ecmfiles.class.php index 1e371c9020a..431e27dd38f 100644 --- a/htdocs/ecm/class/ecmfiles.class.php +++ b/htdocs/ecm/class/ecmfiles.class.php @@ -232,7 +232,7 @@ class EcmFiles //extends CommonObject * Load object in memory from the database * * @param int $id Id object - * @param string $ref Ref = md5 = label + * @param string $ref Not used yet. Will contains a hash id from filename+filepath * @param string $fullpath Full path of file (relative path to document directory) * @return int <0 if KO, 0 if not found, >0 if OK */ @@ -242,6 +242,7 @@ class EcmFiles //extends CommonObject $sql = 'SELECT'; $sql .= ' t.rowid,'; + $sql .= " t.ref,"; $sql .= " t.label,"; $sql .= " t.entity,"; $sql .= " t.filename,"; @@ -260,14 +261,15 @@ class EcmFiles //extends CommonObject $sql .= " t.acl"; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; $sql.= ' WHERE 1 = 1'; + /* Fetching this table depends on filepath+filename, it must not depends on entity if (! empty($conf->multicompany->enabled)) { $sql .= " AND entity IN (" . getEntity("ecmfiles", 1) . ")"; - } + }*/ if ($fullpath) { $sql .= " AND t.filepath = '" . $this->db->escape(dirname($fullpath)) . "' AND t.filename = '".$this->db->escape(basename($fullpath))."'"; } elseif (null !== $ref) { - $sql .= " AND t.label = '".$this->db->escape($ref)."'"; + $sql .= " AND t.ref = '".$this->db->escape($ref)."'"; } else { $sql .= ' AND t.rowid = ' . $id; } @@ -279,7 +281,7 @@ class EcmFiles //extends CommonObject $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; - + $this->ref = $obj->ref; $this->label = $obj->label; $this->entity = $obj->entity; $this->filename = $obj->filename; @@ -367,9 +369,10 @@ class EcmFiles //extends CommonObject } } $sql.= ' WHERE 1 = 1'; + /* Fetching this table depends on filepath+filename, it must not depends on entity if (! empty($conf->multicompany->enabled)) { $sql .= " AND entity IN (" . getEntity("ecmfiles", 1) . ")"; - } + }*/ if (count($sqlwhere) > 0) { $sql .= ' AND ' . implode(' '.$filtermode.' ', $sqlwhere); } diff --git a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql index f586add0837..bf10b925516 100644 --- a/htdocs/install/mysql/migration/5.0.0-6.0.0.sql +++ b/htdocs/install/mysql/migration/5.0.0-6.0.0.sql @@ -25,6 +25,7 @@ -- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); +ALTER TABLE llx_ecm_files ADD COLUMN ref varchar(128) AFTER rowid; ALTER TABLE llx_ecm_files CHANGE COLUMN fullpath filepath varchar(255); ALTER TABLE llx_ecm_files CHANGE COLUMN filepath filepath varchar(255); ALTER TABLE llx_ecm_files ADD COLUMN position integer; diff --git a/htdocs/install/mysql/tables/llx_ecm_files.key.sql b/htdocs/install/mysql/tables/llx_ecm_files.key.sql index b2e686b714b..a55debc9cd0 100644 --- a/htdocs/install/mysql/tables/llx_ecm_files.key.sql +++ b/htdocs/install/mysql/tables/llx_ecm_files.key.sql @@ -1,5 +1,5 @@ -- ============================================================================ --- Copyright (C) 2015 Laurent Destailleur +-- Copyright (C) 2017 Laurent Destailleur -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ -- ============================================================================ -ALTER TABLE llx_ecm_files ADD UNIQUE INDEX uk_ecm_files (filepath, filename, entity); +ALTER TABLE llx_ecm_files ADD UNIQUE INDEX uk_ecm_files (filepath, filename); ALTER TABLE llx_ecm_files ADD INDEX idx_ecm_files_label (label); --ALTER TABLE llx_ecm_files ADD UNIQUE INDEX uk_ecm_files_fullpath(fullpath); Disabled, mysql limits size of index diff --git a/htdocs/install/mysql/tables/llx_ecm_files.sql b/htdocs/install/mysql/tables/llx_ecm_files.sql index 71654eabca1..dcc9dd40b9d 100644 --- a/htdocs/install/mysql/tables/llx_ecm_files.sql +++ b/htdocs/install/mysql/tables/llx_ecm_files.sql @@ -19,6 +19,7 @@ CREATE TABLE llx_ecm_files ( rowid integer AUTO_INCREMENT PRIMARY KEY, + ref varchar(128), -- Not used yet. Will contains a hash id from filename+filepath label varchar(64) NOT NULL, -- label contains a md5 entity integer DEFAULT 1 NOT NULL, -- multi company id filepath varchar(255) NOT NULL, -- relative to dolibarr document dir. Example module/def