Merge branch 'develop' of ssh://git@github.com/Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2012-06-08 22:17:14 +02:00
commit 1022c73c24
3 changed files with 63 additions and 24 deletions

View File

@ -138,6 +138,8 @@ class Product extends CommonObject
//! Contains detail of stock of product into each warehouse
var $stock_warehouse=array();
var $oldcopy;
/**
@ -322,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)
{
@ -403,6 +405,8 @@ class Product extends CommonObject
global $langs, $conf;
$error=0;
$this->db->begin();
// Verification parametres
if (! $this->libelle) $this->libelle = 'MISSING LABEL';
@ -504,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
{
@ -572,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)
{
@ -602,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

View File

@ -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"]);

View File

@ -138,6 +138,8 @@ class Societe extends CommonObject
var $logo;
var $logo_small;
var $logo_mini;
var $oldcopy;
/**
* Constructor