/** * Can I change recursive flag to false * check if there is "linked" object in another entity * * Overloaded from CommonDBTM * * @since version 0.85 * * @return booleen **/ function canUnrecurs() { global $DB; $ID = $this->fields['id']; if ($ID < 0 || !$this->fields['is_recursive']) { return true; } if (!parent::canUnrecurs()) { return false; } $entities = "(" . $this->fields['entities_id']; foreach (getAncestorsOf("glpi_entities", $this->fields['entities_id']) as $papa) { $entities .= ",{$papa}"; } $entities .= ")"; // RELATION : device -> item_device -> item $linktype = static::getItem_DeviceType(); $linktable = getTableForItemType($linktype); $sql = "SELECT `itemtype`,\n GROUP_CONCAT(DISTINCT `items_id`) AS ids\n FROM `{$linktable}`\n WHERE `{$linktable}`.`" . $this->getForeignKeyField() . "` = '{$ID}'\n GROUP BY `itemtype`"; foreach ($DB->request($sql) as $data) { if (!empty($data["itemtype"])) { $itemtable = getTableForItemType($data["itemtype"]); if ($item = getItemForItemtype($data["itemtype"])) { // For each itemtype which are entity dependant if ($item->isEntityAssign()) { if (countElementsInTable($itemtable, "id IN (" . $data["ids"] . ")\n AND entities_id NOT IN {$entities}") > 0) { return false; } } } } } return true; }