Debug modulebuilder
This commit is contained in:
parent
c37deeeb78
commit
5aeb667e94
@ -498,6 +498,136 @@ class MyObject extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate object
|
||||||
|
*
|
||||||
|
* @param User $user User making status change
|
||||||
|
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
|
||||||
|
* @return int <=0 if OK, 0=Nothing done, >0 if KO
|
||||||
|
*/
|
||||||
|
public function validate($user, $notrigger = 0)
|
||||||
|
{
|
||||||
|
global $conf, $langs;
|
||||||
|
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
||||||
|
|
||||||
|
$error = 0;
|
||||||
|
|
||||||
|
// Protection
|
||||||
|
if ($this->statut == self::STATUS_VALIDATED)
|
||||||
|
{
|
||||||
|
dol_syslog(get_class($this)."::validate action abandonned: already validated", LOG_WARNING);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*if (! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->myobject->create))
|
||||||
|
|| (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->myobject->myobject_advance->validate))))
|
||||||
|
{
|
||||||
|
$this->error='NotEnoughPermissions';
|
||||||
|
dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
|
||||||
|
return -1;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
$now = dol_now();
|
||||||
|
|
||||||
|
$this->db->begin();
|
||||||
|
|
||||||
|
// Define new ref
|
||||||
|
if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) // empty should not happened, but when it occurs, the test save life
|
||||||
|
{
|
||||||
|
$num = $this->getNextNumRef();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$num = $this->ref;
|
||||||
|
}
|
||||||
|
$this->newref = $num;
|
||||||
|
|
||||||
|
// Validate
|
||||||
|
$sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element;
|
||||||
|
$sql .= " SET ref = '".$this->db->escape($num)."',";
|
||||||
|
$sql .= " status = ".self::STATUS_VALIDATED.",";
|
||||||
|
$sql .= " date_validation = '".$this->db->idate($now)."',";
|
||||||
|
$sql .= " fk_user_valid = ".$user->id;
|
||||||
|
$sql .= " WHERE rowid = ".$this->id;
|
||||||
|
|
||||||
|
dol_syslog(get_class($this)."::validate()", LOG_DEBUG);
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
|
{
|
||||||
|
dol_print_error($this->db);
|
||||||
|
$this->error = $this->db->lasterror();
|
||||||
|
$error++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$error && !$notrigger)
|
||||||
|
{
|
||||||
|
// Call trigger
|
||||||
|
$result = $this->call_trigger('MYOBJECT_VALIDATE', $user);
|
||||||
|
if ($result < 0) $error++;
|
||||||
|
// End call triggers
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$error)
|
||||||
|
{
|
||||||
|
$this->oldref = $this->ref;
|
||||||
|
|
||||||
|
// Rename directory if dir was a temporary ref
|
||||||
|
if (preg_match('/^[\(]?PROV/i', $this->ref))
|
||||||
|
{
|
||||||
|
// Now we rename also files into index
|
||||||
|
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'myobject/".$this->db->escape($this->newref)."'";
|
||||||
|
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'myobject/".$this->db->escape($this->ref)."' and entity = ".$conf->entity;
|
||||||
|
$resql = $this->db->query($sql);
|
||||||
|
if (!$resql) { $error++; $this->error = $this->db->lasterror(); }
|
||||||
|
|
||||||
|
// We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
|
||||||
|
$oldref = dol_sanitizeFileName($this->ref);
|
||||||
|
$newref = dol_sanitizeFileName($num);
|
||||||
|
$dirsource = $conf->myobject->dir_output.'/'.$oldref;
|
||||||
|
$dirdest = $conf->myobject->dir_output.'/'.$newref;
|
||||||
|
if (!$error && file_exists($dirsource))
|
||||||
|
{
|
||||||
|
dol_syslog(get_class($this)."::validate() rename dir ".$dirsource." into ".$dirdest);
|
||||||
|
|
||||||
|
if (@rename($dirsource, $dirdest))
|
||||||
|
{
|
||||||
|
dol_syslog("Rename ok");
|
||||||
|
// Rename docs starting with $oldref with $newref
|
||||||
|
$listoffiles = dol_dir_list($conf->myobject->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
|
||||||
|
foreach ($listoffiles as $fileentry)
|
||||||
|
{
|
||||||
|
$dirsource = $fileentry['name'];
|
||||||
|
$dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
|
||||||
|
$dirsource = $fileentry['path'].'/'.$dirsource;
|
||||||
|
$dirdest = $fileentry['path'].'/'.$dirdest;
|
||||||
|
@rename($dirsource, $dirdest);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set new ref and current status
|
||||||
|
if (!$error)
|
||||||
|
{
|
||||||
|
$this->ref = $num;
|
||||||
|
$this->status = self::STATUS_VALIDATED;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$error)
|
||||||
|
{
|
||||||
|
$this->db->commit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$this->db->rollback();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set draft status
|
* Set draft status
|
||||||
*
|
*
|
||||||
@ -520,7 +650,7 @@ class MyObject extends CommonObject
|
|||||||
return -1;
|
return -1;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'BOM_UNVALIDATE');
|
return $this->setStatusCommon($user, self::STATUS_DRAFT, $notrigger, 'MYOBJECT_UNVALIDATE');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -545,7 +675,7 @@ class MyObject extends CommonObject
|
|||||||
return -1;
|
return -1;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'BOM_CLOSE');
|
return $this->setStatusCommon($user, self::STATUS_CANCELED, $notrigger, 'MYOBJECT_CLOSE');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -570,7 +700,7 @@ class MyObject extends CommonObject
|
|||||||
return -1;
|
return -1;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'BOM_REOPEN');
|
return $this->setStatusCommon($user, self::STATUS_VALIDATED, $notrigger, 'MYOBJECT_REOPEN');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -135,7 +135,7 @@ if (empty($reshook))
|
|||||||
}
|
}
|
||||||
$triggermodname = 'MYMODULE_MYOBJECT_MODIFY'; // Name of trigger action code to execute when we modify record
|
$triggermodname = 'MYMODULE_MYOBJECT_MODIFY'; // Name of trigger action code to execute when we modify record
|
||||||
|
|
||||||
// Actions cancel, add, update, delete or clone
|
// Actions cancel, add, update, update_extras, confirm_validate, confirm_delete, confirm_deleteline, confirm_clone, confirm_close, confirm_setdraft, confirm_reopen
|
||||||
include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
|
include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
|
||||||
|
|
||||||
// Actions when linking object each other
|
// Actions when linking object each other
|
||||||
@ -460,7 +460,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
{
|
{
|
||||||
if ($permissiontoadd)
|
if ($permissiontoadd)
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=setdraft">'.$langs->trans("SetToDraft").'</a>';
|
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_setdraft&confirm=yes">'.$langs->trans("SetToDraft").'</a>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -481,7 +481,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea
|
|||||||
{
|
{
|
||||||
if (is_array($object->lines) && count($object->lines) > 0)
|
if (is_array($object->lines) && count($object->lines) > 0)
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=validate">'.$langs->trans("Validate").'</a>';
|
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=confirm_validate&confirm=yes">'.$langs->trans("Validate").'</a>';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user