当前位置: 首页>>代码示例>>PHP>>正文


PHP NetworkPort::getFromDBByQuery方法代码示例

本文整理汇总了PHP中NetworkPort::getFromDBByQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP NetworkPort::getFromDBByQuery方法的具体用法?PHP NetworkPort::getFromDBByQuery怎么用?PHP NetworkPort::getFromDBByQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetworkPort的用法示例。


在下文中一共展示了NetworkPort::getFromDBByQuery方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addOrUpdateOther

 /**
  * @param $plugin_ocsinventoryng_ocsservers_id
  * @param $itemtype
  * @param int $ID
  * @param $ocsSnmp
  * @param $loc_id
  * @param $dom_id
  * @param $action
  * @param bool $linked
  * @return int
  */
 static function addOrUpdateOther($plugin_ocsinventoryng_ocsservers_id, $itemtype, $ID = 0, $ocsSnmp, $loc_id, $dom_id, $action, $linked = false)
 {
     $snmpDevice = new $itemtype();
     $cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($plugin_ocsinventoryng_ocsservers_id);
     $input = array("is_dynamic" => 1, "entities_id" => isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : 0);
     if ($cfg_ocs['importsnmp_name'] && $action == "add" || $cfg_ocs['linksnmp_name'] && $linked || $action == "update" && $cfg_ocs['importsnmp_name'] && !$linked || $action == "update" && $cfg_ocs['linksnmp_name'] && $linked) {
         $input["name"] = $ocsSnmp['META']['NAME'];
     }
     if ($cfg_ocs['importsnmp_contact'] && $action == "add" || $cfg_ocs['linksnmp_contact'] && $linked || $action == "update" && $cfg_ocs['importsnmp_name'] && !$linked || $action == "update" && $cfg_ocs['linksnmp_name'] && $linked) {
         $input["contact"] = $ocsSnmp['META']['CONTACT'];
     }
     if ($cfg_ocs['importsnmp_comment'] && $action == "add" || $cfg_ocs['linksnmp_comment'] && $linked || $action == "update" && $cfg_ocs['importsnmp_name'] && !$linked || $action == "update" && $cfg_ocs['linksnmp_name'] && $linked) {
         $input["comment"] = $ocsSnmp['META']['DESCRIPTION'];
     }
     if ($loc_id > 0) {
         $input["locations_id"] = $loc_id;
     }
     if ($dom_id > 0 && $itemtype != "Phone") {
         $input["domains_id"] = $dom_id;
     }
     $id_item = 0;
     if ($action == "add") {
         $id_item = $snmpDevice->add($input, array('unicity_error_message' => true), $cfg_ocs['history_hardware']);
     } else {
         $input["id"] = $ID;
         $id_item = $ID;
         if ($snmpDevice->getFromDB($id_item)) {
             $input["entities_id"] = $snmpDevice->fields['entities_id'];
         }
         $snmpDevice->update($input, $cfg_ocs['history_hardware'], array('unicity_error_message' => false, '_no_history' => !$cfg_ocs['history_hardware']));
     }
     if ($id_item > 0 && ($cfg_ocs['importsnmp_createport'] && $action == "add" || $cfg_ocs['linksnmp_createport'] && $linked || $action == "update" && $cfg_ocs['importsnmp_createport'] && !$linked || $action == "update" && $cfg_ocs['linksnmp_createport'] && $linked)) {
         //Add network port
         $ip = $ocsSnmp['META']['IPADDR'];
         $mac = $ocsSnmp['META']['MACADDR'];
         $np = new NetworkPort();
         $np->getFromDBByQuery("WHERE `mac` LIKE '{$mac}' AND `items_id` = '{$id_item}' AND `itemtype` LIKE '{$itemtype}' ");
         if (count($np->fields) < 1) {
             $item = new $itemtype();
             $entity = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : 0;
             if ($item->getFromDB($id_item)) {
                 $entity = $item->fields['entities_id'];
             }
             $port_input = array('name' => $ocsSnmp['META']['NAME'], 'mac' => $mac, 'items_id' => $id_item, 'itemtype' => $itemtype, 'instantiation_type' => "NetworkPortEthernet", "entities_id" => $entity, "NetworkName__ipaddresses" => array("-100" => $ip), '_create_children' => 1, 'is_deleted' => 0);
             $np->add($port_input, array(), $cfg_ocs['history_network']);
         }
     }
     return $id_item;
 }
开发者ID:pluginsGLPI,项目名称:ocsinventoryng,代码行数:60,代码来源:snmpocslink.class.php

