From 0e76bd7ac659ba9e03baa17246726ba84060b664 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 19 Sep 2012 14:11:01 +0200 Subject: [PATCH] Fix: Blank page when renaming a product ref --- htdocs/core/lib/files.lib.php | 2 +- htdocs/product/class/product.class.php | 5 ++++- htdocs/product/fiche.php | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 6f3303add9e..92399378f53 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -515,13 +515,13 @@ function dol_copy($srcfile, $destfile, $newmask=0, $overwriteifexists=1) /** * Move a file into another name. + * This function differs from dol_move_uploaded_file, because it can be called in any context. * * @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) { diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 00c881f9398..2863fba6bb5 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -524,7 +524,8 @@ class Product extends CommonObject $newdir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->ref); if (file_exists($olddir)) { - $res=@dol_move($olddir, $newdir); + include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; + $res=dol_move($olddir, $newdir); if (! $res) { $this->error='ErrorFailToMoveDir'; @@ -550,11 +551,13 @@ class Product extends CommonObject if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $this->error=$langs->trans("Error")." : ".$langs->trans("ErrorProductAlreadyExists",$this->ref); + $this->db->rollback(); return -1; } else { $this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql; + $this->db->rollback(); return -2; } } diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 14ba98526f0..82f6d192f11 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -239,7 +239,7 @@ if (empty($reshook)) // Update a product or service if ($action == 'update' && ($user->rights->produit->creer || $user->rights->service->creer)) { - if (GETPOST('cancel')) + if (GETPOST('cancel')) { $action = ''; }