diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index cdd573722552f3ca4c9bfd4704e76cc58639a4f8..2c665ec982c6066d069a1e0df12aab62429073aa 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1044,6 +1044,7 @@ else if ($action == 'builddoc') // In get or post $outputlangs->setDefaultLang($newlang); } $result=commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager); + if ($result <= 0) { dol_print_error($db,$result); diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index e13e5f1b93af9da6e937ac11e74f3c2e348a7dd8..84ad7f1ff1587757d1e06f9d5cd67213c69288a1 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -510,13 +510,14 @@ function dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1) } /** - * Move a file into another name + * Move a file into another name. * * @param string $srcfile Source file (can't be a directory) * @param string $destfile Destination file (can't be a directory) * @param string $newmask Mask for new file (0 by default means $conf->global->MAIN_UMASK) * @param int $overwriteifexists Overwrite file if exists (1 by default) * @return boolean True if OK, false if KO + * @see dol_move_uploaded_file */ function dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1) { @@ -554,18 +555,20 @@ function dol_unescapefile($filename) } /** - * Move an uploaded file after some controls. + * Make control on an uploaded file from an GUI page and move it to final destination. * If there is errors (virus found, antivir in error, bad filename), file is not moved. + * Note: This function can be used only into a HTML page context. Use dol_move if you are outside. * * @param string $src_file Source full path filename ($_FILES['field']['tmp_name']) * @param string $dest_file Target full path filename ($_FILES['field']['name']) * @param int $allowoverwrite 1=Overwrite target file if it already exists * @param int $disablevirusscan 1=Disable virus scan - * @param string $uploaderrorcode Value of upload error code ($_FILES['field']['error']) + * @param string $uploaderrorcode Value of PHP upload error code ($_FILES['field']['error']) * @param int $notrigger Disable all triggers - * @param string $upload_dir Upload directory - * @param array $upload_file Values of file uploaded $_FILES['field'] - * @return int >0 if OK, <0 or string if KO + * @param string $upload_dir Directory where to store uploaded file (note: also find in first part of dest_file) + * @param array $upload_file Values of uploaded file ($_FILES['field']) + * @return int >0 if OK, <0 or string if KO + * @see dolCheckUploadedFile, dol_move */ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $notrigger=0, $upload_dir='', $upload_file=null) { @@ -603,8 +606,9 @@ function dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disable * @param string $src_file Source full path filename ($_FILES['field']['tmp_name']) * @param string $dest_file Target full path filename ($_FILES['field']['name']) * @param int $disablevirusscan 1=Disable virus scan - * @param string $uploaderrorcode Value of upload error code ($_FILES['field']['error']) - * @return int >0 if OK, <0 or string if KO + * @param string $uploaderrorcode Value of PHP upload error code ($_FILES['field']['error']) + * @return int >0 if OK, <0 or string if KO + * @see dol_move_uploaded_file */ function dolCheckUploadedFile($src_file, $dest_file, $disablevirusscan=0, $uploaderrorcode=0) { @@ -936,21 +940,28 @@ function dol_delete_preview($object) /** * Create a meta file with document file into same directory. - * This should allow rgrep search + * This should allow "grep" search. + * This feature is enabled only if option MAIN_DOC_CREATE_METAFILE is set. * * @param Object $object Object - * @return void + * @return int 0 if we did nothing, >0 success, <0 error */ function dol_meta_create($object) { - global $langs,$conf; + global $conf; - $object->fetch_thirdparty(); + if (empty($conf->global->MAIN_DOC_CREATE_METAFILE)) return 0; - if ($conf->facture->dir_output) + // Define parent dir of elements + $element=$object->element; + $dir=empty($conf->$element->dir_output)?'':$conf->$element->dir_output; + + if ($dir) { + $object->fetch_thirdparty(); + $facref = dol_sanitizeFileName($object->ref); - $dir = $conf->facture->dir_output . "/" . $facref; + $dir = $dir . "/" . $facref; $file = $dir . "/" . $facref . ".meta"; if (! is_dir($dir)) @@ -985,7 +996,11 @@ function dol_meta_create($object) fclose($fp); if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); + + return 1; } + + return 0; } @@ -1023,7 +1038,7 @@ function dol_init_file_process($pathtoscan='') * All information used are in db, conf, langs, user and _FILES. * Note: This function can be used only into a HTML page context. * - * @param string $upload_dir Directory to store upload files + * @param string $upload_dir Directory where to store uploaded file (note: also find in first part of dest_file) * @param int $allowoverwrite 1=Allow overwrite existing file * @param int $donotupdatesession 1=Do no edit _SESSION variable * @param string $varfiles _FILES var name diff --git a/test/phpunit/FilesLibTest.php b/test/phpunit/FilesLibTest.php index cc47f70d38e5eff93cd872159a75c8078b3f2f4e..9b66ff96aeeec3359452fd2cf6aab8e1635f6f4a 100644 --- a/test/phpunit/FilesLibTest.php +++ b/test/phpunit/FilesLibTest.php @@ -225,11 +225,11 @@ class FilesLibTest extends PHPUnit_Framework_TestCase } /** - * testDolCopyMove + * testDolCopyMoveDelete * * @return int */ - public function testDolCopyMove() + public function testDolCopyMoveDelete() { global $conf,$user,$langs,$db; $conf=$this->savconf;