From 5ef681ef912f8e07a51fa14467037d78809c3628 Mon Sep 17 00:00:00 2001 From: Gauthier PC portable 024 Date: Fri, 15 Oct 2021 10:36:47 +0200 Subject: [PATCH] FIX : stickler --- htdocs/core/class/commonobject.class.php | 36 +++++++++++++----------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 2bf6d758435..8689f7c26d1 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -9058,7 +9058,7 @@ abstract class CommonObject $columnName = $deleteFromObject[2]; $TMoreSQL = array(); $more_sql = $deleteFromObject[3]; - if(!empty($more_sql)) $TMoreSQL['customsql'] = $more_sql; + if (!empty($more_sql)) $TMoreSQL['customsql'] = $more_sql; if (dol_include_once($filePath)) { $childObject = new $className($this->db); if (method_exists($childObject, 'deleteByParentField')) { @@ -9144,10 +9144,12 @@ abstract class CommonObject * * @param int $parentId Parent Id * @param string $parentField Name of Foreign key parent column + * @param array $filter an array filter + * @param string $filtermode AND or OR * @return int <0 if KO, >0 if OK * @throws Exception */ - public function deleteByParentField($parentId = 0, $parentField = '', $filter=array(), $filtermode="AND") + public function deleteByParentField($parentId = 0, $parentField = '', $filter = array(), $filtermode = "AND") { global $user; @@ -9160,22 +9162,22 @@ abstract class CommonObject $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element; $sql .= " WHERE ".$parentField." = ".(int) $parentId; - // Manage filter - $sqlwhere = array(); - if (count($filter) > 0) { - foreach ($filter as $key => $value) { + // Manage filters + $sqlwhere = array(); + if (count($filter) > 0) { + foreach ($filter as $key => $value) { if ($key == 'customsql') { - $sqlwhere[] = $value; - } elseif (strpos($value, '%') === false) { - $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')'; - } else { - $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; - } - } - } - if (count($sqlwhere) > 0) { - $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")"; - } + $sqlwhere[] = $value; + } elseif (strpos($value, '%') === false) { + $sqlwhere[] = $key.' IN ('.$this->db->sanitize($this->db->escape($value)).')'; + } else { + $sqlwhere[] = $key.' LIKE \'%'.$this->db->escape($value).'%\''; + } + } + } + if (count($sqlwhere) > 0) { + $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")"; + } $resql = $this->db->query($sql); if (!$resql) {