当前位置: 首页>>代码示例>>PHP>>正文


PHP Software::addOrRestoreFromTrash方法代码示例

本文整理汇总了PHP中Software::addOrRestoreFromTrash方法的典型用法代码示例。如果您正苦于以下问题:PHP Software::addOrRestoreFromTrash方法的具体用法?PHP Software::addOrRestoreFromTrash怎么用?PHP Software::addOrRestoreFromTrash使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Software的用法示例。


在下文中一共展示了Software::addOrRestoreFromTrash方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: replayDictionnaryOnOneSoftware

 /**
  * Replay dictionnary on one software
  *
  * @param &$new_softs      array containing new softwares already computed
  * @param $res_rule        array of rule results
  * @param $ID                    ID of the software
  * @param $entity                working entity ID
  * @param $name                  softwrae name
  * @param $manufacturer          manufacturer name
  * @param &$soft_ids       array containing replay software need to be dustbined
  **/
 function replayDictionnaryOnOneSoftware(array &$new_softs, array $res_rule, $ID, $entity, $name, $manufacturer, array &$soft_ids)
 {
     global $DB;
     $input["name"] = $name;
     $input["manufacturer"] = $manufacturer;
     $input["entities_id"] = $entity;
     if (empty($res_rule)) {
         $res_rule = $this->processAllRules($input, array(), array());
     }
     $soft = new Software();
     if (isset($res_rules['_ignore_import']) && $res_rules['_ignore_import'] == 1) {
         $soft->putInTrash($ID, __('Software deleted by GLPI dictionary rules'));
         return;
     }
     //Software's name has changed or entity
     if (isset($res_rule["name"]) && $res_rule["name"] != $name || !isset($res_rule["name"]) && isset($res_rule['new_entities_id']) && in_array($res_rule['new_entities_id'], getAncestorsOf('glpi_entities', $entity))) {
         if (isset($res_rule["name"])) {
             $new_name = $res_rule["name"];
         } else {
             $new_name = addslashes($name);
         }
         if (isset($res_rule["manufacturer"]) && $res_rule["manufacturer"]) {
             $manufacturer = $res_rule["manufacturer"];
         } else {
             $manufacturer = addslashes($manufacturer);
         }
         //New software not already present in this entity
         if (!isset($new_softs[$entity][$new_name])) {
             // create new software or restore it from dustbin
             $new_software_id = $soft->addOrRestoreFromTrash($new_name, $manufacturer, $entity, '', true);
             $new_softs[$entity][$new_name] = $new_software_id;
         } else {
             $new_software_id = $new_softs[$entity][$new_name];
         }
         // Move licenses to new software
         $this->moveLicenses($ID, $new_software_id);
     } else {
         $new_software_id = $ID;
         $res_rule["id"] = $ID;
         if (isset($res_rule["manufacturer"]) && $res_rule["manufacturer"]) {
             $res_rule["manufacturers_id"] = Dropdown::importExternal('Manufacturer', $res_rule["manufacturer"]);
             unset($res_rule["manufacturer"]);
         }
         $soft->update($res_rule);
     }
     // Add to software to deleted list
     if ($new_software_id != $ID) {
         $soft_ids[] = $ID;
     }
     //Get all the different versions for a software
     $result = $DB->query("SELECT *\n                            FROM `glpi_softwareversions`\n                            WHERE `softwares_id` = '{$ID}'");
     while ($version = $DB->fetch_assoc($result)) {
         $input["version"] = addslashes($version["name"]);
         $old_version_name = $input["version"];
         if (isset($res_rule["version"]) && $res_rule["version"] != '') {
             $new_version_name = $res_rule["version"];
         } else {
             $new_version_name = $version["name"];
         }
         if ($ID != $new_software_id || $new_version_name != $old_version_name) {
             $this->moveVersions($ID, $new_software_id, $version["id"], $old_version_name, $new_version_name, $entity);
         }
     }
 }
开发者ID:geldarr,项目名称:hack-space,代码行数:75,代码来源:ruledictionnarysoftwarecollection.class.php

示例2: updateSoftware


