Esempio n. 1
0
 /**
  * Clean data in the tables which have linked the deleted item
  * Clear 1/N Relation
  *
  * @return nothing
  **/
 function cleanRelationData()
 {
     global $DB, $CFG_GLPI;
     $RELATION = getDbRelations();
     if (isset($RELATION[$this->getTable()])) {
         $newval = isset($this->input['_replace_by']) ? $this->input['_replace_by'] : 0;
         foreach ($RELATION[$this->getTable()] as $tablename => $field) {
             if ($tablename[0] != '_') {
                 $itemtype = getItemTypeForTable($tablename);
                 // Code factorization : we transform the singleton to an array
                 if (!is_array($field)) {
                     $field = array($field);
                 }
                 foreach ($field as $f) {
                     foreach ($DB->request($tablename, array($f => $this->getID())) as $data) {
                         // Be carefull : we must use getIndexName because self::update rely on that !
                         if ($object = getItemForItemtype($itemtype)) {
                             $idName = $object->getIndexName();
                             // And we must ensure that the index name is not the same as the field
                             // we try to modify. Otherwise we will loose this element because all
                             // will be set to $newval ...
                             if ($idName != $f) {
                                 $object->update(array($idName => $data[$idName], $f => $newval, '_disablenotif' => true));
                                 // Disable notifs
                             }
                         }
                     }
                 }
             }
         }
     }
     // Clean ticket open against the item
     if (in_array($this->getType(), $CFG_GLPI["ticket_types"])) {
         $job = new Ticket();
         $itemsticket = new Item_Ticket();
         $query = "SELECT *\n                   FROM `glpi_items_tickets`\n                   WHERE `items_id` = '" . $this->fields['id'] . "'\n                         AND `itemtype`='" . $this->getType() . "'";
         $result = $DB->query($query);
         if ($DB->numrows($result)) {
             while ($data = $DB->fetch_assoc($result)) {
                 $cnt = countElementsInTable('glpi_items_tickets', "`tickets_id`='" . $data['tickets_id'] . "'");
                 $job->getFromDB($data['tickets_id']);
                 if ($cnt == 1) {
                     if ($CFG_GLPI["keep_tickets_on_delete"] == 1) {
                         $itemsticket->delete(array("id" => $data["id"]));
                     } else {
                         $job->delete(array("id" => $data["tickets_id"]));
                     }
                 } else {
                     $itemsticket->delete(array("id" => $data["id"]));
                 }
             }
         }
     }
 }
Esempio n. 2
0
 /**
  * Transfer tickets
  *
  * @param $itemtype  type of transfered item
  * @param $ID        original ID of the ticket
  * @param $newID     new ID of the ticket
  **/
 function transferTickets($itemtype, $ID, $newID)
 {
     global $DB;
     $job = new Ticket();
     $rel = new Item_Ticket();
     $query = "SELECT `glpi_tickets`.*, `glpi_items_tickets`.`id` as _relid\n                FROM `glpi_tickets`\n                LEFT JOIN `glpi_items_tickets`\n                   ON `glpi_items_tickets`.`tickets_id` = `glpi_tickets`.`id`\n                WHERE `items_id` = '{$ID}'\n                      AND `itemtype` = '{$itemtype}'";
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result) != 0) {
             switch ($this->options['keep_ticket']) {
                 // Transfer
                 case 2:
                     // Same Item / Copy Item -> update entity
                     while ($data = $DB->fetch_assoc($result)) {
                         $input = $this->transferHelpdeskAdditionalInformations($data);
                         $input['id'] = $data['id'];
                         $input['entities_id'] = $this->to;
                         $job->update($input);
                         $input = array();
                         $input['id'] = $data['_relid'];
                         $input['items_id'] = $newID;
                         $input['itemtype'] = $itemtype;
                         $rel->update($input);
                         $this->addToAlreadyTransfer('Ticket', $data['id'], $data['id']);
                         $this->transferTaskCategory('Ticket', $data['id'], $data['id']);
                     }
                     break;
                     // Clean ref : keep ticket but clean link
                 // Clean ref : keep ticket but clean link
                 case 1:
                     // Same Item / Copy Item : keep and clean ref
                     while ($data = $DB->fetch_assoc($result)) {
                         $rel->delete(array('id' => $data['relid']));
                         $this->addToAlreadyTransfer('Ticket', $data['id'], $data['id']);
                     }
                     break;
                     // Delete
                 // Delete
                 case 0:
                     // Same item -> delete
                     if ($ID == $newID) {
                         while ($data = $DB->fetch_assoc($result)) {
                             $job->delete(array('id' => $data['id']));
                         }
                     }
                     // Copy Item : nothing to do
                     break;
             }
         }
     }
 }