diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 92c09402fe270..78fc835aad1e1 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -1038,15 +1038,26 @@ public function fetchAllByAccount($sortorder = '', $sortfield = '', $limit = 0, * @param string $sortfield Sort field * @param int $limit Limit * @param int $offset Offset limit - * @param string|array $filter Filter array + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param string $filtermode Filter mode (AND or OR) * @param int $showAlreadyExportMovements Show movements when field 'date_export' is not empty (0:No / 1:Yes (Default)) * @return int Return integer <0 if KO, >0 if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND', $showAlreadyExportMovements = 1) + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND', $showAlreadyExportMovements = 1) { global $conf; + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.reconciled_option'] = $search_not_reconciled + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + + dol_syslog(__METHOD__, LOG_DEBUG); $sql = 'SELECT'; @@ -1087,6 +1098,8 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Manage filter if (is_array($filter)) { // deprecated, use $filter = USF syntax + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); + $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { diff --git a/htdocs/asset/class/asset.class.php b/htdocs/asset/class/asset.class.php index 35fb04647dd53..4995b171b0645 100644 --- a/htdocs/asset/class/asset.class.php +++ b/htdocs/asset/class/asset.class.php @@ -386,15 +386,21 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + + $records = array(); $sql = "SELECT "; diff --git a/htdocs/asset/class/assetmodel.class.php b/htdocs/asset/class/assetmodel.class.php index 0e457761f9d2e..b1f033b334dc5 100644 --- a/htdocs/asset/class/assetmodel.class.php +++ b/htdocs/asset/class/assetmodel.class.php @@ -337,15 +337,20 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = "SELECT "; @@ -359,7 +364,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Manage filter $errormessage = ''; - $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage); + $sql .= forgeSQLFromUniversalSearchCriteria($filter['uss'], $errormessage); if ($errormessage) { $this->errors[] = $errormessage; dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 1099a9d0ff700..719a10ecc7e98 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -483,14 +483,20 @@ public function fetchLinesbytypeproduct($typeproduct = 0) * @param string $sortfield Sort field * @param int $limit Limit * @param int $offset Offset - * @param string $filter Filter USF + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '' * @param string $filtermode Filter mode (AND or OR) * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; @@ -1268,7 +1274,7 @@ public function getLinesArray() $this->lines = array(); $objectline = new BOMLine($this->db); - $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_bom:=:'.((int) $this->id).')'); + $result = $objectline->fetchAll('ASC', 'position', 0, 0, ['uss' => '(fk_bom:=:'.((int) $this->id).')']); if (is_numeric($result)) { $this->error = $objectline->error; @@ -1904,15 +1910,20 @@ public function fetch($id, $ref = null) * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; diff --git a/htdocs/bookcal/class/availabilities.class.php b/htdocs/bookcal/class/availabilities.class.php index 7a93c574f9fe7..e3a6f04b129fa 100644 --- a/htdocs/bookcal/class/availabilities.class.php +++ b/htdocs/bookcal/class/availabilities.class.php @@ -380,15 +380,20 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = "SELECT "; @@ -929,7 +934,7 @@ public function getLinesArray() $this->lines = array(); $objectline = new AvailabilitiesLine($this->db); - $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_availabilities:=:'.((int) $this->id).')'); + $result = $objectline->fetchAll('ASC', 'position', 0, 0, ['uss' => '(fk_availabilities:=:'.((int) $this->id).')']); if (is_numeric($result)) { $this->error = $objectline->error; diff --git a/htdocs/bookcal/class/calendar.class.php b/htdocs/bookcal/class/calendar.class.php index 7759ad8919e55..635972a6a4683 100644 --- a/htdocs/bookcal/class/calendar.class.php +++ b/htdocs/bookcal/class/calendar.class.php @@ -340,15 +340,20 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = "SELECT "; @@ -921,7 +926,7 @@ public function getLinesArray() $this->lines = array(); $objectline = new CalendarLine($this->db); - $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_calendar:=:'.((int) $this->id).')'); + $result = $objectline->fetchAll('ASC', 'position', 0, 0, ['uss' => '(fk_calendar:=:'.((int) $this->id).')']); if (is_numeric($result)) { $this->setErrorsFromObject($objectline); diff --git a/htdocs/core/class/cgenericdic.class.php b/htdocs/core/class/cgenericdic.class.php index c39f8cbbf2378..ee3ade0303117 100644 --- a/htdocs/core/class/cgenericdic.class.php +++ b/htdocs/core/class/cgenericdic.class.php @@ -225,14 +225,24 @@ public function fetch($id, $code = '', $label = '') * @param string $sortfield Sort field * @param int $limit Limit * @param int $offset offset limit - * @param string|array $filter filter USF + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param string $filtermode filter mode (AND or OR) * @return int Return integer <0 if KO, >0 if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.xxxx'] = + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $fieldrowid = 'rowid'; $fieldlabel = 'label'; if ($this->table_element == 'c_stcomm') { @@ -251,6 +261,8 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); + $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { diff --git a/htdocs/core/class/cleadstatus.class.php b/htdocs/core/class/cleadstatus.class.php index f72f9dddc7d29..87f5a29862ece 100644 --- a/htdocs/core/class/cleadstatus.class.php +++ b/htdocs/core/class/cleadstatus.class.php @@ -170,14 +170,24 @@ public function fetch($id, $code = '') * @param string $sortfield Sort field * @param int $limit Limit * @param int $offset Offset - * @param string $filter Filter USF + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param string $filtermode Filter mode (AND or OR) * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.xxxx'] = + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $sql = "SELECT"; $sql .= " t.rowid,"; $sql .= " t.code,"; @@ -190,6 +200,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index d58838ca9f3ec..d1c166ce3dd27 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -260,13 +260,18 @@ public function getLabelOfUnit($type = 'long') * @param string $sortfield Sort field * @param int $limit Limit the number of lines returned * @param int $offset Offset - * @param string|array $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + return 0; } } diff --git a/htdocs/core/class/cproductnature.class.php b/htdocs/core/class/cproductnature.class.php index 749b07b402905..80faaa7065c2d 100644 --- a/htdocs/core/class/cproductnature.class.php +++ b/htdocs/core/class/cproductnature.class.php @@ -156,14 +156,24 @@ public function fetch($id, $code = '') * @param string $sortfield Sort field * @param int $limit Limit * @param int $offset Offset - * @param string $filter Filter USF + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param string $filtermode Filter mode (AND or OR) * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.xxxx'] = + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $sql = "SELECT"; $sql .= " t.rowid,"; $sql .= " t.code,"; @@ -174,6 +184,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { diff --git a/htdocs/core/class/ctyperesource.class.php b/htdocs/core/class/ctyperesource.class.php index 076b71983538e..71dcdbfc61117 100644 --- a/htdocs/core/class/ctyperesource.class.php +++ b/htdocs/core/class/ctyperesource.class.php @@ -199,14 +199,24 @@ public function fetch($id, $code = '', $label = '') * @param string $sortfield Sort field * @param int $limit Limit * @param int $offset Offset limit - * @param string|array $filter filter array + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param string $filtermode filter mode (AND or OR) * @return int Return integer <0 if KO, >0 if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.xxxx'] = + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $sql = "SELECT"; $sql .= " t.rowid,"; $sql .= " t.code,"; @@ -217,6 +227,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { diff --git a/htdocs/core/class/cunits.class.php b/htdocs/core/class/cunits.class.php index 8d66112174e20..ec4e25e8cee31 100644 --- a/htdocs/core/class/cunits.class.php +++ b/htdocs/core/class/cunits.class.php @@ -212,14 +212,24 @@ public function fetch($id, $code = '', $short_label = '', $unit_type = '') * @param string $sortfield Sort field * @param int $limit Limit * @param int $offset Offset - * @param string|array $filter Filter USF + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param string $filtermode Filter mode (AND or OR) * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.xxxx'] = + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $sql = "SELECT"; $sql .= " t.rowid,"; $sql .= " t.code,"; @@ -234,6 +244,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { diff --git a/htdocs/core/class/defaultvalues.class.php b/htdocs/core/class/defaultvalues.class.php index 100f57246fb1b..9eaa7b22cdba4 100644 --- a/htdocs/core/class/defaultvalues.class.php +++ b/htdocs/core/class/defaultvalues.class.php @@ -240,15 +240,24 @@ public function fetch($id) * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string|array $filter Filter as an Universal Search string or Array (array use is deprecated) - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like 't.page' => 'comm/action/card.php' + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $records = array(); $sql = "SELECT "; @@ -258,6 +267,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Deprecated. For compatibility. if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { diff --git a/htdocs/core/class/timespent.class.php b/htdocs/core/class/timespent.class.php index fe72570d87823..8900d51a64dc4 100644 --- a/htdocs/core/class/timespent.class.php +++ b/htdocs/core/class/timespent.class.php @@ -318,15 +318,20 @@ public function fetch($id, $ref = null) * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { global $conf; + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + dol_syslog(__METHOD__, LOG_DEBUG); $records = array(); diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 4776907192f0c..487c9f21dde51 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -241,7 +241,7 @@ function project_prepare_head(Project $project, $moreparam = '') } else { require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorbooth.class.php'; $conforbooth = new ConferenceOrBooth($db); - $result = $conforbooth->fetchAll('', '', 0, 0, '(t.fk_project:=:'.((int) $project->id).")"); + $result = $conforbooth->fetchAll('', '', 0, 0, ['uss' => '(t.fk_project:=:'.((int) $project->id).')']); //, if (!is_array($result) && $result < 0) { setEventMessages($conforbooth->error, $conforbooth->errors, 'errors'); @@ -257,7 +257,7 @@ function project_prepare_head(Project $project, $moreparam = '') } else { require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php'; $conforboothattendee = new ConferenceOrBoothAttendee($db); - $result = $conforboothattendee->fetchAll('', '', 0, 0, '(t.fk_project:=:'.((int) $project->id).')'); + $result = $conforboothattendee->fetchAll('', '', 0, 0, ['uss' => '(t.fk_project:=:'.((int) $project->id).')']); if (!is_array($result) && $result < 0) { setEventMessages($conforboothattendee->error, $conforboothattendee->errors, 'errors'); diff --git a/htdocs/core/tpl/card_presend.tpl.php b/htdocs/core/tpl/card_presend.tpl.php index 53313f06e9035..22bd16d542b80 100644 --- a/htdocs/core/tpl/card_presend.tpl.php +++ b/htdocs/core/tpl/card_presend.tpl.php @@ -229,7 +229,7 @@ if (getDolGlobalString('MAIN_MAIL_ENABLED_USER_DEST_SELECT')) { $listeuser = array(); $fuserdest = new User($db); - $result = $fuserdest->fetchAll('ASC', 't.lastname', 0, 0, "(t.statut:=:1) AND (t.employee:=:1) AND (t.email:isnot:NULL) AND (t.email:!=:'')", 'AND', true); + $result = $fuserdest->fetchAll('ASC', 't.lastname', 0, 0, ['uss' => "(t.statut:=:1) AND (t.employee:=:1) AND (t.email:isnot:NULL) AND (t.email:!=:'')"], 'AND', true); if ($result > 0 && is_array($fuserdest->users) && count($fuserdest->users) > 0) { foreach ($fuserdest->users as $uuserdest) { $listeuser[$uuserdest->id] = $uuserdest->user_get_property($uuserdest->id, 'email'); diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index 34623fedd339f..53c9276a5a018 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -519,14 +519,24 @@ public function fetch(int $id, string $objectname = '', string $methodname = '') * @param int $limit Limit page * @param int $offset Offset ppage * @param int $status Display active or not - * @param string|array $filter Filter USF. + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param int $processing Processing or not (-1=all, 0=not in progress, 1=in progress) * @return int if KO: <0 || if OK: >0 */ - public function fetchAll(string $sortorder = 'DESC', string $sortfield = 't.rowid', int $limit = 0, int $offset = 0, int $status = 1, $filter = '', int $processing = -1) + public function fetchAll(string $sortorder = 'DESC', string $sortfield = 't.rowid', int $limit = 0, int $offset = 0, int $status = 1, array $filter = array(), int $processing = -1) { $this->lines = array(); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.xxxx'] = + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $sql = "SELECT"; $sql .= " t.rowid,"; $sql .= " t.entity,"; @@ -575,6 +585,7 @@ public function fetchAll(string $sortorder = 'DESC', string $sortfield = 't.rowi // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); if (count($filter) > 0) { foreach ($filter as $key => $value) { if ($key == 't.rowid') { diff --git a/htdocs/ecm/class/ecmfiles.class.php b/htdocs/ecm/class/ecmfiles.class.php index 7cac5150b4815..bbfe04b1f83a8 100644 --- a/htdocs/ecm/class/ecmfiles.class.php +++ b/htdocs/ecm/class/ecmfiles.class.php @@ -535,14 +535,24 @@ public function fetch($id, $ref = '', $relativepath = '', $hashoffile = '', $has * @param string $sortfield Sort field * @param int $limit Limit * @param int $offset Offset limit - * @param string|array $filter filter array + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param string $filtermode filter mode (AND or OR) * @return int Return integer <0 if KO, >0 if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like 't.src_object_type' => $objectType + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $sql = 'SELECT'; $sql .= ' t.rowid,'; $sql .= " t.label,"; @@ -569,6 +579,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { diff --git a/htdocs/eventorganization/class/conferenceorbooth.class.php b/htdocs/eventorganization/class/conferenceorbooth.class.php index 693a53153dba8..a9326d89e088a 100644 --- a/htdocs/eventorganization/class/conferenceorbooth.class.php +++ b/htdocs/eventorganization/class/conferenceorbooth.class.php @@ -273,18 +273,23 @@ public function fetch($id, $ref = null, $ref_ext = '', $email_msgid = '', $loadr * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { //TODO set percent according status global $conf; dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; diff --git a/htdocs/eventorganization/class/conferenceorboothattendee.class.php b/htdocs/eventorganization/class/conferenceorboothattendee.class.php index b7632a2f4047f..2c6b3dffc6a40 100644 --- a/htdocs/eventorganization/class/conferenceorboothattendee.class.php +++ b/htdocs/eventorganization/class/conferenceorboothattendee.class.php @@ -398,15 +398,20 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; diff --git a/htdocs/eventorganization/lib/eventorganization_conferenceorbooth.lib.php b/htdocs/eventorganization/lib/eventorganization_conferenceorbooth.lib.php index 2945f6ae3fb0a..71a28c7647692 100644 --- a/htdocs/eventorganization/lib/eventorganization_conferenceorbooth.lib.php +++ b/htdocs/eventorganization/lib/eventorganization_conferenceorbooth.lib.php @@ -141,7 +141,7 @@ function conferenceorboothProjectPrepareHead($object) } else { require_once DOL_DOCUMENT_ROOT . '/eventorganization/class/conferenceorbooth.class.php'; $conforbooth = new ConferenceOrBooth($db); - $result = $conforbooth->fetchAll('', '', 0, 0, '(t.fk_project:=:' . ((int) $object->id) . ')'); + $result = $conforbooth->fetchAll('', '', 0, 0, ['uss' => '(t.fk_project:=:' . ((int) $object->id) . ')']); if (!is_array($result) && $result < 0) { setEventMessages($conforbooth->error, $conforbooth->errors, 'errors'); } else { @@ -167,7 +167,7 @@ function conferenceorboothProjectPrepareHead($object) } else { require_once DOL_DOCUMENT_ROOT . '/eventorganization/class/conferenceorboothattendee.class.php'; $attendees = new ConferenceOrBoothAttendee($db); - $result = $attendees->fetchAll('', '', 0, 0, '(t.fk_project:=:' . ((int) $object->id) . ')'); + $result = $attendees->fetchAll('', '', 0, 0, ['uss' => '(t.fk_project:=:' . ((int) $object->id) . ')']); if (!is_array($result) && $result < 0) { setEventMessages($attendees->error, $attendees->errors, 'errors'); } else { diff --git a/htdocs/hrm/class/evaluation.class.php b/htdocs/hrm/class/evaluation.class.php index be26c8531992c..3f91eae49b2c1 100644 --- a/htdocs/hrm/class/evaluation.class.php +++ b/htdocs/hrm/class/evaluation.class.php @@ -224,7 +224,7 @@ public function create(User $user, $notrigger = 0) if ($resultcreate > 0) { require_once DOL_DOCUMENT_ROOT . '/hrm/class/skillrank.class.php'; $skillRank = new SkillRank($this->db); - $TRequiredRanks = $skillRank->fetchAll('ASC', 't.rowid', 0, 0, '(fk_object:=:'.((int) $this->fk_job).") AND (objecttype:=:'job')"); + $TRequiredRanks = $skillRank->fetchAll('ASC', 't.rowid', 0, 0, ['uss' => '(fk_object:=:'.((int) $this->fk_job).") AND (objecttype:=:'job')"]); if (is_array($TRequiredRanks) && !empty($TRequiredRanks)) { $this->lines = array(); @@ -381,15 +381,20 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; @@ -907,7 +912,7 @@ public function getLinesArray() $this->lines = array(); $objectline = new EvaluationLine($this->db); - $result = $objectline->fetchAll('ASC', '', 0, 0, '(fk_evaluation:=:'.((int) $this->id).')'); + $result = $objectline->fetchAll('ASC', '', 0, 0, ['uss' => '(fk_evaluation:=:'.((int) $this->id).')']); if (is_numeric($result)) { $this->setErrorsFromObject($objectline); diff --git a/htdocs/hrm/class/evaluationdet.class.php b/htdocs/hrm/class/evaluationdet.class.php index 6c6bbfdc15969..d277d2921b979 100644 --- a/htdocs/hrm/class/evaluationdet.class.php +++ b/htdocs/hrm/class/evaluationdet.class.php @@ -357,17 +357,22 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { global $conf; dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; @@ -887,7 +892,7 @@ public function getLinesArray() $this->lines = array(); $objectline = new EvaluationLine($this->db); - $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_evaluationdet:=:'.((int) $this->id).')'); + $result = $objectline->fetchAll('ASC', 'position', 0, 0, ['uss' => '(fk_evaluationdet:=:'.((int) $this->id).')']); if (is_numeric($result)) { $this->setErrorsFromObject($objectline); diff --git a/htdocs/hrm/class/job.class.php b/htdocs/hrm/class/job.class.php index 72e83fffbd114..f2561da97a52e 100644 --- a/htdocs/hrm/class/job.class.php +++ b/htdocs/hrm/class/job.class.php @@ -352,15 +352,20 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; @@ -916,7 +921,7 @@ public function getLinesArray() $this->lines = array(); $objectline = new JobLine($this->db); - $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_job:=:'.((int) $this->id).')'); + $result = $objectline->fetchAll('ASC', 'position', 0, 0, ['uss' => '(fk_job:=:'.((int) $this->id).')']); if (is_numeric($result)) { $this->setErrorsFromObject($objectline); diff --git a/htdocs/hrm/class/position.class.php b/htdocs/hrm/class/position.class.php index 7d257e5d41c80..4360e8b016ce5 100644 --- a/htdocs/hrm/class/position.class.php +++ b/htdocs/hrm/class/position.class.php @@ -359,15 +359,20 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; @@ -956,7 +961,7 @@ public function getLinesArray() $this->lines = array(); $objectline = new PositionLine($this->db); - $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_position:=:'.((int) $this->id).')'); + $result = $objectline->fetchAll('ASC', 'position', 0, 0, ['uss' => '(fk_position:=:'.((int) $this->id).')']); if (is_numeric($result)) { $this->setErrorsFromObject($objectline); @@ -1032,7 +1037,7 @@ public function getForUser($userid) { $TPosition = array(); - $TPosition = $this->fetchAll('ASC', 't.rowid', 0, 0, '(fk_user:=:'.((int) $userid).')'); + $TPosition = $this->fetchAll('ASC', 't.rowid', 0, 0, ['uss' => '(fk_user:=:'.((int) $userid).')']); return $TPosition; } diff --git a/htdocs/hrm/class/skill.class.php b/htdocs/hrm/class/skill.class.php index 659de91bb318f..1e43f28d370fe 100644 --- a/htdocs/hrm/class/skill.class.php +++ b/htdocs/hrm/class/skill.class.php @@ -400,7 +400,7 @@ public function fetchLines() $this->lines = array(); require_once __DIR__ . '/skilldet.class.php'; $skilldet = new Skilldet($this->db); - $this->lines = $skilldet->fetchAll('ASC', '', 0, 0, '(fk_skill:=:'.$this->id.')'); + $this->lines = $skilldet->fetchAll('ASC', '', 0, 0, ['uss' => '(fk_skill:=:'.$this->id.')']); if (is_array($this->lines)) { return (count($this->lines) > 0) ? $this->lines : array(); @@ -419,15 +419,20 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; @@ -956,7 +961,7 @@ public function getLinesArray() $this->lines = array(); $objectline = new Skilldet($this->db); - $result = $objectline->fetchAll('ASC', 'rankorder', 0, 0, '(fk_skill:=:'.((int) $this->id).')'); + $result = $objectline->fetchAll('ASC', 'rankorder', 0, 0, ['uss' => '(fk_skill:=:'.((int) $this->id).')']); if (is_numeric($result)) { $this->setErrorsFromObject($objectline); diff --git a/htdocs/hrm/class/skilldet.class.php b/htdocs/hrm/class/skilldet.class.php index ab036ae066400..fd0d8eb5aabc1 100644 --- a/htdocs/hrm/class/skilldet.class.php +++ b/htdocs/hrm/class/skilldet.class.php @@ -351,15 +351,20 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; diff --git a/htdocs/hrm/class/skillrank.class.php b/htdocs/hrm/class/skillrank.class.php index 3f647aff86322..6c0c016b11c02 100644 --- a/htdocs/hrm/class/skillrank.class.php +++ b/htdocs/hrm/class/skillrank.class.php @@ -211,7 +211,7 @@ public function create(User $user, $notrigger = 0) { global $langs; - $filter = '(fk_object:=:'.((int) $this->fk_object).") AND (objecttype:=:'".$this->db->escape($this->objecttype)."') AND (fk_skill:=:".((int) $this->fk_skill).")"; + $filter = ['uss' => '(fk_object:=:'.((int) $this->fk_object).") AND (objecttype:=:'".$this->db->escape($this->objecttype)."') AND (fk_skill:=:".((int) $this->fk_skill).")"]; $alreadyLinked = $this->fetchAll('ASC', 'rowid', 0, 0, $filter); if (!empty($alreadyLinked)) { @@ -392,15 +392,20 @@ public function cloneFromCurrentSkill($currentSkill, $fk_user) * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; @@ -916,7 +921,7 @@ public function getLinesArray() /* $objectline = new SkillRankLine($this->db); - $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_skillrank:=:'.((int) $this->id).')'); + $result = $objectline->fetchAll('ASC', 'position', 0, 0, ['uss' => '(fk_skillrank:=:'.((int) $this->id).')']); if (is_numeric($result)) { $this->error = $objectline->error; diff --git a/htdocs/hrm/evaluation_card.php b/htdocs/hrm/evaluation_card.php index 5cddbd523be06..4defe59c89ae7 100644 --- a/htdocs/hrm/evaluation_card.php +++ b/htdocs/hrm/evaluation_card.php @@ -169,7 +169,7 @@ if ($action == 'close') { // save evaldet lines to user; $sk = new SkillRank($db); - $SkillrecordsForActiveUser = $sk->fetchAll('ASC', 'fk_skill', 0, 0, "(fk_object:=:".((int) $object->fk_user).") AND (objecttype:=:'".$db->escape(SkillRank::SKILLRANK_TYPE_USER)."')", 'AND'); + $SkillrecordsForActiveUser = $sk->fetchAll('ASC', 'fk_skill', 0, 0, ['uss' => "(fk_object:=:".((int) $object->fk_user).") AND (objecttype:=:'".$db->escape(SkillRank::SKILLRANK_TYPE_USER)."')"], 'AND'); $errors = 0; // we go through the evaldets of the eval diff --git a/htdocs/hrm/lib/hrm_skillrank.lib.php b/htdocs/hrm/lib/hrm_skillrank.lib.php index 1d0083ea37f36..c9e3876ecad6c 100644 --- a/htdocs/hrm/lib/hrm_skillrank.lib.php +++ b/htdocs/hrm/lib/hrm_skillrank.lib.php @@ -113,7 +113,7 @@ function displayRankInfos($selected_rank, $fk_skill, $inputname = 'TNote', $mode // On charge les différentes notes possibles pour la compétence $fk_skill $skilldet = new Skilldet($db); - $Lines = $skilldet->fetchAll('ASC', 'rankorder', 0, 0, '(fk_skill:=:'.((int) $fk_skill).')'); + $Lines = $skilldet->fetchAll('ASC', 'rankorder', 0, 0, ['uss' => '(fk_skill:=:'.((int) $fk_skill).')']); if (!is_array($Lines) && $Lines<0) { setEventMessages($skilldet->error, $skilldet->errors, 'errors'); diff --git a/htdocs/hrm/skill_tab.php b/htdocs/hrm/skill_tab.php index ea6715d77345c..5ee2057f34054 100644 --- a/htdocs/hrm/skill_tab.php +++ b/htdocs/hrm/skill_tab.php @@ -161,7 +161,7 @@ } elseif ($action == 'saveSkill') { if (!empty($TNote)) { foreach ($TNote as $skillId => $rank) { - $TSkills = $skill->fetchAll('ASC', 't.rowid', 0, 0, '(fk_object:=:'.((int) $id).") AND (objecttype:=:'".$db->escape($objecttype)."') AND (fk_skill:=:".((int) $skillId).')'); + $TSkills = $skill->fetchAll('ASC', 't.rowid', 0, 0, ['uss' => '(fk_object:=:'.((int) $id).") AND (objecttype:=:'".$db->escape($objecttype)."') AND (fk_skill:=:".((int) $skillId).')']); if (is_array($TSkills) && !empty($TSkills)) { foreach ($TSkills as $tmpObj) { $tmpObj->rankorder = $rank; diff --git a/htdocs/knowledgemanagement/class/knowledgerecord.class.php b/htdocs/knowledgemanagement/class/knowledgerecord.class.php index cd89f83ccace9..b9544c4425b6b 100644 --- a/htdocs/knowledgemanagement/class/knowledgerecord.class.php +++ b/htdocs/knowledgemanagement/class/knowledgerecord.class.php @@ -360,14 +360,24 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit Limit * @param int $offset Offset - * @param string|array $filter Filter USF. + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param string $filtermode Filter mode (AND or OR) * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.xxxx'] = + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $records = array(); $sql = 'SELECT '; @@ -381,6 +391,8 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); + $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { @@ -975,7 +987,7 @@ public function getLinesArray() $this->lines = array(); $objectline = new KnowledgeRecordLine($this->db); - $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_knowledgerecord:=:'.((int) $this->id).')'); + $result = $objectline->fetchAll('ASC', 'position', 0, 0, ['uss' => '(fk_knowledgerecord:=:'.((int) $this->id).')']); if (is_numeric($result)) { $this->error = $objectline->error; diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index ef79e85f7488a..bf6b71e916db0 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -433,15 +433,20 @@ public function fetchLines($noextrafields = 0) * @param string $sortfield Sort field * @param int $limit Limit the number of lines returned * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 1000, $offset = 0, string $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 1000, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = "SELECT "; @@ -1084,7 +1089,7 @@ public function getLinesArray() $this->lines = array(); $objectline = new MyObjectLine($this->db); - $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_myobject:=:'.((int) $this->id).')'); + $result = $objectline->fetchAll('ASC', 'position', 0, 0, ['uss' => '(fk_myobject:=:'.((int) $this->id).')']); if (is_numeric($result)) { $this->setErrorsFromObject($objectline); diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index 565339953d228..a5d813af48918 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -483,14 +483,24 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit Limit * @param int $offset Offset - * @param string|array $filter Filter USF. + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param string $filtermode Filter mode (AND or OR) * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.xxxx'] = + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $records = array(); $sql = 'SELECT '; @@ -504,6 +514,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { @@ -925,7 +936,7 @@ public function deleteLine(User $user, $idline, $notrigger = 0, $fk_movement = 0 if (!empty($fk_movement)) { // The fk_movement was not recorded so we try to guess the product and quantity to restore. $moline = new MoLine($this->db); - $TArrayMoLine = $moline->fetchAll('', '', 1, 0, '(fk_stock_movement:=:'.((int) $fk_movement).')'); + $TArrayMoLine = $moline->fetchAll('', '', 1, 0, ['uss' => '(fk_stock_movement:=:'.((int) $fk_movement).')']); $moline = array_shift($TArrayMoLine); $movement = new MouvementStock($this->db); @@ -1631,7 +1642,7 @@ public function getLinesArray($rolefilter = '') if (!empty($rolefilter)) { $filter .= " AND (role:=:'".$this->db->escape($rolefilter)."')"; } - $result = $objectline->fetchAll('ASC', 'position', 0, 0, $filter); + $result = $objectline->fetchAll('ASC', 'position', 0, 0, ['uss' => $filter]); if (is_numeric($result)) { $this->error = $objectline->error; @@ -2190,14 +2201,20 @@ public function fetch($id, $ref = null) * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string|array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...) + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param string $filtermode Filter mode (AND or OR) * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; diff --git a/htdocs/opensurvey/class/opensurveysondage.class.php b/htdocs/opensurvey/class/opensurveysondage.class.php index 91e62bdd41432..477c91c8c3acd 100644 --- a/htdocs/opensurvey/class/opensurveysondage.class.php +++ b/htdocs/opensurvey/class/opensurveysondage.class.php @@ -808,15 +808,20 @@ public function countVotes() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; diff --git a/htdocs/partnership/class/partnership.class.php b/htdocs/partnership/class/partnership.class.php index 0355ae0e9e882..1b4fbbb3a013f 100644 --- a/htdocs/partnership/class/partnership.class.php +++ b/htdocs/partnership/class/partnership.class.php @@ -421,14 +421,24 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit Limit * @param int $offset Offset page - * @param string|array $filter Filter USF. + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param string $filtermode Filter mode (AND or OR) * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.xxxx'] = + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $records = array(); $sql = 'SELECT '; @@ -442,6 +452,8 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); + $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { @@ -1184,7 +1196,7 @@ public function getLinesArray() $this->lines = array(); $objectline = new PartnershipLine($this->db); - $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_partnership:=:'.((int) $this->id).')'); + $result = $objectline->fetchAll('ASC', 'position', 0, 0, ['uss' => '(fk_partnership:=:'.((int) $this->id).')']); if (is_numeric($result)) { $this->error = $objectline->error; diff --git a/htdocs/partnership/class/partnership_type.class.php b/htdocs/partnership/class/partnership_type.class.php index 82719f1338fbd..9719bb4b5be53 100644 --- a/htdocs/partnership/class/partnership_type.class.php +++ b/htdocs/partnership/class/partnership_type.class.php @@ -152,17 +152,22 @@ public function fetch($id, $ref = null) * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { global $conf; dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = "SELECT "; diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 88c2acf96a7fe..12866abafbb31 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1078,7 +1078,7 @@ $filter = array('t.fk_product' => $object->id, 't.fk_soc' => $soc->id); - $result = $prodcustprice->fetchAll('', '', 0, 0, $filter); + $result = $prodcustprice->fetchAll('', '', 0, 0, ['uss' => $filter]); if ($result) { if (count($prodcustprice->lines) > 0) { $pu_ht = price($prodcustprice->lines [0]->price); diff --git a/htdocs/product/class/productcustomerprice.class.php b/htdocs/product/class/productcustomerprice.class.php index a276108342a3f..a25e7458b5bcd 100644 --- a/htdocs/product/class/productcustomerprice.class.php +++ b/htdocs/product/class/productcustomerprice.class.php @@ -383,12 +383,23 @@ public function fetch($id) * @param string $sortfield Sort field * @param int $limit Limit page * @param int $offset offset - * @param string|array $filter Filter USF. + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @return int Return integer <0 if KO, >0 if OK * @since dolibarr v17 */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array()) { + + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like 't.fk_product' => $prod->id + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + if (empty($sortfield)) { $sortfield = "t.rowid"; } @@ -431,6 +442,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); if (count($filter) > 0) { foreach ($filter as $key => $value) { if (strpos($key, 'date')) { // To allow $filter['YEAR(s.dated)']=>$year diff --git a/htdocs/product/class/productfournisseurprice.class.php b/htdocs/product/class/productfournisseurprice.class.php index 9a66040e440c7..e767f42ba7611 100644 --- a/htdocs/product/class/productfournisseurprice.class.php +++ b/htdocs/product/class/productfournisseurprice.class.php @@ -315,14 +315,24 @@ public function fetch($id) * @param string $sortfield Sort field * @param int $limit Limit * @param int $offset Offset - * @param string|array $filter Filter USF. + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param string $filtermode Filter mode (AND or OR) * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.xxxx'] = + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $records = array(); $sql = "SELECT "; @@ -336,6 +346,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { diff --git a/htdocs/product/stock/class/productstockentrepot.class.php b/htdocs/product/stock/class/productstockentrepot.class.php index b65e8e0426266..65e08c3990dfb 100644 --- a/htdocs/product/stock/class/productstockentrepot.class.php +++ b/htdocs/product/stock/class/productstockentrepot.class.php @@ -235,14 +235,24 @@ public function fetch($id, $fk_product = 0, $fk_entrepot = 0) * @param string $sortfield Sort field * @param int $limit Limit * @param int $offset Offset limit - * @param string|array $filter Filter USF. + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param string $filtermode Filter mode (AND or OR) * @return int|array Return integer <0 if KO, array if OK */ - public function fetchAll($fk_product = 0, $fk_entrepot = 0, $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($fk_product = 0, $fk_entrepot = 0, $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.xxxx'] = + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $sql = "SELECT"; $sql .= " t.rowid,"; $sql .= " t.tms,"; @@ -256,6 +266,7 @@ public function fetchAll($fk_product = 0, $fk_entrepot = 0, $sortorder = '', $so // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { diff --git a/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php b/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php index 463b65ad54870..182b2ae95480b 100644 --- a/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php +++ b/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php @@ -414,15 +414,20 @@ public function getValorisationTotale() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; @@ -939,7 +944,7 @@ public function getLinesArray() $this->lines = array(); $objectline = new StockTransferLine($this->db); - $result = $objectline->fetchAll('ASC', 'rang', 0, 0, "(fk_stocktransfer:=:".((int) $this->id).")"); + $result = $objectline->fetchAll('ASC', 'rang', 0, 0, ['uss' => "(fk_stocktransfer:=:".((int) $this->id).")"]); if (is_numeric($result)) { $this->error = $objectline->error; diff --git a/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php b/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php index bc206a34f9243..d17bca786f3aa 100644 --- a/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php +++ b/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php @@ -299,15 +299,20 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; diff --git a/htdocs/product/stock/stocktransfer/stocktransfer_card.php b/htdocs/product/stock/stocktransfer/stocktransfer_card.php index 15ccc7da44851..fa3e134386f85 100644 --- a/htdocs/product/stock/stocktransfer/stocktransfer_card.php +++ b/htdocs/product/stock/stocktransfer/stocktransfer_card.php @@ -200,7 +200,7 @@ if (empty($error)) { $line = new StockTransferLine($db); - $records = $line->fetchAll('', '', 0, 0, '(fk_stocktransfer:=:'.((int) $id).') AND (fk_product:=:'.((int) $fk_product).') AND (fk_warehouse_source:=:'.((int) $fk_warehouse_source).') AND (fk_warehouse_destination:=:'.((int) $fk_warehouse_destination).') AND ('.(empty($batch) ? "(batch:=:'') OR (batch:IS:NULL)" : "batch:=:'".$db->escape($batch)."'").')'); + $records = $line->fetchAll('', '', 0, 0, ['uss' => '(fk_stocktransfer:=:'.((int) $id).') AND (fk_product:=:'.((int) $fk_product).') AND (fk_warehouse_source:=:'.((int) $fk_warehouse_source).') AND (fk_warehouse_destination:=:'.((int) $fk_warehouse_destination).') AND ('.(empty($batch) ? "(batch:=:'') OR (batch:IS:NULL)" : "batch:=:'".$db->escape($batch)."'").')']); if (!empty($records[key($records)])) { $line = $records[key($records)]; } diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index f4a20b6020148..5c1dedf223587 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -993,7 +993,7 @@ if ($object->usage_organize_event) { require_once DOL_DOCUMENT_ROOT.'/eventorganization/class/conferenceorboothattendee.class.php'; $conforboothattendee = new ConferenceOrBoothAttendee($db); - $result = $conforboothattendee->fetchAll('', '', 0, 0, '(t.fk_project:=:'.((int) $object->id).') AND (t.status:=:'.ConferenceOrBoothAttendee::STATUS_VALIDATED.')'); + $result = $conforboothattendee->fetchAll('', '', 0, 0, ['uss' => '(t.fk_project:=:'.((int) $object->id).') AND (t.status:=:'.ConferenceOrBoothAttendee::STATUS_VALIDATED.')']); if (!is_array($result) && $result < 0) { setEventMessages($conforboothattendee->error, $conforboothattendee->errors, 'errors'); diff --git a/htdocs/public/bookcal/index.php b/htdocs/public/bookcal/index.php index 02b830e47cf23..62f3f9c14f53f 100644 --- a/htdocs/public/bookcal/index.php +++ b/htdocs/public/bookcal/index.php @@ -427,7 +427,7 @@ function llxHeaderVierge($title, $head = "", $disablejs = 0, $disablehead = 0, $ // Load into an array all days with availabilities of the calendar for the current month $todayarray['mon'] and $todayarray['year'] $arrayofavailabledays = array(); - $arrayofavailabilities = $availability->fetchAll('', '', 0, 0, '(status:=:1) AND (fk_bookcal_calendar:=:'.((int) $id).')'); + $arrayofavailabilities = $availability->fetchAll('', '', 0, 0, ['uss' => '(status:=:1) AND (fk_bookcal_calendar:=:'.((int) $id).')']); if ($arrayofavailabilities < 0) { setEventMessages($availability->error, $availability->errors, 'errors'); } else { diff --git a/htdocs/public/eventorganization/attendee_new.php b/htdocs/public/eventorganization/attendee_new.php index f8bacc3d940da..191a59de02679 100644 --- a/htdocs/public/eventorganization/attendee_new.php +++ b/htdocs/public/eventorganization/attendee_new.php @@ -276,7 +276,7 @@ function llxFooterVierge() } // Check if there is already an attendee into table eventorganization_conferenceorboothattendee for same event (or conference/booth) - $resultfetchconfattendee = $confattendee->fetchAll('', '', 0, 0, $filter); + $resultfetchconfattendee = $confattendee->fetchAll('', '', 0, 0, ['uss' => $filter]); if (is_array($resultfetchconfattendee) && count($resultfetchconfattendee) > 0) { // Found confattendee diff --git a/htdocs/public/opensurvey/index.php b/htdocs/public/opensurvey/index.php index b07b047d58640..7e6b5fd08018e 100644 --- a/htdocs/public/opensurvey/index.php +++ b/htdocs/public/opensurvey/index.php @@ -170,7 +170,7 @@ } -$results = $object->fetchAll($sortorder, $sortfield, 0, 0, '(status:=:1)'); +$results = $object->fetchAll($sortorder, $sortfield, 0, 0, ['uss' => '(status:=:1)']); $now = dol_now(); if (is_array($results)) { diff --git a/htdocs/public/partnership/new.php b/htdocs/public/partnership/new.php index 9a1db3d88ccab..77e0cbd1c9ee3 100644 --- a/htdocs/public/partnership/new.php +++ b/htdocs/public/partnership/new.php @@ -598,7 +598,7 @@ function llxFooterVierge() // Type $partnershiptype = new PartnershipType($db); -$listofpartnershipobj = $partnershiptype->fetchAll('', '', 1000, 0, '(active:=:1)'); +$listofpartnershipobj = $partnershiptype->fetchAll('', '', 1000, 0, ['uss' => '(active:=:1)']); $listofpartnership = array(); foreach ($listofpartnershipobj as $partnershipobj) { $listofpartnership[$partnershipobj->id] = $partnershipobj->label; diff --git a/htdocs/public/recruitment/index.php b/htdocs/public/recruitment/index.php index 5615e8133e20f..77f678d51b0c3 100644 --- a/htdocs/public/recruitment/index.php +++ b/htdocs/public/recruitment/index.php @@ -171,7 +171,7 @@ } -$results = $object->fetchAll($sortorder, $sortfield, 0, 0, '(status:=:1)'); +$results = $object->fetchAll($sortorder, $sortfield, 0, 0, ['uss' => '(status:=:1)']); $now = dol_now(); if (is_array($results)) { diff --git a/htdocs/reception/class/receptionlinebatch.class.php b/htdocs/reception/class/receptionlinebatch.class.php index 26d77de5b3c29..634cf6697f297 100644 --- a/htdocs/reception/class/receptionlinebatch.class.php +++ b/htdocs/reception/class/receptionlinebatch.class.php @@ -668,14 +668,24 @@ public function initAsSpecimen() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset offset limit - * @param string|array $filter filter array + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param string $filtermode filter mode (AND or OR) * @return int Return integer <0 if KO, >0 if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.xxxx'] = + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $sql = "SELECT"; $sql .= " t.rowid,"; $sql .= " t.fk_element,"; @@ -695,6 +705,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { diff --git a/htdocs/recruitment/class/recruitmentcandidature.class.php b/htdocs/recruitment/class/recruitmentcandidature.class.php index 7fa4a473d5c72..447888032545d 100644 --- a/htdocs/recruitment/class/recruitmentcandidature.class.php +++ b/htdocs/recruitment/class/recruitmentcandidature.class.php @@ -353,15 +353,20 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; @@ -907,7 +912,7 @@ public function getLinesArray() $this->lines = array(); $objectline = new RecruitmentCandidatureLine($this->db); - $result = $objectline->fetchAll('ASC', 'position', 0, 0, '(fk_recruitmentcandidature:=:'.((int) $this->id).')'); + $result = $objectline->fetchAll('ASC', 'position', 0, 0, ['uss' => '(fk_recruitmentcandidature:=:'.((int) $this->id).')']); if (is_numeric($result)) { $this->error = $objectline->error; diff --git a/htdocs/recruitment/class/recruitmentjobposition.class.php b/htdocs/recruitment/class/recruitmentjobposition.class.php index 6b2223d4982eb..026584681b01a 100644 --- a/htdocs/recruitment/class/recruitmentjobposition.class.php +++ b/htdocs/recruitment/class/recruitmentjobposition.class.php @@ -380,15 +380,20 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index cb106b7afeb54..fa7ec353d2c9d 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -605,11 +605,22 @@ public function delete(User $user, int $notrigger = 0) * @param string $sortfield Sort field * @param int $limit Limit page * @param int $offset Offset page - * @param string|array $filter Filter USF. + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @return int If KO: <0 || if OK number of lines loaded */ - public function fetchAll(string $sortorder, string $sortfield, int $limit, int $offset, $filter = '') + public function fetchAll(string $sortorder, string $sortfield, int $limit, int $offset, array $filter = array()) { + + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.xxxx'] = + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); @@ -644,6 +655,7 @@ public function fetchAll(string $sortorder, string $sortfield, int $limit, int $ // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); foreach ($filter as $key => $value) { if (strpos($key, 'date')) { $sql .= " AND ".$this->db->sanitize($key)." = '".$this->db->idate($value)."'"; diff --git a/htdocs/ticket/class/cticketcategory.class.php b/htdocs/ticket/class/cticketcategory.class.php index 617dbcbeceb34..025e49c84a16d 100644 --- a/htdocs/ticket/class/cticketcategory.class.php +++ b/htdocs/ticket/class/cticketcategory.class.php @@ -351,15 +351,20 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; diff --git a/htdocs/ticket/class/ticket.class.php b/htdocs/ticket/class/ticket.class.php index 82b2ade450427..6633cb5848864 100644 --- a/htdocs/ticket/class/ticket.class.php +++ b/htdocs/ticket/class/ticket.class.php @@ -798,13 +798,23 @@ public function fetch($id = 0, $ref = '', $track_id = '', $email_msgid = '') * @param int $limit Limit * @param int $offset Offset page * @param int $arch Archive or not (not used) - * @param string|array $filter Filter for query + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @return int Return integer <0 if KO, >0 if OK */ - public function fetchAll($user, $sortorder = 'ASC', $sortfield = 't.datec', $limit = 0, $offset = 0, $arch = 0, $filter = '') + public function fetchAll($user, $sortorder = 'ASC', $sortfield = 't.datec', $limit = 0, $offset = 0, $arch = 0, array $filter = array()) { global $langs, $extrafields; + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like 't.fk_contract' => $this->id + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + // fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($this->table_element); @@ -857,6 +867,7 @@ public function fetchAll($user, $sortorder = 'ASC', $sortfield = 't.datec', $lim // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); foreach ($filter as $key => $value) { if (strpos($key, 'date')) { // To allow $filter['YEAR(s.dated)']=>$year $sql .= " AND ".$this->db->sanitize($key)." = '".$this->db->escape($value)."'"; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 98b3a24b2faba..68005f9dffd60 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -726,7 +726,7 @@ public function loadDefaultValues() require_once DOL_DOCUMENT_ROOT.'/core/class/defaultvalues.class.php'; $defaultValues = new DefaultValues($this->db); - $result = $defaultValues->fetchAll('', '', 0, 0, '(t.user_id:in:0,'.$this->id.') AND (entity:in:'.(isset($this->entity) ? $this->entity : $conf->entity).','.$conf->entity.')'); // User 0 (all) + me (if defined) + $result = $defaultValues->fetchAll('', '', 0, 0, ['uss' => '(t.user_id:in:0,'.$this->id.') AND (entity:in:'.(isset($this->entity) ? $this->entity : $conf->entity).','.$conf->entity.')']); // User 0 (all) + me (if defined) //$result = $defaultValues->fetchAll('', '', 0, 0, array('t.user_id'=>array(0, $this->id), 'entity'=>array((isset($this->entity) ? $this->entity : $conf->entity), $conf->entity))); // User 0 (all) + me (if defined) if (!is_array($result) && $result < 0) { @@ -4086,16 +4086,21 @@ public function getOnlineVirtualCardUrl($mode = '', $typeofurl = 'external') * @param string $sortfield sort field * @param int $limit limit page * @param int $offset page - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @param bool $entityfilter Activate entity filter * @return int Return integer <0 if KO, >0 if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND', $entityfilter = false) + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND', $entityfilter = false) { global $conf, $user; + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $sql = "SELECT t.rowid"; $sql .= ' FROM '.$this->db->prefix().$this->table_element.' as t '; diff --git a/htdocs/webhook/class/target.class.php b/htdocs/webhook/class/target.class.php index 5a6e94a943c95..a4d1980505556 100644 --- a/htdocs/webhook/class/target.class.php +++ b/htdocs/webhook/class/target.class.php @@ -388,15 +388,20 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = "SELECT "; diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php index dd3d8eb48df68..9f3dcc7948e6b 100644 --- a/htdocs/website/class/website.class.php +++ b/htdocs/website/class/website.class.php @@ -377,14 +377,24 @@ public function fetch($id, $ref = null) * @param string $sortfield Sort field * @param int $limit limit * @param int $offset offset limit - * @param string|array $filter filter array + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = * @param string $filtermode filter mode (AND or OR) * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.xxxx'] = + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $records = array(); $sql = "SELECT"; @@ -406,6 +416,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = // Manage filter if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { diff --git a/htdocs/website/class/websitepage.class.php b/htdocs/website/class/websitepage.class.php index b27e413633786..40cc96dc80a5f 100644 --- a/htdocs/website/class/websitepage.class.php +++ b/htdocs/website/class/websitepage.class.php @@ -368,15 +368,24 @@ public function fetch($id, $website_id = null, $page = null, $aliasalt = null) * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string|array $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return WebSitePage[]|int<-1,-1> int <0 if KO, array of pages if OK */ - public function fetchAll($websiteid, $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($websiteid, $sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + //some part of dolibarr main code use $filter as array like $filter['t.xxxx'] = + //then we use "universal search string only if exists" + if (isset($filter['uss'])) { + $filter = $filter['uss']; + } + $records = array(); $sql = 'SELECT'; @@ -409,6 +418,7 @@ public function fetchAll($websiteid, $sortorder = '', $sortfield = '', $limit = // Deprecated. If we receive an array, we use it. Prefer using the USF syntax. if (is_array($filter)) { + dol_syslog(__METHOD__ . "Using deprecated filter with old array data, please update to Universal Search string syntax", LOG_NOTICE); $sqlwhere = array(); if (count($filter) > 0) { diff --git a/htdocs/workstation/class/workstation.class.php b/htdocs/workstation/class/workstation.class.php index 57326018dc723..bb164c742d9bf 100644 --- a/htdocs/workstation/class/workstation.class.php +++ b/htdocs/workstation/class/workstation.class.php @@ -414,15 +414,20 @@ public function fetchLines() * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT '; diff --git a/htdocs/zapier/class/hook.class.php b/htdocs/zapier/class/hook.class.php index cd743d99badcb..0a0f027e4a82b 100644 --- a/htdocs/zapier/class/hook.class.php +++ b/htdocs/zapier/class/hook.class.php @@ -386,17 +386,22 @@ public function fetch($id, $ref = null) * @param string $sortfield Sort field * @param int $limit limit * @param int $offset Offset - * @param string $filter Filter as an Universal Search string. - * Example: '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' + * @param array $filter Filter as an Universal Search string. + * Example: $filter['uss'] = '((client:=:1) OR ((client:>=:2) AND (client:<=:3))) AND (client:!=:8) AND (nom:like:'a%')' * @param string $filtermode No more used * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND') + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { global $conf; dol_syslog(__METHOD__, LOG_DEBUG); + if (isset($filter['customsql'])) { + trigger_error(__CLASS__ .'::'.__FUNCTION__.' customsql in filter is now forbidden, please use $filter["uss"]="xx:yy:zz" with Universal Search String instead', E_USER_ERROR); + } + $filter = $filter['uss'] ?? ""; + $records = array(); $sql = 'SELECT';