mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
Connect interfaces to each other (1-1 link)
SVN:trunk[816]
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user