function canUnrecurs()
{
global $DB, $CFG_GLPI;
$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 : printers -> _port -> _wire -> _port -> device
// Evaluate connection in the 2 ways
for ($tabend = array("networkports_id_1" => "networkports_id_2", "networkports_id_2" => "networkports_id_1"); list($enda, $endb) = each($tabend);) {
$sql = "SELECT `itemtype`,\n GROUP_CONCAT(DISTINCT `items_id`) AS ids\n FROM `glpi_networkports_networkports`,\n `glpi_networkports`\n WHERE `glpi_networkports_networkports`.`{$endb}` = `glpi_networkports`.`id`\n AND `glpi_networkports_networkports`.`{$enda}`\n IN (SELECT `id`\n FROM `glpi_networkports`\n WHERE `itemtype` = '" . $this->getType() . "'\n AND `items_id` = '{$ID}')\n GROUP BY `itemtype`";
$res = $DB->query($sql);
if ($res) {
while ($data = $DB->fetch_assoc($res)) {
$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;
}