//.........这里部分代码省略.........
         } else {
             $query2 = "SELECT `softwares`.`NAME` AS NAME,\n                              `softwares`.`VERSION` AS VERSION,\n                              `softwares`.`PUBLISHER` AS PUBLISHER,\n                              `softwares`.`COMMENTS` AS COMMENTS\n                       FROM `softwares`\n                       WHERE `softwares`.`HARDWARE_ID` = '{$ocsid}'";
         }
         $result2 = $PluginOcsinventoryngDBocs->query($query2);
         $soft = new Software();
         // Read imported software in last sync
         $query = "SELECT `glpi_computers_softwareversions`.`id` as id,\n                          `glpi_softwares`.`name` as sname,\n                          `glpi_softwareversions`.`name` as vname\n                   FROM `glpi_computers_softwareversions`\n                   INNER JOIN `glpi_softwareversions`\n                           ON `glpi_softwareversions`.`id`= `glpi_computers_softwareversions`.`softwareversions_id`\n                   INNER JOIN `glpi_softwares`\n                           ON `glpi_softwares`.`id`= `glpi_softwareversions`.`softwares_id`\n                   WHERE `glpi_computers_softwareversions`.`computers_id`='{$computers_id}'\n                         AND `is_dynamic`";
         $imported = array();
         foreach ($DB->request($query) as $data) {
             $imported[$data['id']] = strtolower($data['sname'] . self::FIELD_SEPARATOR . $data['vname']);
         }
         if ($PluginOcsinventoryngDBocs->numrows($result2) > 0) {
             while ($data2 = $PluginOcsinventoryngDBocs->fetch_array($result2)) {
                 $data2 = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($data2));
                 //As we cannot be sure that data coming from OCS are in utf8, let's try to encode them
                 //if possible
                 foreach (array('NAME', 'PUBLISHER', 'VERSION') as $field) {
                     $data2[$field] = self::encodeOcsDataInUtf8($is_utf8, $data2[$field]);
                 }
                 //Replay dictionnary on manufacturer
                 $manufacturer = Manufacturer::processName($data2["PUBLISHER"]);
                 $version = $data2['VERSION'];
                 $name = $data2['NAME'];
                 //Software might be created in another entity, depending on the entity's configuration
                 $target_entity = Entity::getUsedConfig('entities_id_software', $entity, '', true);
                 //Do not change software's entity except if the dictionnary explicity changes it
                 if ($target_entity < 0) {
                     $target_entity = $entity;
                 }
                 $modified_name = $name;
                 $modified_version = $version;
                 $is_helpdesk_visible = NULL;
                 if (!$cfg_ocs["use_soft_dict"]) {
                     //Software dictionnary
                     $params = array("name" => $name, "manufacturer" => $manufacturer, "old_version" => $version, "entities_id" => $entity);
                     $rulecollection = new RuleDictionnarySoftwareCollection();
                     $res_rule = $rulecollection->processAllRules(Toolbox::stripslashes_deep($params), array(), Toolbox::stripslashes_deep(array('version' => $version)));
                     if (isset($res_rule["name"]) && $res_rule["name"]) {
                         $modified_name = $res_rule["name"];
                     }
                     if (isset($res_rule["version"]) && $res_rule["version"]) {
                         $modified_version = $res_rule["version"];
                     }
                     if (isset($res_rule["is_helpdesk_visible"]) && strlen($res_rule["is_helpdesk_visible"])) {
                         $is_helpdesk_visible = $res_rule["is_helpdesk_visible"];
                     }
                     if (isset($res_rule['manufacturer']) && $res_rule['manufacturer']) {
                         $manufacturer = Dropdown::getDropdownName('glpi_manufacturers', $res_rule['manufacturer']);
                         $manufacturer = Toolbox::addslashes_deep($manufacturer);
                     }
                     //If software dictionnary returns an entity, it overrides the one that may have
                     //been defined in the entity's configuration
                     if (isset($res_rule["new_entities_id"]) && strlen($res_rule["new_entities_id"])) {
                         $target_entity = $res_rule["new_entities_id"];
                     }
                 }
                 //If software must be imported
                 if (!isset($res_rule["_ignore_import"]) || !$res_rule["_ignore_import"]) {
                     // Clean software object
                     $soft->reset();
                     // EXPLANATION About dictionnaries
                     // OCS dictionnary : if software name change, as we don't store INITNAME
                     //     GLPI will detect an uninstall (oldname) + install (newname)
                     // GLPI dictionnary : is rule have change
                     //     if rule have been replayed, modifiedname will be found => ok
                     //     if not, GLPI will detect an uninstall (oldname) + install (newname)
                     $id = array_search(strtolower(stripslashes($modified_name . self::FIELD_SEPARATOR . $version)), $imported);
                     if ($id) {
                         //-------------------------------------------------------------------------//
                         //---- The software exists in this version for this computer --------------//
                         //---------------------------------------------------- --------------------//
                         unset($imported[$id]);
                     } else {
                         //------------------------------------------------------------------------//
                         //---- The software doesn't exists in this version for this computer -----//
                         //------------------------------------------------------------------------//
                         $isNewSoft = $soft->addOrRestoreFromTrash($modified_name, $manufacturer, $target_entity, '', $entity != $target_entity, $is_helpdesk_visible);
                         //Import version for this software
                         $versionID = self::importVersion($isNewSoft, $modified_version);
                         //Install license for this machine
                         $instID = self::installSoftwareVersion($computers_id, $versionID, $dohistory);
                     }
                 }
             }
         }
         foreach ($imported as $id => $unused) {
             $computer_softwareversion->delete(array('id' => $id, '_no_history' => !$dohistory), true);
             // delete cause a getFromDB, so fields contains values
             $verid = $computer_softwareversion->getField('softwareversions_id');
             if (countElementsInTable('glpi_computers_softwareversions', "softwareversions_id = '{$verid}'") == 0 && countElementsInTable('glpi_softwarelicenses', "softwareversions_id_buy = '{$verid}'") == 0) {
                 $vers = new SoftwareVersion();
                 if ($vers->getFromDB($verid) && countElementsInTable('glpi_softwarelicenses', "softwares_id = '" . $vers->fields['softwares_id'] . "'") == 0 && countElementsInTable('glpi_softwareversions', "softwares_id = '" . $vers->fields['softwares_id'] . "'") == 1) {
                     // 1 is the current to be removed
                     $soft->putInTrash($vers->fields['softwares_id'], __('Software deleted by OCSNG synchronization'));
                 }
                 $vers->delete(array("id" => $verid));
             }
         }
     }
 }
开发者ID:geldarr,项目名称:hack-space,代码行数:101,代码来源:ocsserver.class.php

示例3: replayDictionnaryOnOneSoftware

 /**
  * Replay dictionnary on one software
  *
  * @param $new_softs array containing new softwares already computed
  * @param $res_rule array of rule results
  * @param $ID ID of the software
  * @param $entity working entity ID
  * @param $name softwrae name
  * @param $manufacturer manufacturer ID
  * @param $soft_ids array containing replay software need to be trashed
  **/
 function replayDictionnaryOnOneSoftware(&$new_softs, $res_rule, $ID, $entity, $name, $manufacturer, &$soft_ids)
 {
     global $DB;
     $input["name"] = $name;
     $input["manufacturer"] = $manufacturer;
     $input = addslashes_deep($input);
     if (empty($res_rule)) {
         $res_rule = $this->processAllRules($input, array(), array());
         $res_rule = addslashes_deep($res_rule);
     }
     $soft = new Software();
     //Software's name has changed
     if (isset($res_rule["name"]) && $res_rule["name"] != $name) {
         if (isset($res_rule["manufacturer"])) {
             $manufacturer = Dropdown::getDropdownName("glpi_manufacturers", $res_rule["manufacturer"]);
         }
         //New software not already present in this entity
         if (!isset($new_softs[$entity][$res_rule["name"]])) {
             // create new software or restore it from trash
             $new_software_id = $soft->addOrRestoreFromTrash($res_rule["name"], $manufacturer, $entity);
             $new_softs[$entity][$res_rule["name"]] = $new_software_id;
         } else {
             $new_software_id = $new_softs[$entity][$res_rule["name"]];
         }
         // Move licenses to new software
         $this->moveLicenses($ID, $new_software_id);
     } else {
         $new_software_id = $ID;
         $res_rule["id"] = $ID;
         if (isset($res_rule["manufacturer"])) {
             $res_rule["manufacturers_id"] = $res_rule["manufacturer"];
             unset($res_rule["manufacturer"]);
         }
         $soft->update($res_rule);
     }
     // Add to software to deleted list
     if ($new_software_id != $ID) {
         $soft_ids[] = $ID;
     }
     //Get all the different versions for a software
     $result = $DB->query("SELECT *\n                            FROM `glpi_softwareversions`\n                            WHERE `softwares_id` = '{$ID}'");
     while ($version = $DB->fetch_array($result)) {
         $input["version"] = addslashes($version["name"]);
         $old_version_name = $input["version"];
         if (isset($res_rule["version"]) && $res_rule["version"] != '') {
             $new_version_name = $res_rule["version"];
         } else {
             $new_version_name = $version["name"];
         }
         if ($ID != $new_software_id || $new_version_name != $old_version_name) {
             $this->moveVersions($ID, $new_software_id, $version["id"], $old_version_name, $new_version_name, $entity);
         }
     }
 }
