Przeglądaj źródła

Improved error handling when loading linkedset as attributes in one go

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1410 a333f486-631f-4898-b8df-5754b55c2be0
dflaven 14 lat temu
rodzic
commit
6ed76941fe
1 zmienionych plików z 22 dodań i 0 usunięć
  1. 22 0
      core/attributedef.class.inc.php

+ 22 - 0
core/attributedef.class.inc.php

@@ -602,6 +602,28 @@ class AttributeLinkedSet extends AttributeDefinition
 				}
 			}
 
+			// Check (roughly) if such a link is valid
+			$aErrors = array();
+			foreach(MetaModel::ListAttributeDefs($sTargetClass) as $sAttCode => $oAttDef)
+			{
+				if ($oAttDef->IsExternalKey())
+				{
+					if (($oAttDef->GetTargetClass() == $this->GetHostClass()) || (is_subclass_of($this->GetHostClass(), $oAttDef->GetTargetClass())))
+					{
+						continue; // Don't check the key to self
+					}
+				}
+				
+				if ($oAttDef->IsWritable() && $oAttDef->IsNull($oLink->Get($sAttCode)) && !$oAttDef->IsNullAllowed())
+				{
+					$aErrors[] = $sAttCode;
+				}
+			}
+			if (count($aErrors) > 0)
+			{
+				throw new CoreException("Missing value for mandatory attribute(s): ".implode(', ', $aErrors));
+			}
+
 			$aLinks[] = $oLink;
 		}
 		$oSet = DBObjectSet::FromArray($sTargetClass, $aLinks);