updateDependencies() публичный Метод

splitInputForElements() prepare the data for adding or updating NetworkPortInstantiation and NetworkName. This method will update NetworkPortInstantiation and NetworkName. I must be call after NetworkPort::add or NetworkPort::update otherwise, the networkport ID will not be known and the dependencies won't have a valid items_id field.
См. также: splitInputForElements() for preparing the input
public updateDependencies ( $history = true )
$history (default 1)
 /**
  * @test
  */
 public function prepareDB()
 {
     global $DB;
     $DB->connect();
     $entity = new Entity();
     $computer = new Computer();
     $pfAgent = new PluginFusioninventoryAgent();
     $pfTask = new PluginFusioninventoryTask();
     $pfTaskjob = new PluginFusioninventoryTaskjob();
     $pfIPRange = new PluginFusioninventoryIPRange();
     $networkEquipment = new NetworkEquipment();
     $networkPort = new NetworkPort();
     $printer = new Printer();
     $pfNetworkEquipment = new PluginFusioninventoryNetworkEquipment();
     // Create entities
     $_SESSION['glpiactive_entity'] = 0;
     $DB->query("INSERT INTO `glpi_entities`\n         (`id`, `name`, `entities_id`, `completename`, `level`)\n         VALUES (1, 'ent1', 0, 'Entité racine > ent1', 2)");
     $DB->query("INSERT INTO `glpi_entities`\n         (`id`, `name`, `entities_id`, `completename`, `level`)\n         VALUES (2, 'ent2', 0, 'Entité racine > ent2', 2)");
     $DB->query("INSERT INTO `glpi_entities`\n         (`id`, `name`, `entities_id`, `completename`, `level`)\n         VALUES (3, 'ent1.1', 1, 'Entité racine > ent1 > ent1.1', 3)");
     // Create computers + agents
     $input = array('entities_id' => 0, 'name' => 'computer1');
     $computers_id = $computer->add($input);
     $input = array('entities_id' => 0, 'name' => 'computer1', 'version' => '{"INVENTORY":"v2.3.11"}', 'device_id' => 'computer1', 'useragent' => 'FusionInventory-Agent_v2.3.11', 'computers_id' => $computers_id);
     $pfAgent->add($input);
     // Create Network Equipments
     $input = array('name' => 'sw0', 'entities_id' => 0);
     $networkEquipment->add($input);
     $input = array('entities_id' => 0, 'name' => 'management', 'items_id' => 1, 'itemtype' => 'NetworkEquipment', 'instantiation_type' => 'NetworkPortAggregate', 'NetworkName__ipaddresses' => array('-1' => '10.0.0.10'));
     $networkPort->splitInputForElements($input);
     $networkPort->add($input);
     $networkPort->updateDependencies(1);
     $input = array('networkequipments_id' => 1, 'plugin_fusioninventory_configsecurities_id' => 2);
     $pfNetworkEquipment->add($input);
     $input = array('name' => 'sw1', 'entities_id' => 1);
     $networkEquipment->add($input);
     $input = array('entities_id' => 1, 'name' => 'management', 'items_id' => 2, 'itemtype' => 'NetworkEquipment', 'instantiation_type' => 'NetworkPortAggregate', 'NetworkName__ipaddresses' => array('-1' => '10.0.0.11'));
     $networkPort->splitInputForElements($input);
     $networkPort->add($input);
     $networkPort->updateDependencies(1);
     $input = array('networkequipments_id' => 2, 'plugin_fusioninventory_configsecurities_id' => 2);
     $pfNetworkEquipment->add($input);
     $input = array('name' => 'sw2', 'entities_id' => 2);
     $networkEquipment->add($input);
     $input = array('entities_id' => 2, 'name' => 'management', 'items_id' => 3, 'itemtype' => 'NetworkEquipment', 'instantiation_type' => 'NetworkPortAggregate', 'NetworkName__ipaddresses' => array('-1' => '10.0.0.12'));
     $networkPort->splitInputForElements($input);
     $networkPort->add($input);
     $networkPort->updateDependencies(1);
     $input = array('networkequipments_id' => 3, 'plugin_fusioninventory_configsecurities_id' => 2);
     $pfNetworkEquipment->add($input);
     $input = array('name' => 'sw3/1.1', 'entities_id' => 3);
     $networkEquipment->add($input);
     $input = array('entities_id' => 3, 'name' => 'management', 'items_id' => 4, 'itemtype' => 'NetworkEquipment', 'instantiation_type' => 'NetworkPortAggregate', 'NetworkName__ipaddresses' => array('-1' => '10.0.0.21'));
     $networkPort->splitInputForElements($input);
     $networkPort->add($input);
     $networkPort->updateDependencies(1);
     $input = array('networkequipments_id' => 4, 'plugin_fusioninventory_configsecurities_id' => 2);
     $pfNetworkEquipment->add($input);
     // Create Printers
     // Add IPRange
     $input = array('entities_id' => 1, 'name' => 'Office', 'ip_start' => '10.0.0.1', 'ip_end' => '10.0.0.254');
     $ipranges_id = $pfIPRange->add($input);
     // Allow all agents to do network discovery
     $query = "UPDATE `glpi_plugin_fusioninventory_agentmodules` " . " SET `is_active`='1' " . " WHERE `modulename`='NETWORKINVENTORY'";
     $DB->query($query);
     // create task
     $input = array('entities_id' => 0, 'name' => 'network inventory', 'is_active' => 1);
     $tasks_id = $pfTask->add($input);
     // create taskjob
     $input = array('plugin_fusioninventory_tasks_id' => $tasks_id, 'entities_id' => 0, 'name' => 'inventory', 'method' => 'networkinventory', 'targets' => '[{"PluginFusioninventoryIPRange":"' . $ipranges_id . '"}]', 'actors' => '[{"PluginFusioninventoryAgent":"1"}]');
     $pfTaskjob->add($input);
 }
