Transfer::copySingleSoftware PHP Method

copySingleSoftware() public method

Copy (if needed) One software to the destination entity
public copySingleSoftware ( $ID )
$ID of the software
    function copySingleSoftware($ID)
    {
        global $DB;
        if (isset($this->already_transfer['Software'][$ID])) {
            return $this->already_transfer['Software'][$ID];
        }
        $soft = new Software();
        if ($soft->getFromDB($ID)) {
            if ($soft->fields['is_recursive'] && in_array($soft->fields['entities_id'], getAncestorsOf("glpi_entities", $this->to))) {
                // no need to copy
                $newsoftID = $ID;
            } else {
                $manufacturer = '';
                if (isset($soft->fields['manufacturers_id']) && $soft->fields['manufacturers_id'] > 0) {
                    $manufacturer = "AND `manufacturers_id` = '" . $soft->fields['manufacturers_id'] . "'";
                }
                $query = "SELECT *\n                      FROM `glpi_softwares`\n                      WHERE `entities_id` = " . $this->to . "\n                            AND `name` = '" . addslashes($soft->fields['name']) . "'\n                            {$manufacturer}";
                if ($data = $DB->request($query)->next()) {
                    $newsoftID = $data["id"];
                } else {
                    // create new item (don't check if move possible => clean needed)
                    unset($soft->fields['id']);
                    $input = $soft->fields;
                    $input['entities_id'] = $this->to;
                    unset($soft->fields);
                    $newsoftID = $soft->add(toolbox::addslashes_deep($input));
                }
            }
            $this->addToAlreadyTransfer('Software', $ID, $newsoftID);
            return $newsoftID;
        }
        return -1;
    }