Clean sql

This commit is contained in:
Laurent Destailleur 2021-09-20 11:30:33 +02:00
parent 9b4e4b0ba5
commit 5397e2d9c3

View File

@ -144,7 +144,6 @@ class EcmDirectory extends CommonObject
// Clean parameters // Clean parameters
$this->label = dol_sanitizeFileName(trim($this->label)); $this->label = dol_sanitizeFileName(trim($this->label));
$this->fk_parent = trim($this->fk_parent);
$this->description = trim($this->description); $this->description = trim($this->description);
$this->date_c = $now; $this->date_c = $now;
$this->fk_user_c = $user->id; $this->fk_user_c = $user->id;
@ -155,7 +154,7 @@ class EcmDirectory extends CommonObject
// Check if same directory does not exists with this name // Check if same directory does not exists with this name
$relativepath = $this->label; $relativepath = $this->label;
if ($this->fk_parent) { if ($this->fk_parent > 0) {
$parent = new EcmDirectory($this->db); $parent = new EcmDirectory($this->db);
$parent->fetch($this->fk_parent); $parent->fetch($this->fk_parent);
$relativepath = $parent->getRelativePath().$relativepath; $relativepath = $parent->getRelativePath().$relativepath;
@ -194,11 +193,11 @@ class EcmDirectory extends CommonObject
$sql .= ") VALUES ("; $sql .= ") VALUES (";
$sql .= " '".$this->db->escape($this->label)."',"; $sql .= " '".$this->db->escape($this->label)."',";
$sql .= " '".$this->db->escape($conf->entity)."',"; $sql .= " '".$this->db->escape($conf->entity)."',";
$sql .= " '".$this->db->escape($this->fk_parent)."',"; $sql .= " ".($this->fk_parent > 0 ? ((int) $this->fk_parent) : "null").",";
$sql .= " '".$this->db->escape($this->description)."',"; $sql .= " '".$this->db->escape($this->description)."',";
$sql .= " ".((int) $this->cachenbofdoc).","; $sql .= " ".((int) $this->cachenbofdoc).",";
$sql .= " '".$this->db->idate($this->date_c)."',"; $sql .= " '".$this->db->idate($this->date_c)."',";
$sql .= " '".$this->db->escape($this->fk_user_c)."'"; $sql .= " ".($this->fk_user_c > 0 ? ((int) $this->fk_user_c) : "null").",";
$sql .= ")"; $sql .= ")";
dol_syslog(get_class($this)."::create", LOG_DEBUG); dol_syslog(get_class($this)."::create", LOG_DEBUG);
@ -249,20 +248,19 @@ class EcmDirectory extends CommonObject
// Clean parameters // Clean parameters
$this->label = trim($this->label); $this->label = trim($this->label);
$this->fk_parent = trim($this->fk_parent);
$this->description = trim($this->description); $this->description = trim($this->description);
if ($this->fk_parent <= 0) {
// Check parameters $this->fk_parent = 0;
// Put here code to add control on parameters values }
$this->db->begin(); $this->db->begin();
// Update request // Update request
$sql = "UPDATE ".MAIN_DB_PREFIX."ecm_directories SET"; $sql = "UPDATE ".MAIN_DB_PREFIX."ecm_directories SET";
$sql .= " label='".$this->db->escape($this->label)."',"; $sql .= " label = '".$this->db->escape($this->label)."',";
$sql .= " fk_parent='".$this->db->escape($this->fk_parent)."',"; $sql .= " fk_parent = ".($this->fk_parent > 0 ? ((int) $this->fk_parent) : "null").",";
$sql .= " description='".$this->db->escape($this->description)."'"; $sql .= " description = '".$this->db->escape($this->description)."'";
$sql .= " WHERE rowid=".((int) $this->id); $sql .= " WHERE rowid = ".((int) $this->id);
dol_syslog(get_class($this)."::update", LOG_DEBUG); dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);