diff --git a/htdocs/core/actions_linkedfiles.inc.php b/htdocs/core/actions_linkedfiles.inc.php index d97ecbe716a..018baab0cc0 100644 --- a/htdocs/core/actions_linkedfiles.inc.php +++ b/htdocs/core/actions_linkedfiles.inc.php @@ -18,10 +18,12 @@ * or see http://www.gnu.org/ */ - // Variable $upload_dir must be defined when entering here // Variable $upload_dirold may also exists. +//var_dump($upload_dir); +//var_dump($upload_dirold); + // Submit file/link if (GETPOST('sendit') && ! empty($conf->global->MAIN_UPLOAD_DOC)) { diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 1e07f5c2b0a..78f5f3f5359 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -1001,8 +1001,8 @@ class FormFile $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'; + dol_syslog("list_of_documents We found a file called '".$filearray[$key]['name']."' not indexed into database. We add it"); + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $ecmfile=new EcmFiles($this->db); // Add entry into database diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 8b338f8aea1..245bfe7d310 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -244,6 +244,7 @@ function dol_dir_list_in_database($path, $filter="", $excludefilter=null, $sortc $level1name=(isset($reg[1])?$reg[1]:''); $file_list[] = array( "rowid" => $obj->rowid, + "label" => $obj->label, // md5 "name" => $obj->filename, "path" => DOL_DATA_ROOT.'/'.$obj->filepath, "level1name" => $level1name, @@ -619,7 +620,7 @@ function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1) //var_dump($rel_filetorenamebefore.' - '.$rel_filetorenameafter); dol_syslog("Try to rename also entries in database for full relative path before = ".$rel_filetorenamebefore." after = ".$rel_filetorenameafter, LOG_DEBUG); - include DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $ecmfile=new EcmFiles($db); $result = $ecmfile->fetch(0, '', $rel_filetorenamebefore); if ($result > 0) // If found @@ -895,7 +896,7 @@ function dol_delete_file($file,$disableglob=0,$nophperrors=0,$nohook=0,$object=n $rel_filetodelete = preg_replace('/^[\\/]/', '', $rel_filetodelete); dol_syslog("Try to remove also entries in database for full relative path = ".$rel_filetodelete, LOG_DEBUG); - include DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $ecmfile=new EcmFiles($db); $result = $ecmfile->fetch(0, '', $rel_filetodelete); if ($result >= 0) @@ -1190,42 +1191,43 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio for ($i = 0; $i < $nbfile; $i++) { - // Define $destpath (path to file including filename) and $destfile (only filename) - $destpath=$upload_dir . "/" . $TFile['name'][$i]; + // Define $destfull (path to file including filename) and $destfile (only filename) + $destfull=$upload_dir . "/" . $TFile['name'][$i]; $destfile=$TFile['name'][$i]; $savingdocmask = dol_sanitizeFileName($savingdocmask); if ($savingdocmask) { - $destpath=$upload_dir . "/" . preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask); + $destfull=$upload_dir . "/" . preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask); $destfile=preg_replace('/__file__/',$TFile['name'][$i],$savingdocmask); } // lowercase extension - $info = pathinfo($destpath); - $destpath = $info['dirname'].'/'.$info['filename'].'.'.strtolower($info['extension']); + $info = pathinfo($destfull); + $destfull = $info['dirname'].'/'.$info['filename'].'.'.strtolower($info['extension']); $info = pathinfo($destfile); $destfile = $info['filename'].'.'.strtolower($info['extension']); - $resupload = dol_move_uploaded_file($TFile['tmp_name'][$i], $destpath, $allowoverwrite, 0, $TFile['error'][$i], 0, $varfiles); - if (is_numeric($resupload) && $resupload > 0) + $resupload = dol_move_uploaded_file($TFile['tmp_name'][$i], $destfull, $allowoverwrite, 0, $TFile['error'][$i], 0, $varfiles); + + if (is_numeric($resupload) && $resupload > 0) // $resupload can be 'ErrorFileAlreadyExists' { global $maxwidthsmall, $maxheightsmall, $maxwidthmini, $maxheightmini; include_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; // Generate thumbs. - if (image_format_supported($destpath) == 1) + if (image_format_supported($destfull) == 1) { // Create thumbs // We can't use $object->addThumbs here because there is no $object known // Used on logon for example - $imgThumbSmall = vignette($destpath, $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs"); + $imgThumbSmall = vignette($destfull, $maxwidthsmall, $maxheightsmall, '_small', 50, "thumbs"); // Create mini thumbs for image (Ratio is near 16/9) // Used on menu or for setup page for example - $imgThumbMini = vignette($destpath, $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs"); + $imgThumbMini = vignette($destfull, $maxwidthmini, $maxheightmini, '_mini', 50, "thumbs"); } // Update session @@ -1234,24 +1236,25 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail = new FormMail($db); $formmail->trackid = $trackid; - $formmail->add_attached_files($destpath, $destfile, $TFile['type'][$i]); + $formmail->add_attached_files($destfull, $destfile, $TFile['type'][$i]); } // Update table of files if ($donotupdatesession) { - $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $destfile); - if (! preg_match('/[\\/]temp[\\/]/', $rel_dir)) // If not a tmp file + $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir); + + if (! preg_match('/[\\/]temp[\\/]/', $rel_dir)) // If not a tmp dir { $filename = basename($destfile); $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); - include DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $ecmfile=new EcmFiles($db); $ecmfile->filepath = $rel_dir; $ecmfile->filename = $filename; - $ecmfile->label = md5_file(dol_osencode($destpath)); + $ecmfile->label = md5_file(dol_osencode($destfull)); $ecmfile->fullpath_orig = $TFile['name'][$i]; $ecmfile->gen_or_uploaded = 'uploaded'; $ecmfile->description = ''; // indexed content diff --git a/htdocs/core/photos_resize.php b/htdocs/core/photos_resize.php index 9936a495ceb..8fcd0d2b930 100644 --- a/htdocs/core/photos_resize.php +++ b/htdocs/core/photos_resize.php @@ -143,7 +143,7 @@ if ($action == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POS $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $fullpath); $rel_filename = preg_replace('/^[\\/]/','',$rel_filename); - include DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $ecmfile=new EcmFiles($db); $result = $ecmfile->fetch(0, '', $rel_filename); if ($result > 0) // If found @@ -211,7 +211,7 @@ if ($action == 'confirm_crop') $rel_filename = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $fullpath); $rel_filename = preg_replace('/^[\\/]/','',$rel_filename); - include DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; $ecmfile=new EcmFiles($db); $result = $ecmfile->fetch(0, '', $rel_filename); if ($result > 0) // If found 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 56fdb70b809..7ba91298545 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,10 +25,16 @@ -- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); -ALTER TABLE llx_ecm_files CHANGE COLUMN fullpath filepath varchar(750); +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; ALTER TABLE llx_ecm_files CHANGE COLUMN keyword keyword varchar(750); +ALTER TABLE llx_ecm_files DROP INDEX uk_ecm_files; +ALTER TABLE llx_ecm_files ADD UNIQUE INDEX uk_ecm_files (filepath, filename, entity); + +ALTER TABLE llx_ecm_files ADD INDEX idx_ecm_files_label (label); + insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PRODUCT_CREATE','Product or service created','Executed when a product or sevice is created','product',30); insert into llx_c_action_trigger (code,label,description,elementtype,rang) values ('PRODUCT_MODIFY','Product or service modified','Executed when a product or sevice is modified','product',30); diff --git a/htdocs/install/mysql/tables/llx_ecm_files.key.sql b/htdocs/install/mysql/tables/llx_ecm_files.key.sql index 2b8b1348ba3..b2e686b714b 100644 --- a/htdocs/install/mysql/tables/llx_ecm_files.key.sql +++ b/htdocs/install/mysql/tables/llx_ecm_files.key.sql @@ -17,7 +17,9 @@ -- ============================================================================ -ALTER TABLE llx_ecm_files ADD UNIQUE INDEX uk_ecm_files (label, entity); -- label is a md5 +ALTER TABLE llx_ecm_files ADD UNIQUE INDEX uk_ecm_files (filepath, filename, entity); +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 45157cdf959..71654eabca1 100644 --- a/htdocs/install/mysql/tables/llx_ecm_files.sql +++ b/htdocs/install/mysql/tables/llx_ecm_files.sql @@ -21,7 +21,7 @@ CREATE TABLE llx_ecm_files rowid integer AUTO_INCREMENT PRIMARY KEY, label varchar(64) NOT NULL, -- label contains a md5 entity integer DEFAULT 1 NOT NULL, -- multi company id - filepath varchar(750) NOT NULL, -- relative to dolibarr document dir. Example module/def + filepath varchar(255) NOT NULL, -- relative to dolibarr document dir. Example module/def filename varchar(255) NOT NULL, -- file name only without any directory fullpath_orig varchar(750), -- full path of original filename, when file is uploaded from a local computer description text,