From 355cb988b762bc44ab55482ed422e70efd8e9e30 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 8 Jun 2012 20:27:02 +0200 Subject: [PATCH 1/2] Fix: missing oldcopy during update --- htdocs/product/class/product.class.php | 2 ++ htdocs/product/fiche.php | 2 ++ htdocs/societe/class/societe.class.php | 2 ++ 3 files changed, 6 insertions(+) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 820a66e08d3..d8d52dd1720 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -138,6 +138,8 @@ class Product extends CommonObject //! Contains detail of stock of product into each warehouse var $stock_warehouse=array(); + + var $oldcopy; /** diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 182882bf63f..dcc798df8f3 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -250,6 +250,8 @@ if (empty($reshook)) { if ($object->fetch($id,$ref)) { + $object->oldcopy=dol_clone($object); + $object->ref = $ref; $object->libelle = $_POST["libelle"]; $object->description = dol_htmlcleanlastbr($_POST["desc"]); diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 006988b93fe..a46c5a72292 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -138,6 +138,8 @@ class Societe extends CommonObject var $logo; var $logo_small; var $logo_mini; + + var $oldcopy; /** * Constructor From f4135d3758c9de0051c90b918b3119e06081a384 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 8 Jun 2012 21:38:11 +0200 Subject: [PATCH 2/2] Fix: delete or rename a document product dir --- htdocs/product/class/product.class.php | 81 ++++++++++++++++++-------- 1 file changed, 57 insertions(+), 24 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index d8d52dd1720..789945d1d96 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -324,7 +324,7 @@ class Product extends CommonObject $result = $this->_log_price($user); if ($result > 0) { - if ( $this->update($id, $user, true) > 0) + if ($this->update($id, $user, true) > 0) { if ($this->catid > 0) { @@ -405,6 +405,8 @@ class Product extends CommonObject global $langs, $conf; $error=0; + + $this->db->begin(); // Verification parametres if (! $this->libelle) $this->libelle = 'MISSING LABEL'; @@ -506,8 +508,36 @@ class Product extends CommonObject if ($result < 0) { $error++; $this->errors=$interface->errors; } // Fin appel triggers } - - return 1; + + if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref != $this->ref)) + { + // We remove directory + if ($conf->product->dir_output) + { + $olddir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->oldcopy->ref); + $newdir = $conf->product->dir_output . "/" . dol_sanitizeFileName($this->ref); + if (file_exists($olddir)) + { + $res=@dol_move($olddir, $newdir); + if (! $res) + { + $this->error='ErrorFailToMoveDir'; + $error++; + } + } + } + } + + if (! $error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -$error; + } } else { @@ -574,22 +604,6 @@ class Product extends CommonObject } } - // TODO Remove this. It can already be addressed by previous triggers - if (! $error) - { - // Actions on extra fields (by external module or standard code) - include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'); - $hookmanager=new HookManager($this->db); - $hookmanager->initHooks(array('productdao')); - $parameters=array(); $action='delete'; - $reshook=$hookmanager->executeHooks('deleteProduct',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - if (! empty($hookmanager->error)) - { - $error++; - $this->error=$hookmanager->error; - } - } - // Delete product if (! $error) { @@ -604,16 +618,35 @@ class Product extends CommonObject dol_syslog(get_class($this).'::delete error '.$this->error, LOG_ERR); } } + + if (! $error) + { + // We remove directory + $ref = dol_sanitizeFileName($this->ref); + if ($conf->product->dir_output) + { + $dir = $conf->product->dir_output . "/" . $ref; + if (file_exists($dir)) + { + $res=@dol_delete_dir_recursive($dir); + if (! $res) + { + $this->error='ErrorFailToDeleteDir'; + $error++; + } + } + } + } - if ($error) + if (! $error) { - $this->db->rollback(); - return -$error; + $this->db->commit(); + return 1; } else { - $this->db->commit(); - return 1; + $this->db->rollback(); + return -$error; } } else