Browse Source

Customization: added a check against reuse of an attribute code (collision can happen easily with inheritance)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@1518 a333f486-631f-4898-b8df-5754b55c2be0
romainq 13 years ago
parent
commit
c269a42c90
1 changed files with 14 additions and 3 deletions
  1. 14 3
      core/metamodel.class.php

+ 14 - 3
core/metamodel.class.php

@@ -1536,11 +1536,22 @@ if (!array_key_exists($sAttCode, self::$m_aAttribDefs[$sClass]))
 
 	public static function Init_AddAttribute(AttributeDefinition $oAtt)
 	{
+		$sTargetClass = self::GetCallersPHPClass("Init");
+
 		$sAttCode = $oAtt->GetCode();
-		if ($sAttCode == 'finalclass') throw new Exception('Using a reserved keyword in metamodel declaration: '.$sAttCode);
-		if ($sAttCode == 'friendlyname') throw new Exception('Using a reserved keyword in metamodel declaration: '.$sAttCode);
+		if ($sAttCode == 'finalclass')
+		{
+			throw new Exception("Declaration of $sTargetClass: using the reserved keyword '$sAttCode' in attribute declaration");
+		}
+		if ($sAttCode == 'friendlyname')
+		{
+			throw new Exception("Declaration of $sTargetClass: using the reserved keyword '$sAttCode' in attribute declaration");
+		}
+		if (array_key_exists($sAttCode, self::$m_aAttribDefs[$sTargetClass]))
+		{
+			throw new Exception("Declaration of $sTargetClass: attempting to redeclare the inherited attribute '$sAttCode', originaly declared in ".self::$m_aAttribOrigins[$sTargetClass][$sAttCode]);
+		}
 	
-		$sTargetClass = self::GetCallersPHPClass("Init");
 		// Set the "host class" as soon as possible, since HierarchicalKeys use it for their 'target class' as well
 		// and this needs to be know early (for Init_IsKnowClass 19 lines below)		
 		$oAtt->SetHostClass($sTargetClass);