Software::putInTrash PHP Method

putInTrash() public method

Put software in dustbin because it's been removed by GLPI software dictionnary
public putInTrash ( $ID, $comment = '' ) : boolean
$ID the ID of the software to put in dustbin
$comment the comment to add to the already existing software's comment (default '')
return boolean (success)
    function putInTrash($ID, $comment = '')
    {
        global $CFG_GLPI;
        $this->getFromDB($ID);
        $input["id"] = $ID;
        $input["is_deleted"] = 1;
        //change category of the software on deletion (if defined in glpi_configs)
        if (isset($CFG_GLPI["softwarecategories_id_ondelete"]) && $CFG_GLPI["softwarecategories_id_ondelete"] != 0) {
            $input["softwarecategories_id"] = $CFG_GLPI["softwarecategories_id_ondelete"];
        }
        //Add dictionnary comment to the current comment
        $input["comment"] = ($this->fields["comment"] != '' ? "\n" : '') . $comment;
        return $this->update($input);
    }

Usage Example

 /**
  * Delete a list of softwares
  *
  * @param $soft_ids array containing replay software need to be dustbined
  **/
 function putOldSoftsInTrash(array $soft_ids)
 {
     global $DB;
     if (count($soft_ids) > 0) {
         $ids = implode("','", $soft_ids);
         //Try to delete all the software that are not used anymore
         // (which means that don't have version associated anymore)
         $res_countsoftinstall = $DB->query("SELECT `glpi_softwares`.`id`,\n                                 COUNT(`glpi_softwareversions`.`softwares_id`) AS `cpt`\n                          FROM `glpi_softwares`\n                          LEFT JOIN `glpi_softwareversions`\n                              ON `glpi_softwareversions`.`softwares_id` = `glpi_softwares`.`id`\n                          WHERE `glpi_softwares`.`id` IN ('{$ids}')\n                                AND `is_deleted` = '0'\n                          GROUP BY `glpi_softwares`.`id`\n                          HAVING `cpt` = '0'\n                          ORDER BY `cpt`");
         $software = new Software();
         while ($soft = $DB->fetch_assoc($res_countsoftinstall)) {
             $software->putInTrash($soft["id"], __('Software deleted by GLPI dictionary rules'));
         }
     }
 }
All Usage Examples Of Software::putInTrash