This commit is contained in:
Maxime Kohlhaas 2017-08-31 09:02:21 +02:00
commit 49a29a16e6

View File

@ -43,6 +43,8 @@ class Dolresource extends CommonObject
var $type_label; var $type_label;
var $tms=''; var $tms='';
var $oldcopy;
/** /**
* Constructor * Constructor
* *
@ -240,6 +242,13 @@ class Dolresource extends CommonObject
if (isset($this->fk_code_type_resource)) $this->fk_code_type_resource=trim($this->fk_code_type_resource); if (isset($this->fk_code_type_resource)) $this->fk_code_type_resource=trim($this->fk_code_type_resource);
if (isset($this->description)) $this->description=trim($this->description); if (isset($this->description)) $this->description=trim($this->description);
if (empty($this->oldcopy))
{
$org=new self($this->db);
$org->fetch($this->id);
$this->oldcopy=$org;
}
// Update request // Update request
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
$sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").","; $sql.= " ref=".(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").",";
@ -258,17 +267,33 @@ class Dolresource extends CommonObject
{ {
if (! $notrigger) if (! $notrigger)
{ {
// Uncomment this and change MYOBJECT to your own tag if you // Call trigger
// want this action calls a trigger. $result=$this->call_trigger('RESOURCE_MODIFY',$user);
if ($result < 0) $error++;
// End call triggers
}
}
//// Call triggers if (! $error && (is_object($this->oldcopy) && $this->oldcopy->ref !== $this->ref))
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; {
$interface=new Interfaces($this->db); // We remove directory
$result=$interface->run_triggers('RESOURCE_MODIFY',$this,$user,$langs,$conf); if (! empty($conf->resource->dir_output))
if ($result < 0) { $error++; $this->errors=$interface->errors; } {
//// End call triggers $olddir = $conf->resource->dir_output . "/" . dol_sanitizeFileName($this->oldcopy->ref);
$newdir = $conf->resource->dir_output . "/" . dol_sanitizeFileName($this->ref);
if (file_exists($olddir))
{
$res = @rename($olddir, $newdir);
if (! $res)
{
$langs->load("errors");
$this->error=$langs->trans('ErrorFailToRenameDir',$olddir,$newdir);
$error++;
} }
} }
}
}
if (! $error) if (! $error)
{ {
$action='update'; $action='update';
@ -423,6 +448,25 @@ class Dolresource extends CommonObject
// End call triggers // End call triggers
} }
if (! $error)
{
// We remove directory
$ref = dol_sanitizeFileName($this->ref);
if (! empty($conf->resource->dir_output))
{
$dir = $conf->resource->dir_output . "/" . dol_sanitizeFileName($this->ref);
if (file_exists($dir))
{
$res=@dol_delete_dir_recursive($dir);
if (! $res)
{
$this->errors[] = 'ErrorFailToDeleteDir';
$error++;
}
}
}
}
if (! $error) if (! $error)
{ {
$this->db->commit(); $this->db->commit();