function canUnrecurs()
{
global $DB;
$ID = $this->fields['id'];
if ($ID < 0 || !$this->fields['is_recursive']) {
return true;
}
if (!parent::canUnrecurs()) {
return false;
}
$entities = getAncestorsOf("glpi_entities", $this->fields['entities_id']);
$entities[] = $this->fields['entities_id'];
// 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' => $data["ids"], 'NOT' => ['entities_id' => $entities]]) > 0) {
return false;
}
}
}
}
}
return true;
}