check if attr def exists when setting attribute value

This commit is contained in:
Uwe Steinmann 2020-12-28 08:14:05 +01:00
parent 9f7933f030
commit 144d35849b
3 changed files with 25 additions and 5 deletions

View File

@ -1551,12 +1551,19 @@ class SeedDMS_Core_Document extends SeedDMS_Core_Object { /* {{{ */
if($attributes) {
foreach($attributes as $attrdefid=>$attribute) {
/* $attribute can be a string or an array */
if($attribute)
if(!$content->setAttributeValue($this->_dms->getAttributeDefinition($attrdefid), $attribute)) {
if($attribute) {
if($attrdef = $this->_dms->getAttributeDefinition($attrdefid)) {
if(!$content->setAttributeValue($attrdef, $attribute)) {
$this->_removeContent($content);
$db->rollbackTransaction();
return false;
}
} else {
$this->_removeContent($content);
$db->rollbackTransaction();
return false;
}
}
}
}

View File

@ -700,7 +700,12 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object {
if($attributes) {
foreach($attributes as $attrdefid=>$attribute) {
if($attribute)
if(!$newFolder->setAttributeValue($this->_dms->getAttributeDefinition($attrdefid), $attribute)) {
if($attrdef = $this->_dms->getAttributeDefinition($attrdefid)) {
if(!$newFolder->setAttributeValue($attrdef, $attribute)) {
$db->rollbackTransaction();
return false;
}
} else {
$db->rollbackTransaction();
return false;
}
@ -1026,12 +1031,19 @@ class SeedDMS_Core_Folder extends SeedDMS_Core_Object {
if($attributes) {
foreach($attributes as $attrdefid=>$attribute) {
/* $attribute can be a string or an array */
if($attribute)
if(!$document->setAttributeValue($this->_dms->getAttributeDefinition($attrdefid), $attribute)) {
if($attribute) {
if($attrdef = $this->_dms->getAttributeDefinition($attrdefid)) {
if(!$document->setAttributeValue($attrdef, $attribute)) {
$document->remove();
$db->rollbackTransaction();
return false;
}
} else {
$document->remove();
$db->rollbackTransaction();
return false;
}
}
}
}

View File

@ -29,6 +29,7 @@
- new paramter 'new' of methode SeedDMЅ_Core_AttributeDefinition::validate()
- check if folder/document is below rootDir can be turned on (default off)
- SeedDMS_Core_User::setHomeFolder() can be used to unset the home folder
- check if attribute definition exists when setting attributes of folders and documents
</notes>
<contents>
<dir baseinstalldir="SeedDMS" name="/">