开发者ID:ryukansent,项目名称:Thesis-SideB,代码行数:65,代码来源:ruledictionnarysoftwarecollection.class.php

示例4: testSoftwareCategory

 /**
  * Test software category Rule and putInTrash / removeFromTrash
  */
 public function testSoftwareCategory()
 {
     global $CFG_GLPI;
     $ent0 = $this->sharedFixture['entity'][0];
     // Clean preload rules
     $tmp = SingletonRuleList::getInstance('RuleSoftwareCategory');
     $tmp->load = 0;
     $this->assertArrayHasKey('softwarecategories_id_ondelete', $CFG_GLPI, "Fail: no softwarecategories_id_ondelete");
     $idcat[0] = Dropdown::import('SoftwareCategory', array('name' => 'Trashed'));
     $this->assertGreaterThan(0, $idcat[0], "Fail: can't create SoftwareCategory");
     $idcat[1] = Dropdown::import('SoftwareCategory', array('name' => 'OpenSource'));
     $this->assertGreaterThan(0, $idcat[1], "Fail: can't create SoftwareCategory");
     $rule = new RuleSoftwareCategory();
     $crit = new RuleCriteria();
     $acte = new RuleAction();
     $idr[0] = $rule->add(array('name' => 'OSS', 'sub_type' => 'RuleSoftwareCategory', 'match' => 'AND', 'is_active' => 1));
     $this->assertGreaterThan(0, $idr[0], "Fail: can't create rule 1");
     $this->assertTrue($rule->getFromDB($idr[0]));
     $this->assertEquals(1, $rule->fields['ranking'], "Fail: ranking not set");
     $idc[0] = $crit->add(array('rules_id' => $idr[0], 'criteria' => 'manufacturer', 'condition' => Rule::PATTERN_IS, 'pattern' => 'Indepnet'));
     $this->assertGreaterThan(0, $idc[0], "Fail: can't create rule 1 criteria");
     $ida[0] = $acte->add(array('rules_id' => $idr[0], 'action_type' => 'assign', 'field' => 'softwarecategories_id', 'value' => $idcat[1]));
     $this->assertGreaterThan(0, $ida[0], "Fail: can't create rule 1 action");
     // Createthe software
     $soft = new Software();
     $id[0] = $soft->addOrRestoreFromTrash('GLPI', 'Indepnet', $ent0);
     $this->assertGreaterThan(0, $id[0], "Fail: can't create software 1");
     // Check name
     $this->assertTrue($soft->getFromDB($id[0]), "Fail: can't read new soft");
     $this->assertEquals('GLPI', $soft->getField('name'), "Fail: name not set");
     // Check category
     $catid = $soft->getField('softwarecategories_id');
     $this->assertEquals($idcat[1], $catid, "Fail: category not set");
     // Change configuration
     $CFG_GLPI["softwarecategories_id_ondelete"] = $idcat[0];
     // Delete
     $this->assertTrue($soft->putInTrash($id[0]), "Fail: can't put soft in trash");
     $this->assertTrue($soft->getFromDB($id[0]), "Fail: can't read new soft");
     $catid = $soft->getField('softwarecategories_id');
     $this->assertEquals($idcat[0], $catid, "Fail: category not set");
     $this->assertEquals(1, $soft->getField('is_deleted'), "Fail: soft not deleted");
     // Restore
     $this->assertTrue($soft->removeFromTrash($id[0]), "Fail: can't put soft in trash");
     $this->assertTrue($soft->getFromDB($id[0]), "Fail: can't read new soft");
     $catid = $soft->getField('softwarecategories_id');
     $this->assertEquals($idcat[1], $catid, "Fail: category not set");
     $this->assertEquals(0, $soft->getField('is_deleted'), "Fail: soft not restored");
     // Clean
     $this->assertTrue($soft->delete(array('id' => $id[0]), true), "Fail: can't delete software 1)");
 }
