Transfer::transferItem PHP Method

transferItem() public method

transfer an item to another item (may be the same) in the new entity
public transferItem ( $itemtype, $ID, $newID ) : nothing
$itemtype item type to transfer
$ID ID of the item to transfer
$newID new ID of the ite Transfer item to a new Item if $ID==$newID : only update entities_id field : $ID!=$new ID -> copy datas (like template system)
return nothing (diplays)
    function transferItem($itemtype, $ID, $newID)
    {
        global $CFG_GLPI, $DB;
        if (!($item = getItemForItemtype($itemtype))) {
            return;
        }
        // Is already transfer ?
        if (!isset($this->already_transfer[$itemtype][$ID])) {
            // Check computer exists ?
            if ($item->getFromDB($newID)) {
                // Network connection ? keep connected / keep_disconnected / delete
                if (in_array($itemtype, array('Computer', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer'))) {
                    $this->transferNetworkLink($itemtype, $ID, $newID);
                }
                // Device : keep / delete : network case : delete if net connection delete in import case
                if (in_array($itemtype, Item_Devices::getConcernedItems())) {
                    $this->transferDevices($itemtype, $ID, $newID);
                }
                // Reservation : keep / delete
                if (in_array($itemtype, $CFG_GLPI["reservation_types"])) {
                    $this->transferReservations($itemtype, $ID, $newID);
                }
                // History : keep / delete
                $this->transferHistory($itemtype, $ID, $newID);
                // Ticket : delete / keep and clean ref / keep and move
                $this->transferTickets($itemtype, $ID, $newID);
                // Infocoms : keep / delete
                if (InfoCom::canApplyOn($itemtype)) {
                    $this->transferInfocoms($itemtype, $ID, $newID);
                }
                if ($itemtype == 'Software') {
                    $this->transferSoftwareLicensesAndVersions($ID);
                }
                // Connected item is transfered
                if (in_array($itemtype, $CFG_GLPI["directconnect_types"])) {
                    $this->manageConnectionComputer($itemtype, $ID);
                }
                // Computer Direct Connect : delete link if it is the initial transfer item (no recursion)
                if ($this->inittype == $itemtype && in_array($itemtype, array('Monitor', 'Phone', 'Peripheral', 'Printer'))) {
                    $this->deleteDirectConnection($itemtype, $ID);
                }
                // Contract : keep / delete + clean unused / keep unused
                if (in_array($itemtype, $CFG_GLPI["contract_types"])) {
                    $this->transferContracts($itemtype, $ID, $newID);
                }
                // Contact / Supplier : keep / delete + clean unused / keep unused
                if ($itemtype == 'Supplier') {
                    $this->transferSupplierContacts($ID, $newID);
                }
                // Document : keep / delete + clean unused / keep unused
                if (Document::canApplyOn($itemtype)) {
                    $this->transferDocuments($itemtype, $ID, $newID);
                }
                // Transfer compatible printers
                if ($itemtype == 'CartridgeItem') {
                    $this->transferCompatiblePrinters($ID, $newID);
                }
                // Cartridges  and cartridges items linked to printer
                if ($itemtype == 'Printer') {
                    $this->transferPrinterCartridges($ID, $newID);
                }
                // Transfer Item
                $input = array('id' => $newID, 'entities_id' => $this->to);
                // Manage Location dropdown
                if (isset($item->fields['locations_id'])) {
                    $input['locations_id'] = $this->transferDropdownLocation($item->fields['locations_id']);
                }
                if (in_array($itemtype, array('Ticket', 'Problem', 'Change'))) {
                    $input2 = $this->transferHelpdeskAdditionalInformations($item->fields);
                    $input = array_merge($input, $input2);
                    $this->transferTaskCategory($itemtype, $ID, $newID);
                    $this->transferLinkedSuppliers($itemtype, $ID, $newID);
                }
                $item->update($input);
                $this->addToAlreadyTransfer($itemtype, $ID, $newID);
                // Do it after item transfer for entity checks
                if ($itemtype == 'Computer') {
                    // Monitor Direct Connect : keep / delete + clean unused / keep unused
                    $this->transferDirectConnection($itemtype, $ID, 'Monitor');
                    // Peripheral Direct Connect : keep / delete + clean unused / keep unused
                    $this->transferDirectConnection($itemtype, $ID, 'Peripheral');
                    // Phone Direct Connect : keep / delete + clean unused / keep unused
                    $this->transferDirectConnection($itemtype, $ID, 'Phone');
                    // Printer Direct Connect : keep / delete + clean unused / keep unused
                    $this->transferDirectConnection($itemtype, $ID, 'Printer');
                    // License / Software :  keep / delete + clean unused / keep unused
                    $this->transferComputerSoftwares($ID);
                    // Computer Disks :  delete them or not ?
                    $this->transferComputerDisks($ID);
                }
                Plugin::doHook("item_transfer", array('type' => $itemtype, 'id' => $ID, 'newID' => $newID, 'entities_id' => $this->to));
            }
        }
    }