Fix phpcs

This commit is contained in:
Laurent Destailleur 2021-10-25 22:09:21 +02:00
parent 02f8ac4cbc
commit cffee1df4b

View File

@ -396,125 +396,125 @@ class Delivery extends CommonObject
if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery->creer)) if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery->creer))
|| (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate))) { || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->expedition->delivery_advance->validate))) {
if (!empty($conf->global->DELIVERY_ADDON_NUMBER)) { if (!empty($conf->global->DELIVERY_ADDON_NUMBER)) {
// Setting the command numbering module name // Setting the command numbering module name
$modName = $conf->global->DELIVERY_ADDON_NUMBER; $modName = $conf->global->DELIVERY_ADDON_NUMBER;
if (is_readable(DOL_DOCUMENT_ROOT.'/core/modules/delivery/'.$modName.'.php')) { if (is_readable(DOL_DOCUMENT_ROOT.'/core/modules/delivery/'.$modName.'.php')) {
require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/'.$modName.'.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/delivery/'.$modName.'.php';
$now = dol_now(); $now = dol_now();
// Retrieving the new reference // Retrieving the new reference
$objMod = new $modName($this->db); $objMod = new $modName($this->db);
$soc = new Societe($this->db); $soc = new Societe($this->db);
$soc->fetch($this->socid); $soc->fetch($this->socid);
if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life
$numref = $objMod->delivery_get_num($soc, $this); $numref = $objMod->delivery_get_num($soc, $this);
} else { } else {
$numref = $this->ref; $numref = $this->ref;
}
$this->newref = dol_sanitizeFileName($numref);
// Test if is not already in valid status. If so, we stop to avoid decrementing the stock twice.
$sql = "SELECT ref";
$sql .= " FROM ".MAIN_DB_PREFIX."delivery";
$sql .= " WHERE ref = '".$this->db->escape($numref)."'";
$sql .= " AND fk_statut <> 0";
$sql .= " AND entity = ".((int) $conf->entity);
$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
if ($num > 0) {
return 0;
} }
$this->newref = dol_sanitizeFileName($numref); }
// Test if is not already in valid status. If so, we stop to avoid decrementing the stock twice. $sql = "UPDATE ".MAIN_DB_PREFIX."delivery SET";
$sql = "SELECT ref"; $sql .= " ref='".$this->db->escape($numref)."'";
$sql .= " FROM ".MAIN_DB_PREFIX."delivery"; $sql .= ", fk_statut = 1";
$sql .= " WHERE ref = '".$this->db->escape($numref)."'"; $sql .= ", date_valid = '".$this->db->idate($now)."'";
$sql .= " AND fk_statut <> 0"; $sql .= ", fk_user_valid = ".$user->id;
$sql .= " AND entity = ".((int) $conf->entity); $sql .= " WHERE rowid = ".((int) $this->id);
$sql .= " AND fk_statut = 0";
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) { if (!$resql) {
$num = $this->db->num_rows($resql); dol_print_error($this->db);
if ($num > 0) { $this->error = $this->db->lasterror();
return 0; $error++;
} }
}
$sql = "UPDATE ".MAIN_DB_PREFIX."delivery SET"; if (!$error && !$notrigger) {
$sql .= " ref='".$this->db->escape($numref)."'"; // Call trigger
$sql .= ", fk_statut = 1"; $result = $this->call_trigger('DELIVERY_VALIDATE', $user);
$sql .= ", date_valid = '".$this->db->idate($now)."'"; if ($result < 0) {
$sql .= ", fk_user_valid = ".$user->id;
$sql .= " WHERE rowid = ".((int) $this->id);
$sql .= " AND fk_statut = 0";
$resql = $this->db->query($sql);
if (!$resql) {
dol_print_error($this->db);
$this->error = $this->db->lasterror();
$error++; $error++;
} }
// End call triggers
}
if (!$error && !$notrigger) { if (!$error) {
// Call trigger $this->oldref = $this->ref;
$result = $this->call_trigger('DELIVERY_VALIDATE', $user);
if ($result < 0) { // Rename directory if dir was a temporary ref
$error++; 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 = 'expedition/receipt/".$this->db->escape($this->newref)."'";
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'expedition/receipt/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity);
$resql = $this->db->query($sql);
if (!$resql) {
$error++; $this->error = $this->db->lasterror();
} }
// End call triggers
}
if (!$error) { // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments
$this->oldref = $this->ref; $oldref = dol_sanitizeFileName($this->ref);
$newref = dol_sanitizeFileName($numref);
$dirsource = $conf->expedition->dir_output.'/receipt/'.$oldref;
$dirdest = $conf->expedition->dir_output.'/receipt/'.$newref;
if (!$error && file_exists($dirsource)) {
dol_syslog(get_class($this)."::valid rename dir ".$dirsource." into ".$dirdest);
// Rename directory if dir was a temporary ref if (@rename($dirsource, $dirdest)) {
if (preg_match('/^[\(]?PROV/i', $this->ref)) { dol_syslog("Rename ok");
// Now we rename also files into index // Rename docs starting with $oldref with $newref
$sql = 'UPDATE '.MAIN_DB_PREFIX."ecm_files set filename = CONCAT('".$this->db->escape($this->newref)."', SUBSTR(filename, ".(strlen($this->ref) + 1).")), filepath = 'expedition/receipt/".$this->db->escape($this->newref)."'"; $listoffiles = dol_dir_list($conf->expedition->dir_output.'/receipt/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/'));
$sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%' AND filepath = 'expedition/receipt/".$this->db->escape($this->ref)."' and entity = ".((int) $conf->entity); foreach ($listoffiles as $fileentry) {
$resql = $this->db->query($sql); $dirsource = $fileentry['name'];
if (!$resql) { $dirdest = preg_replace('/^'.preg_quote($oldref, '/').'/', $newref, $dirsource);
$error++; $this->error = $this->db->lasterror(); $dirsource = $fileentry['path'].'/'.$dirsource;
} $dirdest = $fileentry['path'].'/'.$dirdest;
@rename($dirsource, $dirdest);
// 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($numref);
$dirsource = $conf->expedition->dir_output.'/receipt/'.$oldref;
$dirdest = $conf->expedition->dir_output.'/receipt/'.$newref;
if (!$error && file_exists($dirsource)) {
dol_syslog(get_class($this)."::valid 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->expedition->dir_output.'/receipt/'.$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 = $numref;
$this->statut = 1;
}
dol_syslog(get_class($this)."::valid ok");
} }
// Set new ref and current status
if (!$error) { if (!$error) {
$this->db->commit(); $this->ref = $numref;
return 1; $this->statut = 1;
} else {
$this->db->rollback();
return -1;
} }
dol_syslog(get_class($this)."::valid ok");
}
if (!$error) {
$this->db->commit();
return 1;
} else {
$this->db->rollback();
return -1;
} }
} }
} else {
$this->error = "Non autorise";
dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
return -1;
} }
} else {
$this->error = "Non autorise";
dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
return -1;
}
} }
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps