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


PHP NetworkPort::switchInstantiationType方法代码示例

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


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

示例1: processMassiveActionsForOneItemtype

 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     global $DB;
     switch ($ma->getAction()) {
         case 'transform_to':
             $input = $ma->getInput();
             if (isset($input["transform_to"]) && !empty($input["transform_to"])) {
                 $networkport = new NetworkPort();
                 foreach ($ids as $id) {
                     if ($networkport->canEdit($id) && $item->can($id, DELETE)) {
                         if (empty($networkport->fields['instantiation_type'])) {
                             if ($networkport->switchInstantiationType($input['transform_to']) !== false) {
                                 $instantiation = $networkport->getInstantiation();
                                 $input2 = $item->fields;
                                 $input2['networkports_id'] = $input2['id'];
                                 unset($input2['id']);
                                 if ($instantiation->add($input2)) {
                                     $item->delete(array('id' => $id));
                                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                                 } else {
                                     $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                                     $ma->addMessage($networkport->getErrorMessage(ERROR_ON_ACTION));
                                 }
                             } else {
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                                 $ma->addMessage($networkport->getErrorMessage(ERROR_ON_ACTION));
                             }
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                             $ma->addMessage($networkport->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($networkport->getErrorMessage(ERROR_RIGHT));
                     }
                 }
             } else {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:48,代码来源:networkportmigration.class.php

示例2: updateNetworkPort

 /**
  * @param $mac
  * @param $name
  * @param $computers_id
  * @param $instantiation_type
  * @param $inst_input
  * @param $ips
  * @param $check_name
  * @param $dohistory
  * @param $already_known_ports
  * @return ID
  */
 private static function updateNetworkPort($mac, $name, $computers_id, $instantiation_type, $inst_input, $ips, $check_name, $dohistory, $already_known_ports)
 {
     global $DB;
     $network_port = new NetworkPort();
     // Then, find or create the base NetworkPort
     $query = "SELECT `id`, `is_dynamic`\n                FROM `glpi_networkports`\n                WHERE `itemtype` = 'Computer'\n                   AND `items_id` = '{$computers_id}'\n                   AND `mac` = '{$mac}'";
     // If there is virtual ports, then, filter by port's name
     if ($check_name) {
         $query .= " AND `name` = '{$name}'";
     }
     if (count($already_known_ports) > 0) {
         $query .= " AND `id` NOT IN (" . implode(',', $already_known_ports) . ")";
     }
     // We order by is_dynamic to be sure to get the static ones first !
     $query .= " ORDER BY `is_dynamic`, `id`";
     $ports = $DB->request($query);
     if ($ports->numrows() == 0) {
         $port_input = array('name' => $name, 'mac' => $mac, 'items_id' => $computers_id, 'itemtype' => 'Computer', '_no_history' => !$dohistory, 'instantiation_type' => $instantiation_type, '_create_children' => 1, 'is_dynamic' => 1, 'is_deleted' => 0);
         $networkports_id = $network_port->add($port_input, array(), $dohistory);
         if ($networkports_id === false) {
             return -1;
         }
         $inst_input['networkports_id'] = $networkports_id;
         $instantiation = $network_port->getInstantiation();
         $instantiation->update($inst_input);
         unset($instantiation);
     } else {
         $line = $ports->next();
         $networkports_id = $line['id'];
         $network_port->getFromDB($networkports_id);
         if (!$check_name && $network_port->fields['name'] != $name) {
             $port_input = array('id' => $network_port->getID(), 'name' => $name, 'is_dynamic' => 1);
             $network_port->update($port_input);
         }
         if ($network_port->fields['instantiation_type'] != $instantiation_type && $network_port->fields['is_dynamic'] == 1) {
             $network_port->switchInstantiationType($instantiation_type);
             $inst_input['networkports_id'] = $network_port->getID();
             $instantiation = $network_port->getInstantiation();
             $instantiation->add($inst_input);
             unset($instantiation);
         }
         if ($network_port->fields['instantiation_type'] == $instantiation_type) {
             $instantiation = $network_port->getInstantiation();
             $inst_input['id'] = $instantiation->getID();
             $inst_input['networkports_id'] = $network_port->getID();
             $instantiation->update($inst_input);
             unset($instantiation);
         }
     }
     if ($network_port->isNewItem()) {
         return -1;
     }
     $network_name = new NetworkName();
     $query = "SELECT `id`, `is_dynamic`\n                FROM `glpi_networknames`\n                WHERE `itemtype` = 'NetworkPort'\n                   AND `items_id` = '{$networkports_id}'\n                ORDER BY `is_dynamic`";
     if (!$ips || count($ips) == 0) {
         foreach ($DB->request($query) as $line) {
             if ($line['is_dynamic']) {
                 $network_name->delete($line, true, $dohistory);
             }
         }
     } else {
         $names = $DB->request($query);
         if ($names->numrows() == 0) {
             $name_input = array('itemtype' => 'NetworkPort', 'items_id' => $networkports_id, 'is_dynamic' => 1, 'is_deleted' => 0, '_no_history' => !$dohistory, 'name' => 'OCS-INVENTORY-NG');
             $networknames_id = $network_name->add($name_input);
         } else {
             $line = $names->next();
             $networknames_id = $line['id'];
             foreach ($names as $line) {
                 if ($line['is_dynamic'] == 1 && $line['id'] != $networknames_id) {
                     $network_port->delete($line, true, $dohistory);
                 }
             }
         }
         $ip_address = new IPAddress();
         $already_known_addresses = array();
         $query = "SELECT `id`, `name`, `is_dynamic`, `mainitems_id`\n                   FROM `glpi_ipaddresses`\n                   WHERE `itemtype` = 'NetworkName'\n                     AND `items_id` = '{$networknames_id}'\n                   ORDER BY `is_dynamic`";
         foreach ($DB->request($query) as $line) {
             if (in_array($line['name'], $ips) && !empty($line['mainitems_id'])) {
                 $already_known_addresses[] = $line['id'];
                 $ips = array_diff($ips, array($line['name']));
             } elseif ($line['is_dynamic'] == 1) {
                 $ip_address->delete($line, true, $dohistory);
             }
         }
     }
     if ($ips) {
         foreach ($ips as $ip) {
//.........这里部分代码省略.........
开发者ID:pluginsGLPI,项目名称:ocsinventoryng,代码行数:101,代码来源:networkport.class.php

示例3: foreach

     Session::checkRight("networking", UPDATE);
     if (isset($_POST["del_port"]) && count($_POST["del_port"])) {
         foreach ($_POST["del_port"] as $port_id => $val) {
             if ($np->can($port_id, PURGE)) {
                 $np->delete(array("id" => $port_id));
             }
         }
     }
     Event::log(0, "networkport", 5, "inventory", sprintf(__('%s deletes several network ports'), $_SESSION["glpiname"]));
     Html::back();
 } else {
     if (isset($_POST["update"])) {
         $np->check($_POST['id'], PURGE);
         $networkport = new NetworkPort();
         if ($networkport->can($_POST['id'], UPDATE)) {
             if ($networkport->switchInstantiationType($_POST['transform_to']) !== false) {
                 $instantiation = $networkport->getInstantiation();
                 $input = $np->fields;
                 $input['networkports_id'] = $input['id'];
                 unset($input['id']);
                 if ($instantiation->add($input)) {
                     $np->delete($_POST);
                 }
             } else {
                 Session::addMessageAfterRedirect(__('Cannot change a migration network port to an unknown one'));
             }
         } else {
             Session::addMessageAfterRedirect(__('Network port is not available...'));
             $np->delete($_POST);
         }
         Html::redirect($CFG_GLPI["root_doc"] . "/front/networkportmigration.php");
开发者ID:paisdelconocimiento,项目名称:glpi-smartcities,代码行数:31,代码来源:networkportmigration.form.php

示例4: doSpecificMassiveActions

 /**
  * @see CommonDBTM::doSpecificMassiveActions()
  **/
 function doSpecificMassiveActions($input = array())
 {
     $res = array('ok' => 0, 'ko' => 0, 'noright' => 0);
     switch ($input['action']) {
         case "transform_to":
             if (isset($input["transform_to"]) && !empty($input["transform_to"])) {
                 $networkport = new NetworkPort();
                 foreach ($input["item"] as $key => $val) {
                     if ($val == 1) {
                         if ($networkport->can($key, 'w') && $this->can($key, 'd')) {
                             // Don't try to migrate already affected ports
                             if (empty($networkport->fields['instantiation_type'])) {
                                 if ($networkport->switchInstantiationType($input['transform_to']) !== false) {
                                     $instantiation = $networkport->getInstantiation();
                                     $input2 = $this->fields;
                                     $input2['networkports_id'] = $input2['id'];
                                     unset($input2['id']);
                                     if ($instantiation->add($input2)) {
                                         $this->delete(array('id' => $key));
                                         $res['ok']++;
                                     } else {
                                         $res['ko']++;
                                     }
                                 } else {
                                     $res['ko']++;
                                 }
                             } else {
                                 $res['ko']++;
                             }
                         } else {
                             $res['noright']++;
                         }
                     }
                 }
             } else {
                 $res['ko']++;
             }
             break;
         default:
             return parent::doSpecificMassiveActions($input);
     }
     return $res;
 }
开发者ID:geldarr,项目名称:hack-space,代码行数:46,代码来源:networkportmigration.class.php


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