Browse Source

Connect interfaces to each other (1-1 link)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@816 a333f486-631f-4898-b8df-5754b55c2be0
romainq 14 years ago
parent
commit
b95821d66d

+ 1 - 0
core/cmdbobject.class.inc.php

@@ -84,6 +84,7 @@ abstract class CMDBObject extends DBObject
 {
 	protected $m_datCreated;
 	protected $m_datUpdated;
+	// Note: this value is static, but that could be changed because it is sometimes a real issue (see update of interfaces / connected_to
 	protected static $m_oCurrChange = null;
 
 

+ 50 - 1
modules/itop-config-mgmt-1.0.0/model.itop-config-mgmt.php

@@ -845,7 +845,7 @@ class DatabaseInstance extends FunctionalCI
 		MetaModel::Init_Params($aParams);
 		MetaModel::Init_InheritAttributes();
 
-		MetaModel::Init_AddAttribute(new AttributeExternalKey("db_server_instance_id", array("targetclass"=>"DBServerInstance", "jointype"=>null, "allowed_values"=>new ValueSetObjects('SELECT DBServerInstance WHERE org_id = :this->org_id'), "sql"=>"db_server_instance_id", "is_null_allowed"=>true, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array("org_id"))));
+		MetaModel::Init_AddAttribute(new AttributeExternalKey("db_server_instance_id", array("targetclass"=>"DBServerInstance", "jointype"=>null, "allowed_values"=>new ValueSetObjects('SELECT DBServerInstance WHERE org_id = :this->org_id'), "sql"=>"db_server_instance_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array("org_id"))));
 		MetaModel::Init_AddAttribute(new AttributeExternalField("db_server_instance_name", array("allowed_values"=>null, "extkey_attcode"=>"db_server_instance_id", "target_attcode"=>"name", "is_null_allowed"=>true, "depends_on"=>array())));
 		MetaModel::Init_AddAttribute(new AttributeExternalField("db_server_instance_version", array("allowed_values"=>null, "extkey_attcode"=>"db_server_instance_id", "target_attcode"=>"version", "is_null_allowed"=>true, "depends_on"=>array())));
 		MetaModel::Init_AddAttribute(new AttributeWikiText("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
@@ -1068,6 +1068,55 @@ class NetworkInterface extends ConnectableCI
 			return parent::GetRelationQueries($sRelCode);			
 		}
 	}
+
+	protected function UpdateConnectedInterface()
+	{
+		$oConnIf = MetaModel::GetObject('NetworkInterface', $this->Get('connected_if'), false /* no exception if not found */);
+		if (!is_null($oConnIf))
+		{
+			$sLink = $this->Get('link_type');
+			$sConnLink = ($sLink == 'uplink') ? 'downlink' : 'uplink';
+
+			if (($oConnIf->Get('connected_if') != $this->GetKey()) || ($sConnLink != $oConnIf->Get('link_type')))
+			{
+				// Something has to be changed on the connected interface...
+				if ($oConnIf->Get('connected_if') != $this->GetKey())
+				{
+					// It is connected to another interface: reset that third one...
+					$oThirdIf = MetaModel::GetObject('NetworkInterface', $oConnIf->Get('connected_if'), false);
+					if (!is_null($oThirdIf))
+					{
+						$oThirdIf->Set('connected_if', 0);			
+						// Need to backup the current change, because it is reset when DBUpdateTracked is complete
+						$oCurrChange = self::$m_oCurrChange;
+						$oThirdIf->DBUpdateTracked($oCurrChange);
+						self::$m_oCurrChange = $oCurrChange;
+					}
+				}
+				// Connect the remote interface to the current one
+				$oConnIf->Set('connected_if', $this->GetKey());
+				$oConnIf->Set('link_type', $sConnLink);
+
+				// Need to backup the current change, because it is reset when DBUpdateTracked is complete
+				$oCurrChange = self::$m_oCurrChange;
+				$oConnIf->DBUpdateTracked($oCurrChange);
+				self::$m_oCurrChange = $oCurrChange;
+			}
+		}
+	}
+
+	protected function AfterInsert()
+	{
+		$this->UpdateConnectedInterface();
+		parent::AfterInsert();
+	}
+
+	protected function AfterUpdate()
+	{
+		$this->UpdateConnectedInterface();
+		parent::AfterUpdate();
+	}
+
 }
 abstract class Device extends ConnectableCI
 {