Пример #2
0
/**  Generate bigdump : Create networkport ethernet
 *
 * @since version 0.84
 *
 * @param $itemtype        item type
 * @param $items_id        item ID
 * @param $entities_id     item entity ID
 * @param $locations_id    ID of the location trying to link with network equipment (default 0)
**/
function addNetworkEthernetPort($itemtype, $items_id, $entities_id, $locations_id=0) {
   global $NET_LOC, $NET_PORT, $MAX, $VLAN_LOC;

   // Add networking ports
   $newIP   = getNextIP();
   $newMAC  = getNextMAC();

   if (($itemtype == 'NetworkEquipment') && $locations_id) {
      // Find father locations_id;
      $loc = new Location();
      if ($loc->getFromDB($locations_id)) {
         $locations_id = $loc->getField('locations_id');
      } else {
         $locations_id = 0;
      }
   }

   //insert netpoint
   $netpoint   = new NetPoint();
   $netpointID = $netpoint->add(toolbox::addslashes_deep(
                                array('entities_id'  => $entities_id,
                                      'locations_id' => $locations_id,
                                      'name'         => getNextNETPOINT(),
                                      'comment'      => "comment 'netpoint $locations_id")));

   if ($locations_id && !isset($VLAN_LOC[$locations_id])) {
      $vlanID                  = mt_rand(1,$MAX["vlan"]);
      $VLAN_LOC[$locations_id] = $vlanID;
   }
   if (!isset($NET_PORT[$itemtype][$items_id])) {
      $NET_PORT[$itemtype][$items_id]=0;
   }
   $np          = new NetworkPort();
   $nv          = new NetworkPort_Vlan();
   $newportname = "port of $itemtype-$items_id";
   $refportID   = 0;

   if ($locations_id && isset($NET_LOC[$locations_id]) && $NET_LOC[$locations_id]) {
      $refportname  = "link 'port to  $itemtype-$items_id";
      $newportname .= " link to 'NetworkEquipment' -".$NET_LOC[$locations_id];
      $newMAC2      = getNextMAC();
      $newIP2      = getNextIP();

      // Create new port on ref item
      $param = toolbox::addslashes_deep(
               array('itemtype'                 => 'NetworkEquipment',
                     'items_id'                 => $NET_LOC[$locations_id],
                     'entities_id'              => $entities_id,
                     'logical_number'  => $NET_PORT['NetworkEquipment'][$NET_LOC[$locations_id]]++,
                     'name'                     => "name '$refportname",
                     'instantiation_type'       => 'NetworkPortEthernet',
                     'mac'                      => $newMAC2,
                     'comment'                  => "comment '$refportname",
                     'netpoints_id'             => $netpointID,
                     'NetworkName_name'         => "NetworkEquipment$itemtype-$items_id-$entities_id",
                     'NetworkName__ipaddresses' => array(-100 => $newIP2['ip']),
                     ));

                     $np->splitInputForElements($param);
      $refportID = $np->add($param);
      $np->updateDependencies(1);
      if (isset($VLAN_LOC[$locations_id]) && $refportID) {
         $nv->add(array('networkports_id' => $refportID,
                        'vlans_id'        => $VLAN_LOC[$locations_id]));
      }
   }

//    $query = "INSERT INTO `glpi_networkports`
//                VALUES (NULL, '$netwID', 'NetworkEquipment', '$ID_entity', '0',
//                      '".$NET_PORT['NetworkEquipment'][$netwID]++."',
//                      'link port to netw ".$NET_LOC[$data['locations_id']]."',
//                      '".$newIP['ip']."', '$newMAC', '$iface', '$netpointID',
//                      '".$newIP['netwmask']."', '".$newIP['gateway']."',
//                      '".$newIP['subnet']."','comment')";
//    $DB->query($query) or die("PB REQUETE ".$query);

   $param = toolbox::addslashes_deep(
            array('itemtype'                 => $itemtype,
                  'items_id'                 => $items_id,
                  'entities_id'              => $entities_id,
                  'logical_number'           => $NET_PORT[$itemtype][$items_id]++,
                  'name'                     => "name '$newportname",
                  'instantiation_type'       => 'NetworkPortEthernet',
                  'mac'                      => $newMAC,
                  'comment'                  => "comment '$newportname",
                  'netpoints_id'             => $netpointID,
                  'NetworkName_name'         => "$itemtype-$items_id-$entities_id",
                  'NetworkName__ipaddresses' => array(-100 => $newIP['ip']),
                  ));

                  $np->splitInputForElements($param);
   $newportID = $np->add($param);

   $np->updateDependencies(1);
   if (isset($VLAN_LOC[$locations_id]) && $newportID) {
      $nv->add(array('networkports_id' => $newportID,
                     'vlans_id'        => $VLAN_LOC[$locations_id]));
   }
   if ($locations_id && $refportID && $newportID) {
      // link ports
      $nn = new Networkport_Networkport();
      $nn->add(array('networkports_id_1' => $refportID,
                     'networkports_id_2' => $newportID,));
   } else {
      if ($locations_id) {
      }
   }
}
Пример #3
0
if (!isset($_GET["id"])) {
    $_GET["id"] = "";
}
if (isset($_POST["add"])) {
    // Is a preselected mac adress selected ?
    if (isset($_POST['pre_mac'])) {
        if (!empty($_POST['pre_mac'])) {
            $_POST['mac'] = $_POST['pre_mac'];
        }
        unset($_POST['pre_mac']);
    }
    if (!isset($_POST["several"])) {
        $np->check(-1, 'w', $_POST);
        $np->splitInputForElements($_POST);
        $newID = $np->add($_POST);
        $np->updateDependencies(1);
        Event::log($newID, "networkport", 5, "inventory", sprintf(__('%s adds an item'), $_SESSION["glpiname"]));
        Html::back();
    } else {
        Session::checkRight("networking", "w");
        $input = $_POST;
        unset($input['several']);
        unset($input['from_logical_number']);
        unset($input['to_logical_number']);
        for ($i = $_POST["from_logical_number"]; $i <= $_POST["to_logical_number"]; $i++) {
            $add = "";
            if ($i < 10) {
                $add = "0";
            }
            $input["logical_number"] = $i;
            $input["name"] = $_POST["name"] . $add . $i;