From 49f826557aa33d6bca6bd481345bc380da6dcb53 Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Mon, 24 Jun 2024 12:32:38 +0200 Subject: [PATCH 1/2] Dirty fix for inconcistant link psedo langage --- htdocs/core/class/commonobject.class.php | 9 ++++++++- htdocs/core/class/validate.class.php | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index afb86b05a66f9..12be49cce2be1 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -8495,7 +8495,14 @@ public function validateField($fields, $fieldKey, $fieldValue) $classname = $InfoFieldList[0]; $classpath = $InfoFieldList[1]; if (!$validate->isFetchable($fieldValue, $classname, $classpath)) { - $this->setFieldError($fieldKey, $validate->error); + $lastIsFetchableError = $validate->error; + + // from V19 of Dolibarr, In some cases link use element instead of class exemple project_task + if ($validate->isFetchableElement($fieldValue, $classname)) { + return true; + } + + $this->setFieldError($fieldKey, $lastIsFetchableError); return false; } else { return true; diff --git a/htdocs/core/class/validate.class.php b/htdocs/core/class/validate.class.php index 50d290f7517f1..d6a94fe36599d 100644 --- a/htdocs/core/class/validate.class.php +++ b/htdocs/core/class/validate.class.php @@ -335,4 +335,19 @@ public function isFetchable($id, $classname, $classpath) } return false; } + + /** + * Check for all values in db for an element + * @see self::isFetchable() + * + * @param integer $id of element + * @param string $element_type the element type + * @return boolean Validity is ok or not + * @throws Exception + */ + public function isFetchableElement($id, $element_type) + { + $elementProperty = getElementProperties($element_type); + return $this->isFetchable($id, $elementProperty['classname'], $elementProperty['classpath'].'/'.$elementProperty['classfile'].'.class.php'); + } } From 4ccfd36bfc61b8b44f94ac952f0a774e873a5db5 Mon Sep 17 00:00:00 2001 From: John BOTELLA Date: Mon, 24 Jun 2024 12:45:01 +0200 Subject: [PATCH 2/2] add todo --- htdocs/core/class/validate.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/core/class/validate.class.php b/htdocs/core/class/validate.class.php index d6a94fe36599d..1c14d3e60bdc2 100644 --- a/htdocs/core/class/validate.class.php +++ b/htdocs/core/class/validate.class.php @@ -347,6 +347,7 @@ public function isFetchable($id, $classname, $classpath) */ public function isFetchableElement($id, $element_type) { + // TODO use newObjectByElement() introduce in V20 by PR #30036 for better errors management $elementProperty = getElementProperties($element_type); return $this->isFetchable($id, $elementProperty['classname'], $elementProperty['classpath'].'/'.$elementProperty['classfile'].'.class.php'); }