/**
  * Actions done when item is deleted from the database
  * Overloaded to manage autoupdate feature
  *
  *@return nothing
  **/
 function cleanDBonPurge()
 {
     global $CFG_GLPI;
     if (!isset($this->input['_no_auto_action'])) {
         //Get the computer name
         $computer = new Computer();
         $computer->getFromDB($this->fields['computers_id']);
         //Get device fields
         if (class_exists($this->fields['itemtype'])) {
             $device = new $this->fields['itemtype']();
             if ($device->getFromDB($this->fields['items_id'])) {
                 if (!$device->getField('is_global')) {
                     $updates = array();
                     if ($CFG_GLPI["is_location_autoclean"] && $device->isField('locations_id')) {
                         $updates['locations_id'] = 0;
                     }
                     if ($CFG_GLPI["is_user_autoclean"] && $device->isField('users_id')) {
                         $updates['users_id'] = 0;
                     }
                     if ($CFG_GLPI["is_group_autoclean"] && $device->isField('groups_id')) {
                         $updates['groups_id'] = 0;
                     }
                     if ($CFG_GLPI["is_contact_autoclean"] && $device->isField('contact')) {
                         $updates['contact'] = "";
                     }
                     if ($CFG_GLPI["is_contact_autoclean"] && $device->isField('contact_num')) {
                         $updates['contact_num'] = "";
                     }
                     if ($CFG_GLPI["state_autoclean_mode"] < 0 && $device->isField('states_id')) {
                         $updates['states_id'] = 0;
                     }
                     if ($CFG_GLPI["state_autoclean_mode"] > 0 && $device->isField('states_id') && $device->getField('states_id') != $CFG_GLPI["state_autoclean_mode"]) {
                         $updates['states_id'] = $CFG_GLPI["state_autoclean_mode"];
                     }
                     if (count($updates)) {
                         $updates['id'] = $this->fields['items_id'];
                         $device->update($updates);
                     }
                 }
                 if (isset($this->input['_ocsservers_id'])) {
                     $ocsservers_id = $this->input['_ocsservers_id'];
                 } else {
                     $ocsservers_id = OcsServer::getByMachineID($this->fields['computers_id']);
                 }
                 if ($ocsservers_id > 0) {
                     //Get OCS configuration
                     $ocs_config = OcsServer::getConfig($ocsservers_id);
                     //Get the management mode for this device
                     $mode = OcsServer::getDevicesManagementMode($ocs_config, $this->fields['itemtype']);
                     $decoConf = $ocs_config["deconnection_behavior"];
                     //Change status if :
                     // 1 : the management mode IS NOT global
                     // 2 : a deconnection's status have been defined
                     // 3 : unique with serial
                     if ($mode >= 2 && strlen($decoConf) > 0) {
                         //Delete periph from glpi
                         if ($decoConf == "delete") {
                             $tmp["id"] = $this->fields['items_id'];
                             $device->delete($tmp, 1);
                             //Put periph in trash
                         } else {
                             if ($decoConf == "trash") {
                                 $tmp["id"] = $this->fields['items_id'];
                                 $device->delete($tmp, 0);
                             }
                         }
                     }
                 }
                 // $ocsservers_id>0
             }
         }
     }
 }