Procházet zdrojové kódy

Obsolescence: fixed the case when an external field points to an external key that is obsoletable (or archivable), causing an error during the setup (view could not be created)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4776 a333f486-631f-4898-b8df-5754b55c2be0
romainq před 8 roky
rodič
revize
898a6939f6
1 změnil soubory, kde provedl 32 přidání a 11 odebrání
  1. 32 11
      core/metamodel.class.php

+ 32 - 11
core/metamodel.class.php

@@ -1953,7 +1953,7 @@ abstract class MetaModel
 					{
 						// Create the friendly name attribute
 						$sFriendlyNameAttCode = $sAttCode.'_friendlyname';
-						$oFriendlyName = new AttributeExternalField($sFriendlyNameAttCode, array('magic' => true, 'allowed_values'=>null, 'extkey_attcode'=>$sAttCode, "target_attcode"=>'friendlyname', 'depends_on'=>array()));
+						$oFriendlyName = new AttributeExternalField($sFriendlyNameAttCode, array('allowed_values'=>null, 'extkey_attcode'=>$sAttCode, "target_attcode"=>'friendlyname', 'depends_on'=>array()));
 						self::AddMagicAttribute($oFriendlyName, $sClass, self::$m_aAttribOrigins[$sClass][$sAttCode]);
 
 						if (self::HasChildrenClasses($sRemoteClass))
@@ -1996,21 +1996,42 @@ abstract class MetaModel
 						}
 					}
 
-					// Get the real external key attribute
-					// It will be our reference to determine the other ext fields related to the same ext key
-					$oFinalKeyAttDef = $oAttDef->GetKeyAttDef(EXTKEY_ABSOLUTE);
-
 					if (self::IsArchivable($sRemoteClass))
 					{
-						$sArchiveRemote = $sAttCode.'_archive_flag';
-						$oArchiveRemote = new AttributeExternalField($sArchiveRemote, array("allowed_values"=>null, "extkey_attcode"=>$sAttCode, "target_attcode"=>'archive_flag', "depends_on"=>array()));
-						self::AddMagicAttribute($oArchiveRemote, $sClass, self::$m_aAttribOrigins[$sClass][$sAttCode]);
+						$sCode = $sAttCode.'_archive_flag';
+						if ($oAttDef->IsExternalField())
+						{
+							// This is a key, but the value comes from elsewhere
+							// Create an external field pointing to the remote attribute
+							$sKeyAttCode = $oAttDef->GetKeyAttCode();
+							$sRemoteAttCode = $oAttDef->GetExtAttCode().'_archive_flag';
+						}
+						else
+						{
+							$sKeyAttCode = $sAttCode;
+							$sRemoteAttCode = 'archive_flag';
+						}
+						$oMagic = new AttributeExternalField($sCode, array("allowed_values"=>null, "extkey_attcode"=>$sKeyAttCode, "target_attcode"=>$sRemoteAttCode, "depends_on"=>array()));
+						self::AddMagicAttribute($oMagic, $sClass, self::$m_aAttribOrigins[$sClass][$sKeyAttCode]);
+
 					}
 					if (self::IsObsoletable($sRemoteClass))
 					{
-						$sObsoleteRemote = $sAttCode.'_obsolescence_flag';
-						$oObsoleteRemote = new AttributeExternalField($sObsoleteRemote, array("allowed_values"=>null, "extkey_attcode"=>$sAttCode, "target_attcode"=>'obsolescence_flag', "depends_on"=>array()));
-						self::AddMagicAttribute($oObsoleteRemote, $sClass, self::$m_aAttribOrigins[$sClass][$sAttCode]);
+						$sCode = $sAttCode.'_obsolescence_flag';
+						if ($oAttDef->IsExternalField())
+						{
+							// This is a key, but the value comes from elsewhere
+							// Create an external field pointing to the remote attribute
+							$sKeyAttCode = $oAttDef->GetKeyAttCode();
+							$sRemoteAttCode = $oAttDef->GetExtAttCode().'_obsolescence_flag';
+						}
+						else
+						{
+							$sKeyAttCode = $sAttCode;
+							$sRemoteAttCode = 'obsolescence_flag';
+						}
+						$oMagic = new AttributeExternalField($sCode, array("allowed_values"=>null, "extkey_attcode"=>$sKeyAttCode, "target_attcode"=>$sRemoteAttCode, "depends_on"=>array()));
+						self::AddMagicAttribute($oMagic, $sClass, self::$m_aAttribOrigins[$sClass][$sKeyAttCode]);
 					}
 				}
 				if ($oAttDef instanceof AttributeMetaEnum)