diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index e99a7bbac32..18f71ac2f20 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -8739,7 +8739,14 @@ abstract class CommonObject $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, example 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 02ed867a5d8..1c1a895aa2a 100644 --- a/htdocs/core/class/validate.class.php +++ b/htdocs/core/class/validate.class.php @@ -335,4 +335,20 @@ class Validate } 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) + { + // 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'); + } } diff --git a/htdocs/core/db/DoliDB.class.php b/htdocs/core/db/DoliDB.class.php index ea6ad2dcb7b..8895cdf83ec 100644 --- a/htdocs/core/db/DoliDB.class.php +++ b/htdocs/core/db/DoliDB.class.php @@ -201,8 +201,10 @@ abstract class DoliDB implements Database $this->transaction_opened++; dol_syslog("BEGIN Transaction".($textinlog ? ' '.$textinlog : ''), LOG_DEBUG); dol_syslog('', 0, 1); + return 1; + } else { + return 0; } - return (int) $ret; } else { $this->transaction_opened++; dol_syslog('', 0, 1);