modifica lista missing computer
This commit is contained in:
+113
-4
@@ -12,9 +12,12 @@ use CommonDBTM;
|
||||
use CommonGLPI;
|
||||
use Dropdown;
|
||||
use Entity;
|
||||
use Group;
|
||||
use Html;
|
||||
use Location;
|
||||
use Session;
|
||||
use State;
|
||||
use User;
|
||||
|
||||
class Server extends CommonDBTM
|
||||
{
|
||||
@@ -1062,6 +1065,12 @@ class Server extends CommonDBTM
|
||||
}
|
||||
}
|
||||
|
||||
$cacheEntity = [];
|
||||
$cacheLocation = [];
|
||||
$cacheState = [];
|
||||
$cacheUser = [];
|
||||
$cacheGroup = [];
|
||||
|
||||
$itemtypes = Config::getEnabledItemtypes();
|
||||
$missingAssets = [];
|
||||
|
||||
@@ -1100,6 +1109,8 @@ class Server extends CommonDBTM
|
||||
}
|
||||
|
||||
$key = $itemtype . ':' . $assetRow['id'];
|
||||
$assetId = (int) $assetRow['id'];
|
||||
|
||||
if (isset($linkedAssetKeys[$key])) {
|
||||
continue;
|
||||
}
|
||||
@@ -1107,10 +1118,25 @@ class Server extends CommonDBTM
|
||||
continue;
|
||||
}
|
||||
|
||||
$entityName = self::getCachedName('Entity', (int) ($assetRow['entities_id'] ?? 0), $cacheEntity);
|
||||
$locationName = self::getCachedLocationName($assetLocationId, $cacheLocation);
|
||||
$stateName = self::getCachedName('State', (int) ($assetRow['states_id'] ?? 0), $cacheState);
|
||||
$userName = self::getCachedName('User', (int) ($assetRow['users_id'] ?? 0), $cacheUser);
|
||||
$groupName = self::getCachedName('Group', (int) ($assetRow['groups_id'] ?? 0), $cacheGroup);
|
||||
|
||||
$ip = self::getAssetIp($itemtype, $assetId);
|
||||
|
||||
$missingAssets[] = [
|
||||
'itemtype' => $itemtype,
|
||||
'items_id' => (int) $assetRow['id'],
|
||||
'items_id' => $assetId,
|
||||
'name' => $name,
|
||||
'entity' => $entityName,
|
||||
'location' => $locationName,
|
||||
'otherserial' => (string) ($assetRow['otherserial'] ?? ''),
|
||||
'ip' => $ip,
|
||||
'state' => $stateName,
|
||||
'user' => $userName,
|
||||
'group' => $groupName,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1126,17 +1152,28 @@ class Server extends CommonDBTM
|
||||
|
||||
echo '<table class="table table-striped table-hover">';
|
||||
echo '<thead><tr>';
|
||||
echo '<th>' . htmlspecialchars(__('Asset type')) . '</th>';
|
||||
echo '<th>' . htmlspecialchars(__('Name')) . '</th>';
|
||||
echo '<th>' . htmlspecialchars(Entity::getTypeName(1)) . '</th>';
|
||||
echo '<th>' . htmlspecialchars(Location::getTypeName(1)) . '</th>';
|
||||
echo '<th>' . htmlspecialchars(__('Inventory number')) . '</th>';
|
||||
echo '<th>' . htmlspecialchars(__('IP address', 'urbackup')) . '</th>';
|
||||
echo '<th>' . htmlspecialchars(State::getTypeName(1)) . '</th>';
|
||||
echo '<th>' . htmlspecialchars(User::getTypeName(1)) . '</th>';
|
||||
echo '<th>' . htmlspecialchars(Group::getTypeName(1)) . '</th>';
|
||||
echo '<th>' . htmlspecialchars(__('Actions', 'urbackup')) . '</th>';
|
||||
echo '</tr></thead>';
|
||||
echo '<tbody>';
|
||||
|
||||
foreach ($missingAssets as $asset) {
|
||||
$itemtypeLabel = class_exists($asset['itemtype']) ? $asset['itemtype']::getTypeName(1) : $asset['itemtype'];
|
||||
echo '<tr>';
|
||||
echo '<td>' . htmlspecialchars($itemtypeLabel) . '</td>';
|
||||
echo '<td>' . htmlspecialchars($asset['name']) . '</td>';
|
||||
echo '<td>' . htmlspecialchars($asset['entity']) . '</td>';
|
||||
echo '<td>' . htmlspecialchars($asset['location']) . '</td>';
|
||||
echo '<td>' . htmlspecialchars($asset['otherserial']) . '</td>';
|
||||
echo '<td>' . htmlspecialchars($asset['ip']) . '</td>';
|
||||
echo '<td>' . htmlspecialchars($asset['state']) . '</td>';
|
||||
echo '<td>' . htmlspecialchars($asset['user']) . '</td>';
|
||||
echo '<td>' . htmlspecialchars($asset['group']) . '</td>';
|
||||
echo '<td>';
|
||||
echo '<form method="post" action="' . htmlspecialchars($formAction) . '" class="d-inline">';
|
||||
echo Html::hidden('_glpi_csrf_token', ['value' => Session::getNewCSRFToken()]);
|
||||
@@ -1154,4 +1191,76 @@ class Server extends CommonDBTM
|
||||
echo '</tbody>';
|
||||
echo '</table>';
|
||||
}
|
||||
|
||||
private static function getCachedName(string $classname, int $id, array &$cache): string
|
||||
{
|
||||
if ($id <= 0) {
|
||||
return '';
|
||||
}
|
||||
if (!isset($cache[$id])) {
|
||||
$obj = new $classname();
|
||||
if ($obj->getFromDB($id)) {
|
||||
$cache[$id] = (string) ($obj->fields['name'] ?? '');
|
||||
} else {
|
||||
$cache[$id] = '';
|
||||
}
|
||||
}
|
||||
return $cache[$id];
|
||||
}
|
||||
|
||||
private static function getCachedLocationName(int $id, array &$cache): string
|
||||
{
|
||||
if ($id <= 0) {
|
||||
return '';
|
||||
}
|
||||
if (!isset($cache[$id])) {
|
||||
$obj = new Location();
|
||||
if ($obj->getFromDB($id)) {
|
||||
$cache[$id] = (string) ($obj->fields['completename'] ?? $obj->fields['name'] ?? '');
|
||||
} else {
|
||||
$cache[$id] = '';
|
||||
}
|
||||
}
|
||||
return $cache[$id];
|
||||
}
|
||||
|
||||
private static function getAssetIp(string $itemtype, int $items_id): string
|
||||
{
|
||||
global $DB;
|
||||
|
||||
$iterator = $DB->request([
|
||||
'SELECT' => ['ipa.name'],
|
||||
'FROM' => 'glpi_ipaddresses AS ipa',
|
||||
'INNER JOIN' => [
|
||||
'glpi_networknames AS nn' => [
|
||||
'ON' => [
|
||||
'nn' => 'items_id',
|
||||
'ipa' => 'id',
|
||||
['AND' => ['ipa.itemtype' => 'NetworkName']],
|
||||
],
|
||||
],
|
||||
'glpi_networkports AS np' => [
|
||||
'ON' => [
|
||||
'np' => 'id',
|
||||
'nn' => 'items_id',
|
||||
['AND' => ['nn.itemtype' => 'NetworkPort']],
|
||||
],
|
||||
],
|
||||
],
|
||||
'WHERE' => [
|
||||
'np.itemtype' => $itemtype,
|
||||
'np.items_id' => $items_id,
|
||||
],
|
||||
'LIMIT' => 1,
|
||||
]);
|
||||
|
||||
foreach ($iterator as $row) {
|
||||
$ip = (string) ($row['name'] ?? '');
|
||||
if ($ip !== '') {
|
||||
return $ip;
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user