public moveItems ( $items, $to, $options ) | ||
$items | items to transfer | |
$to | entity destination ID | |
$options | options used to transfer |
function moveItems($items, $to, $options)
{
global $CFG_GLPI;
// unset mailing
$CFG_GLPI["use_mailing"] = 0;
$this->options = array('keep_ticket' => 0, 'keep_networklink' => 0, 'keep_reservation' => 0, 'keep_history' => 0, 'keep_device' => 0, 'keep_infocom' => 0, 'keep_dc_monitor' => 0, 'clean_dc_monitor' => 0, 'keep_dc_phone' => 0, 'clean_dc_phone' => 0, 'keep_dc_peripheral' => 0, 'clean_dc_peripheral' => 0, 'keep_dc_printer' => 0, 'clean_dc_printer' => 0, 'keep_supplier' => 0, 'clean_supplier' => 0, 'keep_contact' => 0, 'clean_contact' => 0, 'keep_contract' => 0, 'clean_contract' => 0, 'keep_disk' => 0, 'keep_software' => 0, 'clean_software' => 0, 'keep_document' => 0, 'clean_document' => 0, 'keep_cartridgeitem' => 0, 'clean_cartridgeitem' => 0, 'keep_cartridge' => 0, 'keep_consumable' => 0);
if ($to >= 0) {
// Store to
$this->to = $to;
// Store options
if (is_array($options) && count($options)) {
foreach ($options as $key => $val) {
$this->options[$key] = $val;
}
}
// Simulate transfers To know which items need to be transfer
$this->simulateTransfer($items);
//Html::printCleanArray($this->needtobe_transfer);
// Software first (to avoid copy during computer transfer)
$this->inittype = 'Software';
if (isset($items['Software']) && count($items['Software'])) {
foreach ($items['Software'] as $ID) {
$this->transferItem('Software', $ID, $ID);
}
}
// Computer before all other items
$this->inittype = 'Computer';
if (isset($items['Computer']) && count($items['Computer'])) {
foreach ($items['Computer'] as $ID) {
$this->transferItem('Computer', $ID, $ID);
}
}
// Inventory Items : MONITOR....
$INVENTORY_TYPES = array('CartridgeItem', 'ConsumableItem', 'Monitor', 'NetworkEquipment', 'Peripheral', 'Phone', 'Printer', 'SoftwareLicense');
foreach ($INVENTORY_TYPES as $itemtype) {
$this->inittype = $itemtype;
if (isset($items[$itemtype]) && count($items[$itemtype])) {
foreach ($items[$itemtype] as $ID) {
$this->transferItem($itemtype, $ID, $ID);
}
}
}
// Clean unused
$this->cleanSoftwareVersions();
// Management Items
$MANAGEMENT_TYPES = array('Contact', 'Contract', 'Document', 'Supplier');
foreach ($MANAGEMENT_TYPES as $itemtype) {
$this->inittype = $itemtype;
if (isset($items[$itemtype]) && count($items[$itemtype])) {
foreach ($items[$itemtype] as $ID) {
$this->transferItem($itemtype, $ID, $ID);
}
}
}
// Tickets
$OTHER_TYPES = array('Group', 'Link', 'Ticket', 'Problem', 'Change');
foreach ($OTHER_TYPES as $itemtype) {
$this->inittype = $itemtype;
if (isset($items[$itemtype]) && count($items[$itemtype])) {
foreach ($items[$itemtype] as $ID) {
$this->transferItem($itemtype, $ID, $ID);
}
}
}
}
// $to >= 0
}
static function uninstall($type, $model_id, $tab_ids, $location) { global $UNINSTALL_DIRECT_CONNECTIONS_TYPE; //Get the model $model = new PluginUninstallModel(); $model->getConfig($model_id); //Then destroy all the connexions $transfer = new Transfer(); $transfer->getFromDB($model->fields["transfers_id"]); echo "<div class='center'>"; echo "<table class='tab_cadre_fixe'><tr><th>" . __('Uninstall', 'uninstall') . "</th></tr>"; echo "<tr class='tab_bg_2'><td>"; $count = 0; $tot = count($tab_ids[$type]); Html::createProgressBar(__('Please wait, uninstallation is running...', 'uninstall')); foreach ($tab_ids[$type] as $id => $value) { $count++; $item = new $type(); $item->getFromDB($id); //First clean object and change location and status if needed $entity = $item->fields["entities_id"]; $input = array(); $input["id"] = $id; $input["entities_id"] = $entity; $fields = array(); //Hook to perform actions before item is being uninstalled $item->fields['_uninstall_event'] = $model->getID(); $item->fields['_action'] = 'uninstall'; Plugin::doHook("plugin_uninstall_before", $item); //--------------------// //Direct connections // //------------------// if (in_array($type, $UNINSTALL_DIRECT_CONNECTIONS_TYPE)) { $conn = new Computer_Item(); $conn->deleteByCriteria(array('computers_id' => $id), true); } //--------------------// //-- Common fields --// //------------------// //RAZ contact and contactnumber if ($item->isField('contact') && $model->fields["raz_contact"] == 1) { $fields["contact"] = ''; if ($item->isField('contact_num')) { $fields["contact_num"] = ''; } } //RAZ user if ($model->fields["raz_user"] == 1 && $item->isField('users_id')) { $fields["users_id"] = 0; } //RAZ status if ($model->fields["states_id"] > 0 && $item->isField('states_id')) { $fields["states_id"] = $model->fields["states_id"]; } //RAZ machine's name if ($item->isField('name') && $model->fields["raz_name"] == 1) { $fields["name"] = ''; } if ($item->isField('locations_id')) { if ($location == '') { $location = 0; } switch ($location) { case -1: break; default: $fields["locations_id"] = $location; break; } } if ($item->isField('groups_id')) { $nbgroup = countElementsInTableForEntity("glpi_groups", $entity, "`id`='" . $item->fields['groups_id'] . "'"); if ($model->fields["groups_id"] > -1 && $nbgroup == 1) { // If a new group is defined and if the group is accessible in the object's entity $fields["groups_id"] = $model->fields["groups_id"]; } } //------------------------------// //-- Computer specific fields --// //------------------------------// if ($type == 'Computer') { //RAZ all OS related informations if ($model->fields["raz_os"] == 1) { $fields["operatingsystems_id"] = 0; $fields["operatingsystemversions_id"] = 0; $fields["operatingsystemservicepacks_id"] = 0; $fields["os_licenseid"] = ''; $fields["os_license_number"] = ''; $fields["autoupdatesystems_id"] = 0; } $plug = new Plugin(); if ($plug->isActivated('ocsinventoryng')) { if ($item->fields["is_dynamic"] && ($model->fields["remove_from_ocs"] || $model->fields["delete_ocs_link"])) { $input["is_dynamic"] = 0; } } if ($item->isField('domains_id') && $model->fields["raz_domain"]) { $fields["domains_id"] = 0; } //RAZ network if ($item->isField('networks_id') && $model->fields["raz_network"] == 1) { $fields["networks_id"] = 0; } } //RAZ IPs from all the network cards if ($model->fields["raz_ip"] == 1) { self::razPortInfos($type, $id); // For NetworkEquiment if ($item->isField('ip')) { $fields['ip'] = ''; } if ($item->isField('mac')) { $fields['mac'] = ''; } } foreach ($fields as $name => $value) { if (!($item->getField($name) != NOT_AVAILABLE) || $item->getField($name) != $value) { $input[$name] = $value; } } $item->dohistory = true; $item->update($input); if ($model->fields["raz_budget"] == 1) { $infocom_id = self::getInfocomPresentForDevice($type, $id); if ($infocom_id > 0) { $infocom = new InfoCom(); $tmp["id"] = $infocom_id; $tmp["budgets_id"] = 0; $infocom->dohistory = false; $infocom->update($tmp); } } //Delete machine from glpi_ocs_link if ($type == 'Computer') { //Delete computer's volumes self::purgeComputerVolumes($id); if ($model->fields["raz_history"] == 1) { //Delete history related to software self::deleteHistory($id, false); } else { if ($model->fields["raz_soft_history"] == 1) { //Delete history related to software self::deleteHistory($id, true); } } $plug = new Plugin(); if ($plug->isActivated('ocsinventoryng')) { //Delete computer from OCS if ($model->fields["remove_from_ocs"] == 1) { self::deleteComputerInOCSByGlpiID($id); } //Delete link in glpi_ocs_link if ($model->fields["delete_ocs_link"] || $model->fields["remove_from_ocs"]) { self::deleteOcsLink($id); } } //Should never happend that transfer_id = 0, but just in case if ($model->fields["transfers_id"] > 0) { $transfer->moveItems(array($type => array($id => $id)), $entity, $transfer->fields); } } if ($model->fields['raz_fusioninventory'] == 1) { self::deleteFusionInventoryLink($type, $id); } //Plugin hook after uninstall Plugin::doHook("plugin_uninstall_after", $item); Html::changeProgressBarPosition($count, $tot + 1); } //Add line in machine's history to say that machine was uninstalled self::addUninstallLog($type, $id); Html::changeProgressBarPosition($count, $tot, __('Uninstallation successful', 'uninstall')); echo "</td></tr>"; echo "</table></div>"; }