From 0f4bf91fcd158dce1fbe03a58efa31ca941ee946 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 19 May 2025 09:45:31 +0200 Subject: [PATCH] Fix default value of dol_move --- htdocs/api/class/api_documents.class.php | 1 + htdocs/compta/facture/class/facture.class.php | 10 +++++----- htdocs/core/actions_linkedfiles.inc.php | 2 +- htdocs/core/lib/files.lib.php | 8 +++++--- htdocs/ticket/class/ticket.class.php | 7 ++++++- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/htdocs/api/class/api_documents.class.php b/htdocs/api/class/api_documents.class.php index 400fda31a95..c7d1268cd42 100644 --- a/htdocs/api/class/api_documents.class.php +++ b/htdocs/api/class/api_documents.class.php @@ -962,6 +962,7 @@ class Documents extends DolibarrApi if (!empty($cover)) { $moreinfo = array_merge($moreinfo, ["cover" => $cover]); } + $moreinfo['gen_or_uploaded'] = 'api'; // Move the temporary file at its final emplacement $result = dol_move($destfiletmp, $dest_file, '0', $overwriteifexists, 1, 1, $moreinfo); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 107be0b6a48..53353411d84 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3487,6 +3487,7 @@ class Facture extends CommonInvoice /** * Tag invoice as validated + call trigger BILL_VALIDATE * Object must have lines loaded with fetch_lines + * This may rename files on disk because ref is modified but it does not generate any document. * * @param User $user Object user that validate * @param string $force_number Reference to force on invoice @@ -3861,7 +3862,7 @@ class Facture extends CommonInvoice } if (!$error) { - // Rename directory if dir was a temporary ref + // Rename directory in index entry if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { // Now we rename also files into index $sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'facture/".$this->db->escape($this->newref)."'"; @@ -3923,7 +3924,8 @@ class Facture extends CommonInvoice } } - // Rename directory if dir was a temporary ref + // All database actions are now complete + // We rename the directory and files on disk if old dir was a temporary ref. if (!$error && preg_match('/^[\(]?PROV/i', $this->oldref)) { // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->oldref); @@ -3935,7 +3937,7 @@ class Facture extends CommonInvoice if (@rename($dirsource, $dirdest)) { dol_syslog("Rename ok"); - // Rename docs starting with $oldref with $newref + // Rename also docs starting with $oldref with $newref $listoffiles = dol_dir_list($conf->facture->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); foreach ($listoffiles as $fileentry) { $dirsource = $fileentry['name']; @@ -5729,8 +5731,6 @@ class Facture extends CommonInvoice */ public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null) { - global $conf, $langs; - $outputlangs->loadLangs(array("bills", "products")); if (!dol_strlen($modele)) { diff --git a/htdocs/core/actions_linkedfiles.inc.php b/htdocs/core/actions_linkedfiles.inc.php index 1b081757ad2..56dc6ecc96b 100644 --- a/htdocs/core/actions_linkedfiles.inc.php +++ b/htdocs/core/actions_linkedfiles.inc.php @@ -297,7 +297,7 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes' && !empty($permissionto $langs->load("errors"); // lang must be loaded because we can't rely on loading during output, we need var substitution to be done now. setEventMessages($langs->trans("ErrorFilenameCantStartWithDot", $filenameto), null, 'errors'); } elseif (!file_exists($destpath)) { - $result = dol_move($srcpath, $destpath); + $result = dol_move($srcpath, $destpath, '0', 1, 0, 1); if ($result) { // Define if we have to generate thumbs or not $generatethumbs = 1; diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index ad3eed61ebf..41540a1eb62 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -765,7 +765,8 @@ function dolReplaceInFile($srcfile, $arrayreplacement, $destfile = '', $newmask dolChmod($newpathoftmpdestfile, $newmask); // Rename - $result = dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile) ? 1 : 0), 0, $indexdatabase); + $moreinfo = array('gen_or_uploaded' => 'dolReplaceInFile'); + $result = dol_move($newpathoftmpdestfile, $newpathofdestfile, $newmask, (($destfile == $srcfile) ? 1 : 0), 0, $indexdatabase, $moreinfo); if (!$result) { dol_syslog("files.lib.php::dolReplaceInFile failed to move tmp file to final dest", LOG_WARNING); return -3; @@ -1145,7 +1146,7 @@ function dol_move($srcfile, $destfile, $newmask = '0', $overwriteifexists = 1, $ if (!empty($moreinfo) && !empty($moreinfo['gen_or_uploaded'])) { $ecmfile->gen_or_uploaded = $moreinfo['gen_or_uploaded']; } else { - $ecmfile->gen_or_uploaded = 'uploaded'; + $ecmfile->gen_or_uploaded = 'undefined'; // or 'generated', 'uploaded' } if (!empty($moreinfo) && !empty($moreinfo['description'])) { $ecmfile->description = $moreinfo['description']; // indexed content @@ -1272,7 +1273,8 @@ function dol_move_dir($srcdir, $destdir, $overwriteifexists = 1, $indexdatabase if ($file["type"] == "dir") { $res = dol_move_dir($filepath.'/'.$oldname, $filepath.'/'.$newname, $overwriteifexists, $indexdatabase, $renamedircontent); } else { - $res = dol_move($filepath.'/'.$oldname, $filepath.'/'.$newname, '0', $overwriteifexists, 0, $indexdatabase); + $moreinfo = array('gen_or_uploaded' => 'dol_move_dir'); + $res = dol_move($filepath.'/'.$oldname, $filepath.'/'.$newname, '0', $overwriteifexists, 0, $indexdatabase, $moreinfo); } if (!$res) { return $result; diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index dfb8177824c..125f530827b 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -2576,7 +2576,12 @@ class Ticket extends CommonObject $destfile = $destdir.'/'.$pathinfo['filename'].' - '.dol_print_date($now, 'dayhourlog').'.'.$pathinfo['extension']; } - $moreinfo = array('description' => 'File saved by copyFilesForTicket', 'src_object_type' => $this->element, 'src_object_id' => $this->id); + $moreinfo = array( + 'description' => 'File saved by copyFilesForTicket', + 'src_object_type' => $this->element, + 'src_object_id' => $this->id, + 'gen_or_uploaded' => 'uploaded' + ); $res = dol_move($filepath[$i], $destfile, '0', 1, 0, 1, $moreinfo);