/** * Clone the current NetworkPort when the item is clone * * @since version 0.84 * * @param $itemtype the type of the item that was clone * @param $old_items_id the id of the item that was clone * @param $new_items_id the id of the item after beeing cloned **/ static function cloneItem($itemtype, $old_items_id, $new_items_id) { global $DB; $np = new self(); // ADD Ports $query = "SELECT `id`\n FROM `glpi_networkports`\n WHERE `items_id` = '" . $old_items_id . "'\n AND `itemtype` = '" . $itemtype . "';"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { while ($data = $DB->fetch_assoc($result)) { $np->getFromDB($data["id"]); unset($np->fields["id"]); $np->fields["items_id"] = $new_items_id; $portid = $np->addToDB(); $instantiation = $np->getInstantiation(); if ($instantiation !== false) { $instantiation->add(array('id' => $portid)); unset($instantiation); } $npv = new NetworkPort_Vlan(); foreach ($DB->request($npv->getTable(), array($npv->items_id_1 => $data["id"])) as $vlan) { $input = array($npv->items_id_1 => $portid, $npv->items_id_2 => $vlan['vlans_id']); if (isset($vlan['tagged'])) { $input['tagged'] = $vlan['tagged']; } $npv->add($input); } } } }
/** * Clone the current NetworkPort when the item is clone * * @since version 0.84 * * @param $itemtype the type of the item that was clone * @param $old_items_id the id of the item that was clone * @param $new_items_id the id of the item after beeing cloned **/ static function cloneItem($itemtype, $old_items_id, $new_items_id) { global $DB; $np = new self(); // ADD Ports foreach ($DB->request('glpi_networkports', array('FIELDS' => 'id', 'WHERE' => "`items_id` = '{$old_items_id}'\n AND `itemtype` = '{$itemtype}'")) as $data) { $np->getFromDB($data["id"]); $instantiation = $np->getInstantiation(); unset($np->fields["id"]); $np->fields["items_id"] = $new_items_id; $portid = $np->addToDB(); if ($instantiation !== false) { $input = array(); $input["networkports_id"] = $portid; unset($instantiation->fields["id"]); unset($instantiation->fields["networkports_id"]); foreach ($instantiation->fields as $key => $val) { if (!empty($val)) { $input[$key] = $val; } } $instantiation->add($input); unset($instantiation); } $npv = new NetworkPort_Vlan(); foreach ($DB->request($npv->getTable(), array($npv::$items_id_1 => $data["id"])) as $vlan) { $input = array($npv::$items_id_1 => $portid, $npv::$items_id_2 => $vlan['vlans_id']); if (isset($vlan['tagged'])) { $input['tagged'] = $vlan['tagged']; } $npv->add($input); } } }