From 6e46e957024307c91c36896314ba52c5d6181cc4 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Mon, 14 Dec 2020 18:46:38 +0100 Subject: [PATCH] pass current object and $new to validate() --- SeedDMS_Core/Core/inc.ClassAttribute.php | 9 ++++++--- controllers/class.EditDocument.php | 2 +- controllers/class.EditFolder.php | 2 +- op/op.EditAttributes.php | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/SeedDMS_Core/Core/inc.ClassAttribute.php b/SeedDMS_Core/Core/inc.ClassAttribute.php index f36f29584..b6f342295 100644 --- a/SeedDMS_Core/Core/inc.ClassAttribute.php +++ b/SeedDMS_Core/Core/inc.ClassAttribute.php @@ -1134,18 +1134,21 @@ class SeedDMS_Core_AttributeDefinition { /* {{{ */ * Set $new to true if the value to be checked isn't saved to the database * already. It will just be passed to the callback onAttributeValidate where * it could be used to, e.g. check if a value is unique once it is saved to - * the database. + * the database. $object is set to a folder, document or documentcontent + * if the attribute belongs to such an object. This will be null, if a + * new object is created. * * @param string|array $attrvalue attribute value + * @param object $object set if the current attribute is saved for this object * @param boolean $new set to true if the value is new value and not taken from * an existing attribute * @return boolean true if validation succeds, otherwise false */ - function validate($attrvalue, $new=false) { /* {{{ */ + function validate($attrvalue, $object=null, $new=false) { /* {{{ */ /* Check if 'onAttributeValidate' callback is set */ if(isset($this->_dms->callbacks['onAttributeValidate'])) { foreach($this->_dms->callbacks['onAttributeValidate'] as $callback) { - $ret = call_user_func($callback[0], $callback[1], $this, $attrvalue, $new); + $ret = call_user_func($callback[0], $callback[1], $this, $attrvalue, $object, $new); if(is_bool($ret)) return $ret; } diff --git a/controllers/class.EditDocument.php b/controllers/class.EditDocument.php index 680d31577..58ffc8a77 100644 --- a/controllers/class.EditDocument.php +++ b/controllers/class.EditDocument.php @@ -120,7 +120,7 @@ class SeedDMS_Controller_EditDocument extends SeedDMS_Controller_Common { if($attrdef = $dms->getAttributeDefinition($attrdefid)) { if(null === ($ret = $this->callHook('validateAttribute', $attrdef, $attribute))) { if($attribute) { - if(!$attrdef->validate($attribute, true)) { + if(!$attrdef->validate($attribute, $document, true)) { $this->errormsg = getAttributeValidationError($attrdef->getValidationError(), $attrdef->getName(), $attribute); return false; } diff --git a/controllers/class.EditFolder.php b/controllers/class.EditFolder.php index a2d27c34f..0110f6e06 100644 --- a/controllers/class.EditFolder.php +++ b/controllers/class.EditFolder.php @@ -54,7 +54,7 @@ class SeedDMS_Controller_EditFolder extends SeedDMS_Controller_Common { $attrdef = $dms->getAttributeDefinition($attrdefid); if(null === ($ret = $this->callHook('validateAttribute', $attrdef, $attribute))) { if($attribute) { - if(!$attrdef->validate($attribute)) { + if(!$attrdef->validate($attribute, $folder, true)) { $this->errormsg = getAttributeValidationText($attrdef->getValidationError(), $attrdef->getName(), $attribute); return false; } diff --git a/op/op.EditAttributes.php b/op/op.EditAttributes.php index 4397351a6..4181452d3 100644 --- a/op/op.EditAttributes.php +++ b/op/op.EditAttributes.php @@ -71,7 +71,7 @@ if($attributes) { foreach($attributes as $attrdefid=>$attribute) { $attrdef = $dms->getAttributeDefinition($attrdefid); if($attribute) { - if(!$attrdef->validate($attribute)) { + if(!$attrdef->validate($attribute, $version, true)) { $errmsg = getAttributeValidationText($attrdef->getValidationError(), $attrdef->getName(), $attribute); UI::exitError(getMLText("document_title", array("documentname" => $document->getName())), $errmsg); }