diff --git a/inc/inventorynetworkequipmentlib.class.php b/inc/inventorynetworkequipmentlib.class.php index 7e0a000079..4c3db4a20d 100644 --- a/inc/inventorynetworkequipmentlib.class.php +++ b/inc/inventorynetworkequipmentlib.class.php @@ -514,11 +514,11 @@ function importConnectionMac($a_portconnection, $networkports_id) { // Try detect phone + computer on this port if (count($list_all_ports_found) == 2) { + $phonecase = 0; + $macNotPhone_id = 0; + $phonePort_id = 0; foreach ($this->found_ports as $itemtype => $ids) { - $phonecase = 0; - $macNotPhone_id = 0; - $phonePort_id = 0; - if ($itemtype == "phone") { + if ($itemtype == "Phone") { // Connect phone on switch port and other (computer..) in this phone foreach ($ids as $items_id) { $phonePort_id = current($items_id); @@ -531,8 +531,18 @@ function importConnectionMac($a_portconnection, $networkports_id) { } } if ($phonecase == 1) { - $wire->add(['networkports_id_1'=> $networkports_id, + $opposite_id = $wire->getOppositeContact($networkports_id); + if (isset($opposite_id)) { + if ($opposite_id != $phonePort_id) { + $pfNetworkPort->disconnectDB($networkports_id); // disconnect this port + $pfNetworkPort->disconnectDB($phonePort_id); // disconnect this port + $wire->add(['networkports_id_1'=> $networkports_id, + 'networkports_id_2' => $phonePort_id]); + } + } else { + $wire->add(['networkports_id_1'=> $networkports_id, 'networkports_id_2' => $phonePort_id]); + } $networkPort->getFromDB($phonePort_id); $portLink_id = 0; if ($networkPort->fields['name'] == 'Link') { @@ -561,11 +571,15 @@ function importConnectionMac($a_portconnection, $networkports_id) { } } $opposite_id = false; - if ($opposite_id == $wire->getOppositeContact($portLink_id)) { + if ($opposite_id = $wire->getOppositeContact($portLink_id)) { if ($opposite_id != $macNotPhone_id) { $pfNetworkPort->disconnectDB($portLink_id); // disconnect this port $pfNetworkPort->disconnectDB($macNotPhone_id); // disconnect destination port + } else { // yet connected + return; } + } else { + $pfNetworkPort->disconnectDB($macNotPhone_id); // disconnect destination port } $wire->add([ 'networkports_id_1'=> $portLink_id,