Fix: delete or rename a document product dir
This commit is contained in:
parent
1b19fddbc6
commit
c512585670
@ -324,7 +324,7 @@ class Product extends CommonObject
|
|||||||
$result = $this->_log_price($user);
|
$result = $this->_log_price($user);
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
if ( $this->update($id, $user, true) > 0)
|
if ($this->update($id, $user, true) > 0)
|
||||||
{
|
{
|
||||||
if ($this->catid > 0)
|
if ($this->catid > 0)
|
||||||
{
|
{
|
||||||
@ -406,6 +406,8 @@ class Product extends CommonObject
|
|||||||
|
|
||||||
$error=0;
|
$error=0;
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
// Verification parametres
|
// Verification parametres
|
||||||
if (! $this->libelle) $this->libelle = 'MISSING LABEL';
|
if (! $this->libelle) $this->libelle = 'MISSING LABEL';
|
||||||
|
|
||||||
@ -507,7 +509,35 @@ class Product extends CommonObject
|
|||||||
// Fin appel triggers
|
// 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
|
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
|
// Delete product
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
@ -605,15 +619,34 @@ class Product extends CommonObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($error)
|
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)
|
||||||
{
|
{
|
||||||
$this->db->rollback();
|
$this->db->commit();
|
||||||
return -$error;
|
return 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->db->commit();
|
$this->db->rollback();
|
||||||
return 1;
|
return -$error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user