moveItems() public method

Transfer items
public moveItems ( $items, $to, $options )
$items items to transfer
$to entity destination ID
$options options used to transfer
コード例 #1
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>";
 }
コード例 #2
0
ファイル: transfer.action.php プロジェクト: btry/glpi
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Html::header(__('Transfer'), '', 'admin', 'rule', 'transfer');
$transfer = new Transfer();
$transfer->checkGlobal(READ);
if (isset($_POST['transfer'])) {
    if (isset($_SESSION['glpitransfer_list'])) {
        if (!Session::haveAccessToEntity($_POST['to_entity'])) {
            Html::displayRightError();
        }
        $transfer->moveItems($_SESSION['glpitransfer_list'], $_POST['to_entity'], $_POST);
        unset($_SESSION['glpitransfer_list']);
        echo "<div class='b center'>" . __('Operation successful') . "<br>";
        echo "<a href='central.php'>" . __('Back') . "</a></div>";
        Html::footer();
        exit;
    }
} else {
    if (isset($_POST['clear'])) {
        unset($_SESSION['glpitransfer_list']);
        echo "<div class='b center'>" . __('Operation successful') . "<br>";
        echo "<a href='central.php'>" . __('Back') . "</a></div>";
        echo "</div>";
        Html::footer();
        exit;
    }
コード例 #3
0
 /**
  * Do automatic transfer if option is enable
  *
  * @param $line_links array : data from glpi_plugin_ocsinventoryng_ocslinks table
  * @param $line_ocs array : data from ocs tables
  *
  * @return nothing
  **/
 static function transferComputer($line_links, $line_ocs)
 {
     global $DB, $PluginOcsinventoryngDBocs, $CFG_GLPI;
     // Get all rules for the current plugin_ocsinventoryng_ocsservers_id
     $rule = new RuleImportEntityCollection();
     $data = array();
     $data = $rule->processAllRules(array('ocsservers_id' => $line_links["plugin_ocsinventoryng_ocsservers_id"], '_source' => 'ocsinventoryng'), array(), array('ocsid' => $line_links["ocsid"]));
     // If entity is changing move items to the new entities_id
     if (isset($data['entities_id']) && $data['entities_id'] != $line_links['entities_id']) {
         if (!isCommandLine() && !Session::haveAccessToEntity($data['entities_id'])) {
             Html::displayRightError();
         }
         $transfer = new Transfer();
         $transfer->getFromDB($CFG_GLPI['transfers_id_auto']);
         $item_to_transfer = array("Computer" => array($line_links['computers_id'] => $line_links['computers_id']));
         $transfer->moveItems($item_to_transfer, $data['entities_id'], $transfer->fields);
     }
     //If location is update by a rule
     self::updateLocation($line_links, $data);
 }
コード例 #4
0
 /**
  * Update computer to not change entity (transfer not allowed)
  *
  * @test
  */
 public function updateComputerNoTranfer()
 {
     global $DB;
     $DB->connect();
     $transfer = new Transfer();
     $computer = new Computer();
     $pfiComputerInv = new PluginFusioninventoryInventoryComputerInventory();
     $pfEntity = new PluginFusioninventoryEntity();
     // Manual transfer computer to entity 2
     $transfer->getFromDB(1);
     $item_to_transfer = array("Computer" => array(1 => 1));
     $transfer->moveItems($item_to_transfer, 2, $transfer->fields);
     $computer->getFromDB(1);
     $this->assertEquals(2, $computer->fields['entities_id'], 'Transfer move computer');
     $this->AgentEntity(1, 2, 'Transfer computer on entity 2');
     // Define entity 2 not allowed to transfer
     $ents_id = $pfEntity->add(array('entities_id' => 2, 'transfers_id_auto' => 0));
     $this->assertEquals(2, $ents_id, 'Entity 2 defined with no transfer');
     // Update computer and computer must not be transfered (keep in entoty 2)
     $a_inventory = array();
     $a_inventory['CONTENT']['HARDWARE'] = array('NAME' => 'pc1');
     $a_inventory['CONTENT']['BIOS'] = array('SSN' => 'xxyyzz');
     $pfiComputerInv->import("pc-2013-02-13", "", $a_inventory);
     // Update
     $this->assertEquals(1, countElementsInTable('glpi_computers'), 'Must have only 1 computer');
     $computer->getFromDB(1);
     $this->assertEquals(2, $computer->fields['entities_id'], 'Computer must not be transfered');
     $this->AgentEntity(1, 2, 'Agent must stay with entity 2');
 }
 /**
  * If rule have found computer or rule give to create computer
  *
  * @param $items_id integer id of the computer found (or 0 if must be created)
  * @param $itemtype value Computer type here
  *
  * @return nothing
  *
  **/
 function rulepassed($items_id, $itemtype)
 {
     global $DB, $PLUGIN_FUSIONINVENTORY_XML, $PF_ESXINVENTORY, $CFG_GLPI;
     PluginFusioninventoryToolbox::logIfExtradebug("pluginFusioninventory-rules", "Rule passed : " . $items_id . ", " . $itemtype . "\n");
     $pfFormatconvert = new PluginFusioninventoryFormatconvert();
     $a_computerinventory = $pfFormatconvert->replaceids($this->arrayinventory);
     $entities_id = $_SESSION["plugin_fusioninventory_entity"];
     if ($itemtype == 'Computer') {
         $pfInventoryComputerLib = new PluginFusioninventoryInventoryComputerLib();
         $pfAgent = new PluginFusioninventoryAgent();
         $computer = new Computer();
         if ($items_id == '0') {
             if ($entities_id == -1) {
                 $entities_id = 0;
                 $_SESSION["plugin_fusioninventory_entity"] = 0;
             }
             $_SESSION['glpiactiveentities'] = array($entities_id);
             $_SESSION['glpiactiveentities_string'] = $entities_id;
             $_SESSION['glpiactive_entity'] = $entities_id;
         } else {
             $computer->getFromDB($items_id);
             $a_computerinventory['Computer']['states_id'] = $computer->fields['states_id'];
             $input = array();
             PluginFusioninventoryInventoryComputerInventory::addDefaultStateIfNeeded($input);
             if (isset($input['states_id'])) {
                 $a_computerinventory['Computer']['states_id'] = $input['states_id'];
             }
             if ($entities_id == -1) {
                 $entities_id = $computer->fields['entities_id'];
                 $_SESSION["plugin_fusioninventory_entity"] = $computer->fields['entities_id'];
             }
             $_SESSION['glpiactiveentities'] = array($entities_id);
             $_SESSION['glpiactiveentities_string'] = $entities_id;
             $_SESSION['glpiactive_entity'] = $entities_id;
             if ($computer->fields['entities_id'] != $entities_id) {
                 $pfEntity = new PluginFusioninventoryEntity();
                 $pfInventoryComputerComputer = new PluginFusioninventoryInventoryComputerComputer();
                 $moveentity = FALSE;
                 if ($pfEntity->getValue('transfers_id_auto', $computer->fields['entities_id']) > 0) {
                     if (!$pfInventoryComputerComputer->getLock($items_id)) {
                         $moveentity = TRUE;
                     }
                 }
                 if ($moveentity) {
                     $pfEntity = new PluginFusioninventoryEntity();
                     $transfer = new Transfer();
                     $transfer->getFromDB($pfEntity->getValue('transfers_id_auto', $entities_id));
                     $item_to_transfer = array("Computer" => array($items_id => $items_id));
                     $transfer->moveItems($item_to_transfer, $entities_id, $transfer->fields);
                 } else {
                     $_SESSION["plugin_fusioninventory_entity"] = $computer->fields['entities_id'];
                     $_SESSION['glpiactiveentities'] = array($computer->fields['entities_id']);
                     $_SESSION['glpiactiveentities_string'] = $computer->fields['entities_id'];
                     $_SESSION['glpiactive_entity'] = $computer->fields['entities_id'];
                     $entities_id = $computer->fields['entities_id'];
                 }
             }
         }
         $a_computerinventory = $pfFormatconvert->extraCollectInfo($a_computerinventory, $items_id);
         $a_computerinventory = $pfFormatconvert->computerSoftwareTransformation($a_computerinventory, $entities_id);
         $no_history = FALSE;
         // * New
         $setdynamic = 1;
         if ($items_id == '0') {
             $input = array();
             $input['entities_id'] = $entities_id;
             PluginFusioninventoryInventoryComputerInventory::addDefaultStateIfNeeded($input);
             if (isset($input['states_id'])) {
                 $a_computerinventory['Computer']['states_id'] = $input['states_id'];
             } else {
                 $a_computerinventory['Computer']['states_id'] = 0;
             }
             $items_id = $computer->add($input);
             $no_history = TRUE;
             $setdynamic = 0;
         }
         if (isset($_SESSION['plugin_fusioninventory_locations_id'])) {
             $a_computerinventory['Computer']['locations_id'] = $_SESSION['plugin_fusioninventory_locations_id'];
             unset($_SESSION['plugin_fusioninventory_locations_id']);
         }
         $serialized = gzcompress(serialize($a_computerinventory));
         $a_computerinventory['fusioninventorycomputer']['serialized_inventory'] = Toolbox::addslashes_deep($serialized);
         if (!$PF_ESXINVENTORY) {
             $pfAgent->setAgentWithComputerid($items_id, $this->device_id, $entities_id);
         }
         $pfConfig = new PluginFusioninventoryConfig();
         $query = "INSERT INTO `glpi_plugin_fusioninventory_dblockinventories`\n            SET `value`='" . $items_id . "'";
         $CFG_GLPI["use_log_in_files"] = FALSE;
         if (!$DB->query($query)) {
             $communication = new PluginFusioninventoryCommunication();
             $communication->setMessage("<?xml version='1.0' encoding='UTF-8'?>\n         <REPLY>\n         <ERROR>ERROR: SAME COMPUTER IS CURRENTLY UPDATED</ERROR>\n         </REPLY>");
             $communication->sendMessage($_SESSION['plugin_fusioninventory_compressmode']);
             exit;
         }
         $CFG_GLPI["use_log_in_files"] = TRUE;
         // * For benchs
         //$start = microtime(TRUE);
         PluginFusioninventoryInventoryComputerStat::increment();
         $pfInventoryComputerLib->updateComputer($a_computerinventory, $items_id, $no_history, $setdynamic);
         $query = "DELETE FROM `glpi_plugin_fusioninventory_dblockinventories`\n               WHERE `value`='" . $items_id . "'";
         $DB->query($query);
         $plugin = new Plugin();
         if ($plugin->isActivated('monitoring')) {
             Plugin::doOneHook("monitoring", "ReplayRulesForItem", array('Computer', $items_id));
         }
         // * For benchs
         //Toolbox::logInFile("exetime", (microtime(TRUE) - $start)." (".$items_id.")\n".
         //  memory_get_usage()."\n".
         //  memory_get_usage(TRUE)."\n".
         //  memory_get_peak_usage()."\n".
         //  memory_get_peak_usage()."\n");
         if (isset($_SESSION['plugin_fusioninventory_rules_id'])) {
             $pfRulematchedlog = new PluginFusioninventoryRulematchedlog();
             $inputrulelog = array();
             $inputrulelog['date'] = date('Y-m-d H:i:s');
             $inputrulelog['rules_id'] = $_SESSION['plugin_fusioninventory_rules_id'];
             if (isset($_SESSION['plugin_fusioninventory_agents_id'])) {
                 $inputrulelog['plugin_fusioninventory_agents_id'] = $_SESSION['plugin_fusioninventory_agents_id'];
             }
             $inputrulelog['items_id'] = $items_id;
             $inputrulelog['itemtype'] = $itemtype;
             $inputrulelog['method'] = 'inventory';
             $pfRulematchedlog->add($inputrulelog, array(), FALSE);
             $pfRulematchedlog->cleanOlddata($items_id, $itemtype);
             unset($_SESSION['plugin_fusioninventory_rules_id']);
         }
         // Write XML file
         if (!empty($PLUGIN_FUSIONINVENTORY_XML)) {
             PluginFusioninventoryToolbox::writeXML($items_id, $PLUGIN_FUSIONINVENTORY_XML->asXML(), 'computer');
         }
     } else {
         if ($itemtype == 'PluginFusioninventoryUnmanaged') {
             $a_computerinventory = $pfFormatconvert->computerSoftwareTransformation($a_computerinventory, $entities_id);
             $class = new $itemtype();
             if ($items_id == "0") {
                 if ($entities_id == -1) {
                     $entities_id = 0;
                     $_SESSION["plugin_fusioninventory_entity"] = 0;
                 }
                 $input = array();
                 $input['date_mod'] = date("Y-m-d H:i:s");
                 $items_id = $class->add($input);
                 if (isset($_SESSION['plugin_fusioninventory_rules_id'])) {
                     $pfRulematchedlog = new PluginFusioninventoryRulematchedlog();
                     $inputrulelog = array();
                     $inputrulelog['date'] = date('Y-m-d H:i:s');
                     $inputrulelog['rules_id'] = $_SESSION['plugin_fusioninventory_rules_id'];
                     if (isset($_SESSION['plugin_fusioninventory_agents_id'])) {
                         $inputrulelog['plugin_fusioninventory_agents_id'] = $_SESSION['plugin_fusioninventory_agents_id'];
                     }
                     $inputrulelog['items_id'] = $items_id;
                     $inputrulelog['itemtype'] = $itemtype;
                     $inputrulelog['method'] = 'inventory';
                     $pfRulematchedlog->add($inputrulelog);
                     $pfRulematchedlog->cleanOlddata($items_id, $itemtype);
                     unset($_SESSION['plugin_fusioninventory_rules_id']);
                 }
             }
             $class->getFromDB($items_id);
             $_SESSION["plugin_fusioninventory_entity"] = $class->fields['entities_id'];
             $input = array();
             $input['id'] = $class->fields['id'];
             // Write XML file
             if (!empty($PLUGIN_FUSIONINVENTORY_XML)) {
                 PluginFusioninventoryToolbox::writeXML($items_id, $PLUGIN_FUSIONINVENTORY_XML->asXML(), 'PluginFusioninventoryUnmanaged');
             }
             if (isset($a_computerinventory['Computer']['name'])) {
                 $input['name'] = $a_computerinventory['Computer']['name'];
             }
             $input['item_type'] = "Computer";
             if (isset($a_computerinventory['Computer']['domains_id'])) {
                 $input['domain'] = $a_computerinventory['Computer']['domains_id'];
             }
             if (isset($a_computerinventory['Computer']['serial'])) {
                 $input['serial'] = $a_computerinventory['Computer']['serial'];
             }
             $class->update($input);
         }
     }
 }
コード例 #6
0
 /**
  * Do automatic transfer if option is enable
  *
  * @param $line_links array : data from glpi_plugin_ocsinventoryng_ocslinks table
  * @return nothing
  * @internal param array $line_ocs : data from ocs tables
  *
  */
 static function transferComputer($line_links)
 {
     global $DB, $CFG_GLPI;
     $ocsClient = self::getDBocs($line_links["plugin_ocsinventoryng_ocsservers_id"]);
     $cfg_ocs = self::getConfig($line_links["plugin_ocsinventoryng_ocsservers_id"]);
     $ocsComputer = $ocsClient->getComputer($line_links["ocsid"]);
     $locations_id = 0;
     $contact = isset($ocsComputer['META']["USERID"]) ? $ocsComputer['META']["USERID"] : "";
     if (!empty($contact)) {
         $query = "SELECT `id`\n                   FROM `glpi_users`\n                   WHERE `name` = '" . $contact . "';";
         $result = $DB->query($query);
         if ($DB->numrows($result) == 1) {
             $user_id = $DB->result($result, 0, 0);
             $user = new User();
             $user->getFromDB($user_id);
             $locations_id = $user->fields["locations_id"];
         }
     }
     // Get all rules for the current plugin_ocsinventoryng_ocsservers_id
     $rule = new RuleImportEntityCollection();
     $data = array();
     $data = $rule->processAllRules(array('ocsservers_id' => $line_links["plugin_ocsinventoryng_ocsservers_id"], '_source' => 'ocsinventoryng', 'locations_id' => $locations_id), array('locations_id' => $locations_id), array('ocsid' => $line_links["ocsid"]));
     // If entity is changing move items to the new entities_id
     if (isset($data['entities_id']) && $data['entities_id'] > -1 && $data['entities_id'] != $line_links['entities_id']) {
         if (!isCommandLine() && !Session::haveAccessToEntity($data['entities_id'])) {
             Html::displayRightError();
         }
         $transfer = new Transfer();
         $transfer->getFromDB($CFG_GLPI['transfers_id_auto']);
         $item_to_transfer = array("Computer" => array($line_links['computers_id'] => $line_links['computers_id']));
         $transfer->moveItems($item_to_transfer, $data['entities_id'], $transfer->fields);
     }
     //If location is update by a rule
     self::updateLocation($line_links, $data, $cfg_ocs);
 }
コード例 #7
0
 /**
  * Do automatic transfer if option is enable
  *
  * @param $line_links array : data from glpi_ocslinks table
  * @param $line_ocs array : data from ocs tables
  *
  * @return nothing
  **/
 static function transferComputer($line_links, $line_ocs)
 {
     global $DB, $DBocs, $CFG_GLPI;
     // Get all rules for the current ocsservers_id
     $rules = new RuleOcsCollection($line_links["ocsservers_id"]);
     $data = array();
     $data = $rules->processAllRules(array(), array(), $line_links["ocsid"]);
     // If entity is changing move items to the new entities_id
     if (isset($data['entities_id']) && $data['entities_id'] != $line_links['entities_id']) {
         if (!isCommandLine() && !haveAccessToEntity($data['entities_id'])) {
             displayRightError();
         }
         $transfer = new Transfer();
         $transfer->getFromDB($CFG_GLPI['transfers_id_auto']);
         $item_to_transfer = array("Computer" => array($line_links['computers_id'] => $line_links['computers_id']));
         $transfer->moveItems($item_to_transfer, $data['entities_id'], $transfer->fields);
     }
     // Update TAG
     self::updateTag($line_links, $line_ocs);
 }