示例2: importIpDiscover

 /**
  * import ipdiscover object
  * @param type $ipDiscoveryObject array
  * @param type $plugin_ocsinventoryng_ocsservers_id integer
  * @param $subnet
  * @return array
  */
 static function importIpDiscover($ipDiscoveryObject, $plugin_ocsinventoryng_ocsservers_id, $subnet)
 {
     global $DB;
     $id = null;
     $identify = false;
     $cfg_ocs = PluginOcsinventoryngOcsServer::getConfig($plugin_ocsinventoryng_ocsservers_id);
     if (isset($ipDiscoveryObject["ocsItemType"]) && $ipDiscoveryObject["ocsItemType"] == Dropdown::EMPTY_VALUE) {
         return array('status' => PluginOcsinventoryngOcsServer::IPDISCOVER_FAILED_IMPORT);
     }
     if ($ipDiscoveryObject["itemDescription"] == '') {
         return array('status' => PluginOcsinventoryngOcsServer::IPDISCOVER_FAILED_IMPORT);
     }
     if ($ipDiscoveryObject["itemName"] == "") {
         $ipDiscoveryObject["itemName"] = $ipDiscoveryObject["itemDescription"];
     }
     switch ($ipDiscoveryObject["glpiItemType"]) {
         //empty dropdown value
         case '0':
             return array('status' => PluginOcsinventoryngOcsServer::IPDISCOVER_FAILED_IMPORT);
     }
     if (isset($ipDiscoveryObject["ocsItemType"])) {
         $identify = true;
     }
     $mac = $ipDiscoveryObject["macAdress"];
     $netPort = new NetworkPort();
     $netPort->getFromDBByQuery("WHERE `mac` = '{$mac}' ");
     if (count($netPort->fields) < 1) {
         $input = array('is_dynamic' => 1, 'locations_id' => 0, 'domains_id' => 0, 'entities_id' => $ipDiscoveryObject["entity"], 'name' => $ipDiscoveryObject["itemName"], 'comment' => $ipDiscoveryObject["itemDescription"]);
         $device = new $ipDiscoveryObject["glpiItemType"]();
         $id = $device->add($input, array(), $cfg_ocs['history_devices']);
         //ipdiscover link
         $date = date("Y-m-d H:i:s");
         $glpiType = $ipDiscoveryObject["glpiItemType"];
         $ip = $ipDiscoveryObject["itemIp"];
         $glpiQuery = "INSERT INTO `glpi_plugin_ocsinventoryng_ipdiscoverocslinks`\n                       (`items_id`,`itemtype`,`macaddress`,`last_update`,`subnet`,`plugin_ocsinventoryng_ocsservers_id`)\n                       VALUES('{$id}','{$glpiType}','{$mac}','{$date}','{$subnet}','{$plugin_ocsinventoryng_ocsservers_id}')";
         $DB->query($glpiQuery);
         //add port
         $port_input = array('name' => $ipDiscoveryObject["itemName"] . "-" . $ip, 'mac' => $mac, 'items_id' => $id, 'itemtype' => $glpiType, 'instantiation_type' => "NetworkPortEthernet", "entities_id" => $ipDiscoveryObject["entity"], "NetworkName__ipaddresses" => array("-100" => $ip), '_create_children' => 1, 'is_deleted' => 0);
         $netPort->add($port_input, array(), $cfg_ocs['history_network']);
         /* $netPortInput = array(
                       "itemtype"           => $glpiType,
                       "items_id"           => $id,
                       'entities_id'        => $ipDiscoveryObject["entity"],
                       "name"               => $ipDiscoveryObject["itemName"] . "-" . $ip,
                       "instantiation_type" => "NetworkPortEthernet",
                       "mac"                => $mac
                   );
         
                   $netPort->splitInputForElements($netPortInput);
                   $NewNetPortId = $netPort->add($netPortInput);
                   $netPort->updateDependencies(1);
                   //make link to IPAdress manualy
         
                   //add ipAdress
                   $networkName= new NetworkName();
                   $networkNameId=$networkName->add(array("items_id"=>$NewNetPortId,"itemtype"=>"NetworkPort"));
                   $ipAdresses = new IPAddress();
         
                   $input = array('name'        => $ip,
                               'itemtype'    => 'NetworkName',
                               'items_id'    => $networkNameId,
                               'is_deleted'  => 0,
                                'mainitems_id'=>$id,
                                'mainitemtype'=>$glpiType);
                   $ipAdresses->add($input);*/
     }
     if ($id && $identify) {
         //identify object
         //WAS IS DAS ? CHMA
         $userId = Session::getLoginUserID();
         $query = "SELECT `glpi_users`.`name` \n                         FROM `glpi_users`\n                         WHERE glpi_users.id like '{$userId}'";
         $queryResult = $DB->query($query);
         $userAssoc = $DB->fetch_assoc($queryResult);
         if ($userAssoc) {
             $ocsClient = new PluginOcsinventoryngOcsServer();
             $DBOCS = $ocsClient->getDBocs($plugin_ocsinventoryng_ocsservers_id)->getDB();
             $ocsType = $ipDiscoveryObject["ocsItemType"];
             $description = $ipDiscoveryObject["itemDescription"];
             $user = $userAssoc["name"];
             $ocsQuery = "INSERT INTO `network_devices` (`description`,`type`,`macaddr`,`user`)\n                            VALUES('{$description}','{$ocsType}','{$mac}','{$user}')";
             $DBOCS->query($ocsQuery);
         }
     }
     if ($id) {
         return array('status' => PluginOcsinventoryngOcsServer::IPDISCOVER_IMPORTED);
     } else {
         Session::addMessageAfterRedirect($mac . " : " . __('Unable to add. an object with same MAC address already exists.', 'ocsinventoryng'), false, ERROR);
         return array('status' => PluginOcsinventoryngOcsServer::IPDISCOVER_FAILED_IMPORT);
     }
 }
开发者ID:pluginsGLPI,项目名称:ocsinventoryng,代码行数:97,代码来源:ipdiscoverocslink.class.php


注:本文中的NetworkPort::getFromDBByQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。