Skip to content

Commit

Permalink
Use of NetworkPort_NetworkPort->delete() instead of removeConnector()…
Browse files Browse the repository at this point in the history
…. See release fusioninventory#47
  • Loading branch information
Vincent MAZZONI committed Apr 28, 2010
1 parent 643c3a2 commit 6787210
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
6 changes: 4 additions & 2 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -2578,17 +2578,19 @@ function plugin_pre_item_purge_fusioninventory($parm) {
case PLUGIN_FUSIONINVENTORY_MAC_UNKNOWN :
// Delete ports and connections if exists
$np=new Netport;
$nn = new NetworkPort_NetworkPort();
$query = "SELECT `ID`
FROM `glpi_networking_ports`
WHERE `on_device` = '".$parm["ID"]."'
AND `device_type` = '".PLUGIN_FUSIONINVENTORY_MAC_UNKNOWN."';";
$result = $DB->query($query);
while ($data = $DB->fetch_array($result)) {
removeConnector($data["ID"]);
if ($nn->getFromDBForNetworkPort($data['ID'])) {
$nn->delete($data);
}
$np->delete(array("ID"=>$data["ID"]));
}
break;

}
}
return $parm;
Expand Down
5 changes: 4 additions & 1 deletion inc/discovery.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ static function PluginFusioninventoryDiscovery::import($discovery_ID,$Import=0,
$data["ifmac"] = $Netport->fields["ifmac"];
$ID_Device = $Netdevice->add($data);

removeConnector($Netport->fields["ID"]);
$nn = new NetworkPort_NetworkPort();
if ($nn->getFromDBForNetworkPort($Netport->fields["ID"])) {
$nn->delete($Netport->fields);
}
$Netdevice->deleteFromDB($Netport->fields["ID"]);

$data_fusioninventory["FK_networking"] = $ID_Device;
Expand Down
11 changes: 7 additions & 4 deletions inc/port.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,13 @@ function disconnectDB($p_port='') {
$netwire = new Netwire;
PluginFusionInventorySNMPHistory::addLogConnection("remove",$netwire->getOppositeContact($p_port));
//PluginFusionInventorySNMPHistory::addLogConnection("remove",$p_port);
if (removeConnector($p_port)) {
$ptap = new PluginFusionInventoryAgentsProcesses;
$ptap->updateProcess($_SESSION['glpi_plugin_fusioninventory_processnumber'],
array('query_nb_connections_deleted' => '1'));
$nn = new NetworkPort_NetworkPort();
if ($nn->getFromDBForNetworkPort($p_port)) {
if ($nn->delete(array('id'=>$p_port))) {
$ptap = new PluginFusionInventoryAgentsProcesses;
$ptap->updateProcess($_SESSION['glpi_plugin_fusioninventory_processnumber'],
array('query_nb_connections_deleted' => '1'));
}
}
}

Expand Down
28 changes: 22 additions & 6 deletions inc/snmp.classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,17 @@ function PortsConnection($source_port, $destination_port,$FK_process,$vlan="") {
PluginFusionInventorySNMPHistory::addLogConnection("remove",$netwire->getOppositeContact($source_port),$FK_process);
PluginFusionInventorySNMPHistory::addLogConnection("remove",$source_port,$FK_process);
$this->CleanVlan($source_port);
removeConnector($source_port);
$nn = new NetworkPort_NetworkPort();
if ($nn->getFromDBForNetworkPort($source_port)) {
$nn->delete(array('id'=>$source_port));
}

PluginFusionInventorySNMPHistory::addLogConnection("remove",$netwire->getOppositeContact($destination_port),$FK_process);
PluginFusionInventorySNMPHistory::addLogConnection("remove",$destination_port,$FK_process);
$this->CleanVlan($destination_port);
removeConnector($destination_port);
if ($nn->getFromDBForNetworkPort($destination_port)) {
$nn->delete(array('id'=>$destination_port));
}

makeConnector($source_port,$destination_port);
PluginFusionInventorySNMPHistory::addLogConnection("make",$destination_port,$FK_process);
Expand Down Expand Up @@ -838,6 +843,7 @@ static function getOIDPorts($ID_Device,$type,$oidsModel,$oidvalues,
$logicalnumberlist .= ")";
}
// Delete all ports that will be not here
$nn = new NetworkPort_NetworkPort();
foreach($deleteportname as $id=>$i) {
$query = "SELECT *
FROM `glpi_networking_ports`
Expand All @@ -850,7 +856,9 @@ static function getOIDPorts($ID_Device,$type,$oidsModel,$oidvalues,
PluginFusionInventorySNMPHistory::addLogConnection(
"remove",$netwire->getOppositeContact($data['ID']),$FK_process);
PluginFusionInventorySNMPHistory::addLogConnection("remove",$data['ID'],$FK_process);
removeConnector($data['ID']);
if ($nn->getFromDBForNetworkPort($data['ID'])) {
$nn->delete($data);
}

$ptp->deleteFromDB($data["ID"],1);
$np->delete($data);
Expand All @@ -869,7 +877,9 @@ static function getOIDPorts($ID_Device,$type,$oidsModel,$oidvalues,
PluginFusionInventorySNMPHistory::addLogConnection(
"remove",$netwire->getOppositeContact($data['ID']),$FK_process);
PluginFusionInventorySNMPHistory::addLogConnection("remove",$data['ID'],$FK_process);
removeConnector($data['ID']);
if ($nn->getFromDBForNetworkPort($data['ID'])) {
$nn->delete($data);
}
$np->delete($data);
$query_delete = "DELETE FROM `glpi_plugin_fusioninventory_networking_ports`
WHERE `FK_networking_ports`='".$data["ID"]."';";
Expand Down Expand Up @@ -1124,6 +1134,7 @@ static function updateGLPINetworkingPorts($ID_Device,$type,$oidsModel,$oidvalues
if ($_SESSION['fusioninventory_logs'] == "1") $logs = new PluginFusionInventoryLogs;
$snmp_queries = new PluginFusionInventorySNMP;
$walks = new PluginFusionInventoryWalk;
$nn = new NetworkPort_NetworkPort();

if ($_SESSION['fusioninventory_logs'] == "1") $logs->write("fusioninventory_fullsync",
">>>>>>>>>> Update ports device values <<<<<<<<<<",$type,$ID_Device,1);
Expand Down Expand Up @@ -1245,7 +1256,9 @@ static function updateGLPINetworkingPorts($ID_Device,$type,$oidsModel,$oidvalues
PluginFusionInventorySNMPHistory::addLogConnection(
"remove",$netwire->getOppositeContact($data["ID"]),$FK_process);
PluginFusionInventorySNMPHistory::addLogConnection("remove",$data["ID"],$FK_process);
removeConnector($data["ID"]);
if ($nn->getFromDBForNetworkPort($data['ID'])) {
$nn->delete($data);
}

}
// Add log because snmp value change
Expand Down Expand Up @@ -1349,6 +1362,7 @@ static function cdp_trunk($ID_Device,$type,$oidsModel,$oidvalues,
global $DB;

$netwire=new Netwire;
$nn = new NetworkPort_NetworkPort();
$snmp_queries = new PluginFusionInventorySNMP;
if ($_SESSION['fusioninventory_logs'] == "1") $logs = new PluginFusionInventoryLogs;
$walks = new PluginFusionInventoryWalk;
Expand Down Expand Up @@ -1527,7 +1541,9 @@ static function cdp_trunk($ID_Device,$type,$oidsModel,$oidvalues,
$snmp_queries->CleanVlan($data['FK_networking_ports']);
$snmp_queries->CleanVlan($netwire->getOppositeContact($data['FK_networking_ports']));
// Remove connection
removeConnector($data['FK_networking_ports']);
if ($nn->getFromDBForNetworkPort($data['FK_networking_ports'])) {
$nn->delete(array('id'=>$data['FK_networking_ports']));
}
PluginFusioninventoryDb::lock_wire_unlock();
}
} else if($data['trunk'] != "0") {
Expand Down

0 comments on commit 6787210

Please sign in to comment.