开发者ID:btry,项目名称:glpi,代码行数:53,代码来源:Import.php

示例5: updateSoftware


//.........这里部分代码省略.........
                     $data2["PUBLISHER"] = encodeInUtf8($data2["PUBLISHER"]);
                 }
                 $version = $data2["VERSION"];
                 $manufacturer = Manufacturer::processName($data2["PUBLISHER"]);
                 $use_glpi_dictionnary = false;
                 if (!$cfg_ocs["use_soft_dict"]) {
                     //Software dictionnary
                     $rulecollection = new RuleDictionnarySoftwareCollection();
                     $res_rule = $rulecollection->processAllRules(array("name" => $name, "manufacturer" => $manufacturer, "old_version" => $version), array(), array('version' => $version));
                     $res_rule = addslashes_deep($res_rule);
                     if (isset($res_rule["name"])) {
                         $modified_name = $res_rule["name"];
                     } else {
                         $modified_name = $name;
                     }
                     if (isset($res_rule["version"]) && $res_rule["version"] != '') {
                         $modified_version = $res_rule["version"];
                     } else {
                         $modified_version = $version;
                     }
                 } else {
                     $modified_name = $name;
                     $modified_version = $version;
                 }
                 //Ignore this software
                 if (!isset($res_rule["_ignore_ocs_import"]) || !$res_rule["_ignore_ocs_import"]) {
                     // Clean software object
                     $soft->reset();
                     //If name+version not in present for this computer in glpi, add it
                     if (!in_array(stripslashes($initname . self::FIELD_SEPARATOR . $version), $import_software)) {
                         //------------------------------------------------------------------------//
                         //---- The software doesn't exists in this version for this computer -----//
                         //------------------------------------------------------------------------//
                         $isNewSoft = $soft->addOrRestoreFromTrash($modified_name, $manufacturer, $entity);
                         //Import version for this software
                         $versionID = self::importVersion($isNewSoft, $modified_version);
                         //Install license for this machine
                         $instID = self::installSoftwareVersion($computers_id, $versionID, $dohistory);
                         //Add the software to the table of softwares for this computer to add in database
                         $to_add_to_ocs_array[$instID] = $initname . self::FIELD_SEPARATOR . $version;
                     } else {
                         $instID = -1;
                         //-------------------------------------------------------------------------//
                         //---- The software exists in this version for this computer --------------//
                         //---------------------------------------------------- --------------------//
                         //Get the name of the software in GLPI to know if the software's name
                         //have already been changed by the OCS dictionnary
                         $instID = array_search(stripslashes($initname . self::FIELD_SEPARATOR . $version), $import_software);
                         $query_soft = "SELECT `glpi_softwares`.`id`,\n                                           `glpi_softwares`.`name`,\n                                           `glpi_softwares`.`entities_id`\n                                    FROM `glpi_softwares`,\n                                         `glpi_computers_softwareversions`,\n                                         `glpi_softwareversions`\n                                    WHERE `glpi_computers_softwareversions`.`id` = '{$instID}'\n                                          AND `glpi_computers_softwareversions`.`softwareversions_id`\n                                                = `glpi_softwareversions`.`id`\n                                          AND `glpi_softwareversions`.`softwares_id`\n                                                = `glpi_softwares`.`id`";
                         $result_soft = $DB->query($query_soft);
                         $tmpsoft = $DB->fetch_array($result_soft);
                         $softName = $tmpsoft["name"];
                         $softID = $tmpsoft["id"];
                         $s = new Software();
                         $input["id"] = $softID;
                         $input["entities_id"] = $tmpsoft['entities_id'];
                         //First, get the name of the software into GLPI db IF dictionnary is used
                         if ($cfg_ocs["use_soft_dict"]) {
                             //First use of the OCS dictionnary OR name changed in the dictionnary
                             if ($softName != $name) {
                                 $input["name"] = $name;
                                 $s->update($input);
                             }
                         } else {
                             if ($softName != $modified_name) {
                                 // OCS Dictionnary not use anymore : revert to original name
开发者ID:ryukansent,项目名称:Thesis-SideB,代码行数:67,代码来源:ocsserver.class.php


注:本文中的Software::addOrRestoreFromTrash方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。